环境评价程序设计
河流断面、多箱模型
小组成员:陈泽洲 200712023
许双辰 200712011 王成宁 200712003
2010/1/20
程序一 河流断面(以5断面为例)
程序界面:
程序代码(Form1):
Dim a_1, b_1, c_1, d_1, A, B, C, D, f As Single
'------------------------------------------------------------------------------ '矩阵的乘法函数
Public Function MatMultiply(x() As Single, y() As Single) As Single() Dim n As Integer Dim m As Integer Dim p As Integer Dim k As Integer Dim z() As Single n = UBound(x, 1)
m = UBound(x, 2) p = UBound(y, 2)
ReDim z(1 To n, 1 To p) ReDim z(n, p)
If m <> UBound(y, 1) Then
MsgBox (\"这两个矩阵不能相乘!\" + Str$(m) + Str$(UBound(y, 1))) Else: For i = 1 To n For j = 1 To m For k = 1 To p
z(i, k) = z(i, k) + x(i, j) * y(j, k) Next k Next j Next i End If
MatMultiply = z End Function
'------------------------------------------------------------------------------ Private Sub Command1_Click() '赋值
OS = Val(Text39.Text)
Q1 = Val(Text1.Text) Q2 = Val(Text2.Text) Q3 = Val(Text3.Text) Q4 = Val(Text4.Text) Q5 = Val(Text5.Text)
L1 = Val(Text6.Text) L2 = Val(Text7.Text) L3 = Val(Text8.Text) L4 = Val(Text9.Text) L5 = Val(Text10.Text)
O1 = Val(Text11.Text) O2 = Val(Text12.Text) O3 = Val(Text13.Text) O4 = Val(Text14.Text) O5 = Val(Text15.Text)
Q0 = Val(Text16.Text) L0 = Val(Text17.Text) O0 = Val(Text18.Text)
K10 = Val(Text19.Text)
K20 = Val(Text20.Text) t0 = Val(Text21.Text)
K11 = Val(Text25.Text) K21 = Val(Text26.Text) t1 = Val(Text30.Text)
K12 = Val(Text24.Text) K22 = Val(Text27.Text) t2 = Val(Text31.Text)
K13 = Val(Text23.Text) K23 = Val(Text28.Text) t3 = Val(Text32.Text)
K14 = Val(Text22.Text) K24 = Val(Text29.Text) t4 = Val(Text33.Text)
Q31 = Val(Text34.Text) Q32 = Val(Text35.Text) Q33 = Val(Text36.Text) Q34 = Val(Text37.Text) Q35 = Val(Text38.Text)
Q21 = Q0 - Q31 + Q1 Q12 = Q21
Q22 = Q12 - Q32 + Q2 Q13 = Q22
Q23 = Q13 - Q33 + Q3 Q14 = Q23
Q24 = Q14 - Q34 + Q4 Q15 = Q24
Q25 = Q15 - Q35 + Q5
'------------------------------------------------------------------------------ 'a_ b_ c_ d_ 的计算 a_0 = Exp(-K10 * t0) a_1 = Exp(-K11 * t1) a_2 = Exp(-K12 * t2) a_3 = Exp(-K13 * t3) a_4 = Exp(-K14 * t4)
c_0 = Exp(-K20 * t0)
c_1 = Exp(-K21 * t1) c_2 = Exp(-K22 * t2) c_3 = Exp(-K23 * t3) c_4 = Exp(-K24 * t4)
b_0 = K10 * (a_0 - c_0) / (K20 - K10) b_1 = K11 * (a_1 - c_1) / (K21 - K11) b_2 = K12 * (a_2 - c_2) / (K22 - K12) b_3 = K13 * (a_3 - c_3) / (K23 - K13) b_4 = K14 * (a_4 - c_4) / (K24 - K14)
d_0 = OS * (1 - c_0) d_1 = OS * (1 - c_1) d_2 = OS * (1 - c_2) d_3 = OS * (1 - c_3) d_4 = OS * (1 - c_4)
'------------------------------------------------------------------------------ '矩阵中元素a b c d f 的计算 a0 = a_0 * (Q0 - Q31) / Q21 a1 = a_1 * (Q12 - Q32) / Q22 a2 = a_2 * (Q13 - Q33) / Q23 a3 = a_3 * (Q14 - Q34) / Q24 a4 = a_4 * (Q15 - Q35) / Q25
b1 = Q1 / Q21 b2 = Q2 / Q22 b3 = Q3 / Q23 b4 = Q4 / Q24 b5 = Q5 / Q25
c0 = (Q0 - Q31) / Q21 * c_0 c1 = (Q12 - Q32) / Q22 * c_1 c2 = (Q13 - Q33) / Q23 * c_2 c3 = (Q14 - Q34) / Q24 * c_3 c4 = (Q15 - Q35) / Q25 * c_4
d0 = (Q0 - Q31) / Q21 * b_0 d1 = (Q12 - Q32) / Q22 * b_1 d2 = (Q13 - Q33) / Q23 * b_2 d3 = (Q14 - Q34) / Q24 * b_3 d4 = (Q15 - Q35) / Q25 * b_4
f0 = (Q0 - Q31) / Q21 * d_0 f1 = (Q12 - Q32) / Q22 * d_1
f2 = (Q13 - Q33) / Q23 * d_2 f3 = (Q14 - Q34) / Q24 * d_3 f4 = (Q15 - Q35) / Q25 * d_4
'------------------------------------------------------------------------------'矩阵 A B C D f g h f+h(fh) O L 的计算 Dim A(5, 5) As Single For i = 1 To 5 For j = 1 To 5 A(i, j) = 0 Next j Next i
If 1 > 0 Then A(2, 1) = -a1 A(3, 2) = -a2 A(4, 3) = -a3 A(5, 4) = -a4 A(1, 1) = 1 A(2, 2) = 1 A(3, 3) = 1 A(4, 4) = 1 A(5, 5) = 1 End If
Dim B(5, 5) As Single For i = 1 To 5 For j = 1 To 5 B(i, k) = 0 Next j Next i
If 1 > 0 Then B(1, 1) = b1 B(2, 2) = b2 B(3, 3) = b3 B(4, 4) = b4 B(5, 5) = b5 End If
Dim C(5, 5) As Single For i = 1 To 5 For j = 1 To 5 C(i, j) = 0 Next j Next i
If 1 > 0 Then
C(2, 1) = -c1 C(3, 2) = -c2 C(4, 3) = -c3 C(5, 4) = -c4 C(1, 1) = 1 C(2, 2) = 1 C(3, 3) = 1 C(4, 4) = 1 C(5, 5) = 1 End If
Dim D(5, 5) As Single For i = 1 To 5 For j = 1 To 5 D(i, k) = 0 Next j Next i
If 1 > 0 Then D(2, 1) = d1 D(3, 2) = d2 D(4, 3) = d3 D(5, 4) = d4 End If
Dim g(5, 1) As Single For i = 1 To 5 g(i, 1) = 0 Next i
g(1, 1) = a0 * L0
Dim f(5, 1) As Single If 1 > 0 Then f(1, 1) = f0 f(2, 1) = f1 f(3, 1) = f2 f(4, 1) = f3 f(5, 1) = f4 End If
Dim h(5, 1) As Single For i = 1 To 5 h(i, 1) = 0 Next i
h(1, 1) = c0 * O0 - d0 * L0
Dim fh(5, 1) As Single For i = 1 To 5
fh(i, 1) = f(i, 1) + h(i, 1) Next i
Dim O(5, 1) As Single If 1 > 0 Then O(1, 1) = O1 O(2, 1) = O2 O(3, 1) = O3 O(4, 1) = O4 O(5, 1) = O5 End If
Dim L(5, 1) As Single If 1 > 0 Then L(1, 1) = L1 L(2, 1) = L2 L(3, 1) = L3 L(4, 1) = L4 L(5, 1) = L5 End If
'------------------------------------------------------------------------------ '求向量A、C的逆矩阵AA、CC Form2.Text2.Text = 1 i = 1 j = 1
For k = 1 To 5 ^ 2 If j > 5 Then j = 1 i = i + 1 End If
Form2.Text1(k - 1).Text = A(i, j) j = j + 1 Next k
Form2.Text2.Text = 2 Dim AA(5, 5) As Single i = 1 j = 1
For k = 1 To 5 ^ 2 If j > 5 Then j = 1
i = i + 1 End If
AA(i, j) = Form2.Text1(k - 1).Text j = j + 1 Next k
Form2.Text2.Text = 3 i = 1 j = 1
For k = 1 To 5 ^ 2 If j > 5 Then j = 1 i = i + 1 End If
Form2.Text1(k - 1).Text = C(i, j) j = j + 1 Next k
Form2.Text2.Text = 4 Dim CC(5, 5) As Single i = 1 j = 1
For k = 1 To 5 ^ 2 If j > 5 Then j = 1 i = i + 1 End If
CC(i, j) = Form2.Text1(k - 1).Text j = j + 1 Next k
'------------------------------------------------------------------------------ '求U、V_、m、n V(向量的乘法) Dim U() As Single
ReDim V_(5, 5) As Single Dim m() As Single
U = MatMultiply(AA(), B())
V_ = MatMultiply(MatMultiply(MatMultiply(CC(), D()), AA()), B()) m = MatMultiply(AA(), g())
Dim V(5, 5) As Single For i = 1 To 5 For j = 1 To 5
V(i, j) = -1 * V_(i, j)
Next j Next i
'-------------------------------------------------------------- '求n
ReDim n1(5, 1) As Single ReDim n2(5, 1) As Single ReDim n3(5, 1) As Single Dim n(5, 1) As Single
n1 = MatMultiply(MatMultiply(CC(), B()), O()) n2 = MatMultiply(CC(), fh)
n3 = MatMultiply(MatMultiply(MatMultiply(CC(), D()), AA()), g())
For i = 1 To 5
n(i, 1) = n1(i, 1) + n2(i, 1) - n3(i, 1) Next i
'------------------------------------------------------------------------------ '输出结果U、V、m、n
Form1.Picture1.Print \"计算结果为\" Form1.Picture1.Print
Form1.Picture1.Print \"U=\" For i = 1 To 5 For j = 1 To 5
Form1.Picture1.Print Round(U(i, j), 5), tab5, Next j
Picture1.Print Next i
Form1.Picture1.Print
Form1.Picture1.Print \"V=\" For i = 1 To 5 For j = 1 To 5
Form1.Picture1.Print Round(V(i, j), 5), tab5, Next j
Picture1.Print Next i
Form1.Picture2.Print
Form1.Picture2.Print \"m=\" For i = 1 To 5
Form1.Picture2.Print Round(m(i, 1), 5), tab5, Picture2.Print Next i
Form1.Picture2.Print
Form1.Picture2.Print \"n=\" For i = 1 To 5
Form1.Picture2.Print Round(n(i, 1), 5), tab5, Picture2.Print Next i
'------------------------------------------------------------------------------ '计算L2、O2
Dim UL() As Single
Dim L2_(5, 1) As Single
UL = MatMultiply(U(), L()) For i = 1 To 5
L2_(i, 1) = UL(i, 1) + m(i, 1) Next i
Dim VL() As Single
Dim O2_(5, 1) As Single VL = MatMultiply(V(), L()) For i = 1 To 5
O2_(i, 1) = VL(i, 1) + n(i, 1) Next i
'------------------------------------------------------------------------------ '输出L2、O2
Form1.Picture2.Print
Form1.Picture2.Print \"L2=\" For i = 1 To 5
Form1.Picture2.Print Round(L2_(i, 1), 5), tab5, Picture2.Print Next i
Form1.Picture2.Print
Form1.Picture2.Print \"O2=\" For i = 1 To 5
Form1.Picture2.Print Round(O2_(i, 1), 5), tab5, Picture2.Print Next i End Sub
程序代码(Form2):
Dim A() As Double Dim B() As Double Dim n As Integer
Private Sub Form_Load() n = 5
ReDim A(n * n) As Double ReDim B(n * n) As Double
Call Cs1(A, B, n, 0)
End Sub
'------------------------------------------------------------------------------ Private Sub Qn(Ysz As Variant, Xsz As Variant, ByVal n As Integer) '求逆函数 Dim Tmpsz As Variant
ReDim Preserve Ysz(n * n) As Double '对数组的重声明 ReDim Preserve Xsz(n * n) As Double ReDim Tmpsz(2 * n * n) As Double Dim i As Integer Dim j As Integer Dim k As Integer
For i = 0 To n - 1 '将原数组转入临时数组 For j = 0 To n - 1
Tmpsz(2 * i * n + j) = Ysz(i * n + j) Next j Next i
For i = 0 To n - 1 '在后面加一个增补矩阵 For j = 0 To n - 1
Tmpsz(2 * i * n + n + j) = 0 Tmpsz(2 * i * n + n + i) = 1 Next j Next i
For i = 0 To n - 1 Dim Ik As Double
Dim Icount As Integer Icount = 0
Ik = Tmpsz(2 * i * n + i) '解决其中首数字为0的情况 If Ik = 0 Then Icount = 1
For k = i To n - 1
If Tmpsz(2 * k * n + i) <> 0 Then Icount = Icount + 1 Dim iTmp As Double
Ik = Tmpsz(2 * k * n + i)
For j = i To 2 * n - 1
iTmp = Tmpsz(2 * k * n + j)
Tmpsz(2 * k * n + j) = Tmpsz(2 * i * n + j) Tmpsz(2 * i * n + j) = iTmp Next j Exit For End If Next k End If
If Icount = 1 Then '无逆矩阵情况 Exit Sub End If
For k = i To 2 * n - 1
Tmpsz(2 * i * n + k) = Tmpsz(2 * i * n + k) / Ik '首数字变为1 Next k
For j = 0 To n - 1 '将这一列变为0 Dim Iw As Double
Iw = Tmpsz(2 * j * n + i) For k = i To 2 * n - 1 If j <> i Then
Tmpsz(2 * j * n + k) = Tmpsz(2 * j * n + k) - Iw * Tmpsz(2 * i * n + k) End If Next k Next j Next i
For i = 0 To n - 1 '将临时数组里的数传给新数组 For j = 0 To n - 1
Xsz(i * n + j) = Tmpsz(2 * i * n + n + j) Next j Next i End Sub
'------------------------------------------------------------------------------ Private Sub Cs1(ls As Variant, lx As Variant, n As Integer, Fs As Integer) Dim i As Integer Dim j As Integer
ReDim Preserve ls(n * n) As Double ReDim Preserve lx(n * n) As Double
If Fs = 0 Then
Form2.Text1(0).Move 100, 100, 1000, 400
Form2.Text1(0).Enabled = True Form2.Text1(0).Visible = True Form2.Text1(0).Text = 0
For i = 0 To n - 1 For j = 0 To n - 1
If i <> 0 Or j <> 0 Then
Load Form2.Text1(i * n + j)
Form2.Text1(i * n + j).Visible = True Form2.Text1(i * n + j).Enabled = True
Form2.Text1(i * n + j).Move 100 + 1100 * j, 100 + 500 * i, 1000, 400 Form2.Text1(i * n + j).Text = 0 End If Next j Next i End If
If Fs = 1 Then
ls(0) = Form2.Text1(0).Text For i = 0 To n - 1 For j = 0 To n - 1
ls(i * n + j) = Form2.Text1(i * n + j).Text Next j Next i End If
If Fs = 2 Then
Form2.Text1(0).Text = lx(0) For i = 0 To n - 1 For j = 0 To n - 1
Form2.Text1(i * n + j).Text = lx(i * n + j) Next j Next i End If End Sub
'------------------------------------------------------------------------------ Private Sub Text2_Change() ReDim A(n * n) As Double ReDim B(n * n) As Double
Call Cs1(A, B, n, 1) Call Qn(A, B, n) Call Cs1(A, B, n, 2) End Sub
程序二 多箱模型(通用)
程序界面:
程序代码(Form1):
Dim A() As Double Dim B() As Double Dim n As Integer
'------------------------------------------------------------------------------ '矩阵的乘法函数
Public Function MatMultiply(x() As Double, y() As Double) As Double() Dim n As Integer Dim m As Integer Dim p As Integer Dim k As Integer Dim z() As Double n = UBound(x, 1) m = UBound(x, 2) p = UBound(y, 2)
ReDim z(1 To n, 1 To p) ReDim z(n, p)
If m <> UBound(y, 1) Then
MsgBox (\"这两个矩阵不能相乘!\" + Str$(m) + Str$(UBound(y, 1))) Else: For i = 1 To n For j = 1 To m For k = 1 To p
z(i, k) = z(i, k) + x(i, j) * y(j, k) Next k Next j Next i End If
MatMultiply = z End Function
'------------------------------------------------------------------------------ Private Sub Command1_Click() ReDim A(n * n) As Double ReDim B(n * n) As Double
h = Val(Text4.Text) l = Val(Text5.Text)
ReDim u(n) As Double ReDim C(n) As Double For i = 1 To n
u(i) = Val(Text2(2 * (i - 1)).Text) C(i) = Val(Text2(2 * i - 1).Text) Next i
ReDim Q(n) As Double For i = 1 To n
Q(i) = Val(Text3(i - 1).Text) * (10 ^ 6) / (86400 * (l / n)) Next i
ReDim E(n) As Double For i = 1 To n - 1
E(i) = Val(Text10(i - 1).Text) Next i
'------------------------------------------------------------------------------ '给元素aa()、ee()赋值 ReDim aa(n) As Double For i = 1 To n
aa(i) = u(i) * l / n Next i
ReDim ee(n) As Double For i = 1 To n
ee(i) = E(i) * (l / n) / (h / n) Next i
'------------------------------------------------------------------------------ '求数组A_、D
ReDim A_(n, n) As Double A_(m, n) = 0 For i = 1 To n For j = 1 To n A_(i, j) = 0 Next j Next i
For i = 1 To n - 1 A_(i, i + 1) = -ee(i) Next i
For j = 1 To n - 1 A_(j + 1, j) = -ee(j) Next j
For k = 2 To n - 1
A_(k, k) = aa(k) + ee(n - 1) + ee(k) A_(1, 1) = aa(1) + ee(1) A_(n, n) = aa(n) + ee(n - 1) Next k
ReDim D(n, 1) As Double For i = 2 To n
D(i, 1) = aa(i) * C(i) Next i
D(1, 1) = Q(1) * (l / n) + aa(1) * C(1)
'------------------------------------------------------------------------------ '求逆矩阵AA_
ReDim AA_(n, n) As Double Form2.Text2.Text = 1
i = 1 j = 1
For k = 1 To n * n If j > n Then j = 1 i = i + 1 End If
Form2.Text1(k - 1).Text = A_(i, j) j = j + 1 Next k
Form2.Text2.Text = 2 i = 1 j = 1
For k = 1 To n * n If j > n Then j = 1 i = i + 1 End If
AA_(i, j) = Form2.Text1(k - 1).Text j = j + 1 Next k
'------------------------------------------------------------------------------ '计算第一个CC
Dim CC() As Double
CC = MatMultiply(AA_(), D())
'------------------------------------------------------------------------------ '转成最终CCC矩阵的第一列 ReDim CCC(n, n) As Double For i = 1 To n
CCC(i, 1) = CC(n + 1 - i, 1) Next i
'------------------------------------------------------------------------------ '计算其他CC并转成最终CCC矩阵的其他列
ReDim DD(n, 1) As Double For j = 1 To n - 1 For i = 1 To n
DD(i, 1) = aa(i) * CC(i, 1) Next i
DD(1, 1) = Q(j + 1) * (l / n) + aa(1) * CC(1, 1)
CC = MatMultiply(AA_(), DD())
For k = 1 To n
CCC(k, j + 1) = CC(n + 1 - k, 1) Next k Next j
'------------------------------------------------------------------------------ '输出最终的CCC值 For i = 1 To n For j = 1 To n
Form1.Picture1.Print Round(CCC(i, j), 5), Next j
Form1.Picture1.Print Next i
i = 1 j = 1
For k = 1 To n * n If j > n Then j = 1 i = i + 1 End If
Form1.Text1(k - 1).Text = CCC(i, j) j = j + 1 Next k
Call Cs1(A, B, n, 1) Call Cs1(A, B, n, 2) End Sub
'------------------------------------------------------------------------------ Private Sub Command2_Click() Picture1.Cls End Sub
'------------------------------------------------------------------------------ Private Sub Form_Load() Dim u() As Double Dim aa() As Double
Dim ee() As Double Dim A_() As Double Dim D() As Double
n = InputBox(\"请输入多箱模型的层数\输入) Text7.Text = n
For i = 0 To 2 * n - 1 Label1(i).Visible = True Text2(i).Visible = True Next i
For i = 0 To n - 1
Label2(i).Visible = True Text3(i).Visible = True Next i
If n > 1 Then
For i = 0 To (n - 1) * n - 1 Text10(i).Visible = True Next i End If
ReDim A(n * n) As Double ReDim B(n * n) As Double
Call Cs1(A, B, n, 0) End Sub
'------------------------------------------------------------------------------ Private Sub Cs1(ls As Variant, lx As Variant, n As Integer, Fs As Integer) Dim i As Integer Dim j As Integer
ReDim Preserve ls(n * n) As Double ReDim Preserve lx(n * n) As Double
If Fs = 0 Then
Form1.Text1(0).Move 100, 100, 1000, 400 Form1.Text1(0).Enabled = True Form1.Text1(0).Visible = True Form1.Text1(0).Text = \" \"
For i = 0 To n - 1 For j = 0 To n - 1
If i <> 0 Or j <> 0 Then
Load Form1.Text1(i * n + j)
Form1.Text1(i * n + j).Visible = True Form1.Text1(i * n + j).Enabled = True
Form1.Text1(i * n + j).Move 100 + 1100 * j, 100 + 500 * i, 1000, 400 Form1.Text1(i * n + j).Text = \" \" End If Next j Next i End If
If Fs = 1 Then
ls(0) = Form1.Text1(0).Text For i = 0 To n - 1 For j = 0 To n - 1
ls(i * n + j) = Form1.Text1(i * n + j).Text Next j Next i End If
If Fs = 2 Then
Form1.Text1(0).Text = lx(0) For i = 0 To n - 1 For j = 0 To n - 1
Form1.Text1(i * n + j).Text = lx(i * n + j) Next j Next i End If End Sub
'------------------------------------------------------------------------------ Private Sub Text8_Change() If n > 1 Then
For i = 0 To (n - 1) * n - 1 Text10(i).Text = Text8.Text Next i End If End Sub
程序代码(Form2):
Dim A() As Double Dim B() As Double Dim n As Integer
'------------------------------------------------------------------------------ Private Sub Form_Load()
n = Form1.Text7.Text ReDim A(n * n) As Double ReDim B(n * n) As Double
Call Cs1(A, B, n, 0) End Sub
'------------------------------------------------------------------------------ Private Sub Qn(Ysz As Variant, Xsz As Variant, ByVal n As Integer) '求逆函数 Dim Tmpsz As Variant
ReDim Preserve Ysz(n * n) As Double '对数组的重声明
ReDim Preserve Xsz(n * n) As Double ReDim Tmpsz(2 * n * n) As Double Dim i As Integer Dim j As Integer Dim k As Integer
For i = 0 To n - 1 ' For j = 0 To n - 1
Tmpsz(2 * i * n + j) = Ysz(i * n + j) Next j Next i
For i = 0 To n - 1 ' For j = 0 To n - 1
Tmpsz(2 * i * n + n + j) = 0 Tmpsz(2 * i * n + n + i) = 1 Next j Next i
For i = 0 To n - 1 Dim Ik As Double
Dim Icount As Integer Icount = 0
Ik = Tmpsz(2 * i * n + i) ' If Ik = 0 Then Icount = 1
For k = i To n - 1
If Tmpsz(2 * k * n + i) <> 0 Then Icount = Icount + 1 Dim iTmp As Double
Ik = Tmpsz(2 * k * n + i) For j = i To 2 * n - 1
将原数组转入临时数组 在后面加一个增补矩阵 解决其中首数字为0的情况 iTmp = Tmpsz(2 * k * n + j)
Tmpsz(2 * k * n + j) = Tmpsz(2 * i * n + j) Tmpsz(2 * i * n + j) = iTmp Next j Exit For End If Next k End If
If Icount = 1 Then '无逆矩阵情况 Exit Sub End If
For k = i To 2 * n - 1
Tmpsz(2 * i * n + k) = Tmpsz(2 * i * n + k) / Ik '首数字变为1 Next k
For j = 0 To n - 1 '将这一列变为0 Dim Iw As Double
Iw = Tmpsz(2 * j * n + i)
For k = i To 2 * n - 1 If j <> i Then
Tmpsz(2 * j * n + k) = Tmpsz(2 * j * n + k) - Iw * Tmpsz(2 * i * n + k) End If Next k Next j Next i
For i = 0 To n - 1 '将临时数组里的数传给新数组 For j = 0 To n - 1
Xsz(i * n + j) = Tmpsz(2 * i * n + n + j) Next j Next i End Sub
'------------------------------------------------------------------------------ Private Sub Cs1(ls As Variant, lx As Variant, n As Integer, Fs As Integer) Dim i As Integer Dim j As Integer
ReDim Preserve ls(n * n) As Double ReDim Preserve lx(n * n) As Double
If Fs = 0 Then
Form2.Text1(0).Move 100, 100, 1000, 400
Form2.Text1(0).Enabled = True Form2.Text1(0).Visible = True Form2.Text1(0).Text = 0
For i = 0 To n - 1 For j = 0 To n - 1
If i <> 0 Or j <> 0 Then
Load Form2.Text1(i * n + j)
Form2.Text1(i * n + j).Visible = True Form2.Text1(i * n + j).Enabled = True
Form2.Text1(i * n + j).Move 100 + 1100 * j, 100 + 500 * i, 1000, 400 Form2.Text1(i * n + j).Text = 0 End If Next j Next i End If
If Fs = 1 Then
ls(0) = Form2.Text1(0).Text For i = 0 To n - 1 For j = 0 To n - 1
ls(i * n + j) = Form2.Text1(i * n + j).Text Next j Next i End If
If Fs = 2 Then
Form2.Text1(0).Text = lx(0) For i = 0 To n - 1 For j = 0 To n - 1
Form2.Text1(i * n + j).Text = lx(i * n + j) Next j Next i End If End Sub
'------------------------------------------------------------------------------ Private Sub Text2_Change() ReDim A(n * n) As Double ReDim B(n * n) As Double
Call Cs1(A, B, n, 1) Call Qn(A, B, n) Call Cs1(A, B, n, 2) End Sub
因篇幅问题不能全部显示,请点此查看更多更全内容