高手来看一下,用vb解四元一次方程组(主元消去法)三元一次是这样的,那么四元一次是在三元的基础上稍微变动一下,还是要做很大的变动,最好可以把程序写出来Private Sub Command1_Click()Dim i, j,
来源:学生作业帮助网 编辑:六六作业网 时间:2024/11/22 17:54:31
高手来看一下,用vb解四元一次方程组(主元消去法)三元一次是这样的,那么四元一次是在三元的基础上稍微变动一下,还是要做很大的变动,最好可以把程序写出来Private Sub Command1_Click()Dim i, j,
高手来看一下,用vb解四元一次方程组(主元消去法)
三元一次是这样的,那么四元一次是在三元的基础上稍微变动一下,还是要做很大的变动,最好可以把程序写出来
Private Sub Command1_Click()
Dim i, j, m, n As Integer
Dim a(), z(), x(), w, aa(), s, t, k
n = InputBox("n")
ReDim a(n + 2, n + 2), z(n + 2, n + 2), x(n + 1), aa(n + 2, n + 2)
For i = 1 To n
For j = 1 To n + 1
a(i, j) = InputBox("输入系数矩阵A(" & i & "," & j & ")")
Next j
Next i
For i = 1 To n
If i = n Then GoTo 200
For t = i + 1 To n
If Abs(a(i, i)) < Abs(a(t, i)) Then
For s = i To n + 1
aa(t, s) = a(i, s)
a(i, s) = a(t, s)
a(t, s) = aa(t, s)
Next s
Else
End If
Next t
200
w = a(i, i)
For j = 1 To n + 1
a(i, j) = a(i, j) / w
Next j
If i = n Then GoTo 100
For j = i + 1 To n
For k = i + 1 To n + 1
z(j, k) = a(j, k) * a(j, i)
a(j, k) = a(j, k) - z(i, k)
Next k
Next j
Next i
100
x(n + 1) = 0
For k = n To 1 Step -1
s = 0
For j = k + 1 To n
s = s + a(k, j) * x(j)
Next j
x(k) = a(k, n + 1) - s
Print "x("; k; ")"; x(k)
Next k
Text1.Text = i
Text2.Text = j
Text3.Text = k
Text4.Text = m
End Sub
高手来看一下,用vb解四元一次方程组(主元消去法)三元一次是这样的,那么四元一次是在三元的基础上稍微变动一下,还是要做很大的变动,最好可以把程序写出来Private Sub Command1_Click()Dim i, j,
Private Sub Command1_Click()
Dim n As Integer '阶数
n = InputBox("n")
Dim a() As Double '系数矩阵
Dim temp1 As Double '临时存储点东西用
ReDim a(n,n + 1) '不明白你为什么要用n+2*n+2的
Dim x() As Double '解数据
ReDim x(n + 1)
For i = 1 To n '输入系数,没什么好说的
For j = 1 To n + 1
a(i,j) = InputBox("输入系数矩阵A(" & i & "," & j & ")")
Next j
Next i
For i = 1 To n '进入计算过程了
If i = n Then GoTo 200
For t = i + 1 To n
If Abs(a(i,i)) < Abs(a(t,i)) Then
For s = i To n + 1
temp1 = a(i,s) 'aa(i,t)以后还有什么用?临时找个量存储一下就行了
a(i,s) = a(t,s)
a(t,s) = temp1
Next s
End If 'else里没有语句就省掉了
Next t
200:
temp1 = a(i,i)
For j = 1 To n + 1
a(i,j) = a(i,j) / temp1
Next j
If i = n Then GoTo 100
For j = i + 1 To n '对角线下的化为零
For k = i + 1 To n + 1
temp1 = a(i,k) * a(j,i) '不应该是a(j,k)把
a(j,k) = a(j,k) - temp1
Next k
Next j
Next i '对角线上系数全为1,对角线下系数全为零(注意:矩阵中存储的数不为零)
100
x(n + 1) = 0
For k = n To 1 Step -1
s = 0
For j = k + 1 To n
s = s + a(k,j) * x(j)
Next j
x(k) = a(k,n + 1) - s
Print "x("; k; ")"; x(k)
Next k
End Sub
你的程序本来就可以算四元的,只是里面有个逻辑错误,没有考虑多解和无解的现象,现在这个也没考虑,你自己改进把,算100元都没问题.