急急急!用VB编程求解线性方程组,用高斯消去法

源代码如下:
Dim a() As Double, b() As Double, nIs As Integer, nJs As Integer, p As Double, t As Double, d As Double
Private Sub Form_Click()
Dim n As Integer, m As Integer
m = 0
n = Val(InputBox("输入线性方程组的阶数n"))
'输入系数矩阵
ReDim a(n, n) As Double
Form1.Print "系数矩阵:"
For v = 1 To n
For w = 1 To n
a(v, w) = Val(InputBox("a(" & v & "," & w & ")"))
m = m + 1
Print a(v, w);
If m Mod n = 0 Then Print
Next w
Next v
Print
Print "常数向量:"
ReDim b(n) As Double
For v = 1 To n
b(n) = Val(InputBox(输入常数向量 & "b(" & v & ")"))
Print b(n);
Next v
'寻找最大值元素
For k = 1 To n
t = 0#
For i = k To n
For j = k To n
d = Abs(a(i, j))
If a(i, j) > t Then
t = a(i, j)
nIs = i
nJs = j
End If
Next j, i
'交换最大值元素行
If nIs <> k Then
For j = 1 To n
p = a(k, j)
a(k, j) = a(nIs, j)
a(nIs, j) = p
Next j
p = b(k)
b(k) = b(nIs)
b(nIs) = p
End If
'交换最大值元素列
If nJs <> k Then
For i = 1 To n
p = a(i, k)
a(i, k) = a(i, nJs)
a(i, nJs) = p
Next i
End If
'消元
For i = k + 1 To n
For j = 1 To n
a(i, j) = a(i, j) * a(k, k) / a(i, k) - a(k, j)
Next j, i
Next k
'回代
b(n) = b(n) / a(n, n)
For i = n - 1 To 1 Step -1
t = 0
For j = i + 1 To n
t = t + a(i, j) * b(j)
Next j
b(i) = (b(i) - t) / a(i, i)
Next i
Print "解得结果为:"
For i = 1 To n
Print b(i);
Next i
End Sub

Private Sub Form_Load()
Form1.AutoRedraw = True
Print "单击窗体开始"
End Sub
我知道不专业,别来批我了。只需要你高抬贵手帮忙该哈,我将不胜感激。
可不可以有个完整的代码啊?我考过来就是老是弄不出来,对SUB 过程和FUNCTION 过程都不熟悉,谢谢哈!完整一点的……

每个人的思维逻辑都不一样.这是我写的代码,供参考:

Sub 解方程(XiSu() As Double, Jie() As Double)

Dim BeiSu As Double
On Error GoTo err1

m = UBound(XiSu, 1) '行数
n = UBound(XiSu, 2) '列数
If n <> m + 1 Then
MsgBox "系数矩阵维数不正确!", , "注意"
Exit Sub
End If

For i = 0 To m
If XiSu(i, i) = 0 Then
MsgBox "系数矩阵的对角线系数不能有 0 ,请校对后重新输入!", , "注意"
Exit Sub
End If
Next

For i = 1 To m '行
For k = i To m '行
BeiSu = XiSu(k, i - 1) / XiSu(i - 1, i - 1)
For j = i - 1 To n '列数据处理
XiSu(k, j) = XiSu(k, j) - BeiSu * XiSu(i - 1, j)
Next
Next
Next

For i = m - 1 To 0 Step -1
For k = i To 0 Step -1
BeiSu = XiSu(k, i + 1) / XiSu(i + 1, i + 1)
For j = i To n
XiSu(k, j) = XiSu(k, j) - BeiSu * XiSu(i + 1, j)
Next
Next
Next

For i = 0 To m
Jie(i) = XiSu(i, n) / XiSu(i, i)
Next

Exit Sub
err1:
If Err.Number = 11 Then
MsgBox "方程组无解,请校对系数。", , "提示"
Else
MsgBox Err.Description, , "提示"
End If
End Sub

Private Sub Command1_Click()
Dim suju() As Double, jie() As Double
n = Val(InputBox("请输入方程组元数(未知数个数):"))
ReDim suju(n - 1, n)
ReDim jie(n - 1)
For i = 0 To n - 1 '输入系数
For j = 0 To n
suju(i, j) = Val(InputBox("请输入方程系数:" & vbCrLf & "第" & i + 1 & "行,第" & j + 1 & "列:"))
Next
Next

Call 解方程(suju, jie)
Cls
For i = 0 To n - 1
Print "X" & i + 1 & "="; jie(i)
Next

End Sub
温馨提示:内容为网友见解,仅供参考
无其他回答

急急急!用VB编程求解线性方程组,用高斯消去法
n = Val(InputBox("请输入方程组元数(未知数个数):"))ReDim suju(n - 1, n)ReDim jie(n - 1)For i = 0 To n - 1 '输入系数 For j = 0 To n suju(i, j) = Val(InputBox("请输入方程系数:" & vbCrLf & "第" & i + 1 & "行,第" & j + 1 & "列:"))N...

用高斯法求解方程
dfgf(gvgv)hyd-==dshgcf _dhf{{{nhfjr_jdb+jjhfbb=jej } ndsj"""smslkjjjjjjjjjjejbur-lkdj=ddda {skncvfhvb ej ::} so

判断一组向量线性相关,线性无关最简单易学的方法
当向量元素的个数大于向量组的个数时就需要判断向量组矩阵的秩,当秩小于元素个数时,向量组线性相关。当秩大于等于元素个数时线性无关。当元素个数很多时矩阵的秩需要用程序计算。即使元素个数少时一般的矩阵也没什么简便的求秩方法。用计算机编程来求是方便的。就是用高斯消元法,用c语言,vb都可以。

怎样用VB编程矩阵求逆
Private Function MRinv(N As Integer, mtxA() As Double) As Boolean '' 功能: 实现矩阵求逆的全选主元高斯-约当法 ' 参数: n - Integer型变量,矩阵的阶数 ' mtxA - Double型二维数组,体积为n x n。存放原矩阵A;返回时存放其逆矩阵A-1。' 返回值:Boolean型,失败...

相似回答