急急急!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
非专业的,只是需要,哪位能尽快帮忙指出哪错啦?怎么该?
非常感谢!

第1个回答  2009-06-08
读你的程序,十分艰难,既没有注释,变量名称也没有字面意义。
我把自己写的一个给你,要不要?本回答被提问者采纳

急急急!用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

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

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

相似回答