高手来看一下,用vb解四元一次方程组(主元消去法)
来源:学生作业帮 编辑:神马作文网作业帮 分类:数学作业 时间:2024/11/16 14:18:27
高手来看一下,用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
三元一次是这样的,那么四元一次是在三元的基础上稍微变动一下,还是要做很大的变动,最好可以把程序写出来
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
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元都没问题.
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元都没问题.
高手来看一下,用vb解四元一次方程组(主元消去法)
谁能给我讲讲:2元一次方程组,用消元发解2元一次方程组,用图像法解2元一次方程组,2元一次
解二元一次方程组2x-5y=2,3y-2x=4用( )法先消去未知数( )简便,方程组的解为( )
c语言 列主元素消去法求方程组
用MATLAB或VB解四元二次方程组
(应该是四元一次方程组)
2元一次方程组
高手来!这道方程组怎么消去参数k?
已知二元一次方程组2x=3y-1,5y=2x+3,用代入法消去x,可得到关于y的一元一次方程为()即()
麻烦用二元一次方程组解一下,
哪个高手能帮我用C++编写一个可以解 五元一次方程组 的程序?
matlab用列主元高斯消去法解方程组,