2X2 aa(2,2) bb(2,2) cc(2,2) dim s as double dim i,j,t as integer t=1 for i=1 to 2 for j=1 to 2 s=aa(i,j)*bb(j,i) next cc(i,t)=s t=t+1 if t>2 then t=1 end if next
我有一个matlab的 不知道你要不要
大概框架。 以下用的是高斯消元法 Dim tArray() As Double '存a11,a12,a13...a45 Dim m_tArray() As Double dim x() as double private sub command1_click() dim n as integer n=inputbox("输入矩阵的阶数") redim tarray(n,n+1) redim x(n) 这里给tarray(1,1)=.. tarray(1,2)=.. tarray(1,n+1)=.. .............. tarray(n,n+1)=... 具体怎么赋值方便看你自己设置了,如果数多了,这么赋值很累,可以用循环。 calu_gsxy end sub Sub calu_gsxy() Dim i As Integer Dim j As Integer Dim k As Integer Dim mid_num As Single redim m_tarray(n,n+1) For i=1 to n for j=1 to n+1 m_tArray(i, j) = tArray(i, j) next j next i For k = 1 To n - 1 For i = k + 1 To n tArray(i, n + 1) = tArray(i, n + 1) - tArray(k, n + 1) * (tArray(i, k) / tArray(k, k)) For j = k To n tArray(i, j) = tArray(i, j) - tArray(k, j) * (m_tArray(i, k) / tArray(k, k)) Next j For j = 1 To n m_tArray(i, j) = tArray(i, j) Next j Next i Next k For i = n To 1 Step -1 x(n) = tArray(n, n + 1) / tArray(n, n) For j = i + 1 To n mid_num = tArray(i, j) * x(j) Next j x(i) = (tArray(i, n + 1) - mid_num) / tArray(i, i) mid_num = 0 Next i For i = n To 1 Step -1 x(n) = tArray(n, n + 1) / tArray(n, n) For j = i + 1 To n mid_num = tArray(i, j) * x(j) Next j x(i) = (tArray(i, n + 1) - mid_num) / tArray(i, i) mid_num = 0 Next i For i = 1 To n Print "x" & i & "=" & x(i),'答案 Next i End Sub
aa(2,2)
bb(2,2)
cc(2,2)
dim s as double
dim i,j,t as integer
t=1
for i=1 to 2
for j=1 to 2
s=aa(i,j)*bb(j,i)
next
cc(i,t)=s
t=t+1
if t>2 then
t=1
end if
next
不知道你要不要
以下用的是高斯消元法
Dim tArray() As Double '存a11,a12,a13...a45
Dim m_tArray() As Double
dim x() as double
private sub command1_click()
dim n as integer
n=inputbox("输入矩阵的阶数")
redim tarray(n,n+1)
redim x(n)
这里给tarray(1,1)=..
tarray(1,2)=..
tarray(1,n+1)=..
..............
tarray(n,n+1)=...
具体怎么赋值方便看你自己设置了,如果数多了,这么赋值很累,可以用循环。
calu_gsxy
end sub
Sub calu_gsxy()
Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim mid_num As Single
redim m_tarray(n,n+1)
For i=1 to n
for j=1 to n+1
m_tArray(i, j) = tArray(i, j)
next j
next i
For k = 1 To n - 1
For i = k + 1 To n
tArray(i, n + 1) = tArray(i, n + 1) - tArray(k, n + 1) * (tArray(i, k) / tArray(k, k))
For j = k To n
tArray(i, j) = tArray(i, j) - tArray(k, j) * (m_tArray(i, k) / tArray(k, k))
Next j
For j = 1 To n
m_tArray(i, j) = tArray(i, j)
Next j
Next i
Next k
For i = n To 1 Step -1
x(n) = tArray(n, n + 1) / tArray(n, n)
For j = i + 1 To n
mid_num = tArray(i, j) * x(j)
Next j
x(i) = (tArray(i, n + 1) - mid_num) / tArray(i, i)
mid_num = 0
Next i
For i = n To 1 Step -1
x(n) = tArray(n, n + 1) / tArray(n, n)
For j = i + 1 To n
mid_num = tArray(i, j) * x(j)
Next j
x(i) = (tArray(i, n + 1) - mid_num) / tArray(i, i)
mid_num = 0
Next i
For i = 1 To n
Print "x" & i & "=" & x(i),'答案
Next i
End Sub
用时只有2秒钟,
我现在没有多的时间来研究这个
如果你想要源代码,
留下邮箱