Private Sub Command1_Click()
'program D1R9
'Driver program for routine SPARSE
N = 20
Dim B(20), X(20), BCMP(20)
'输入已知的方程组的右端向量B
For I = 1 To N
X(I) = 0#
B(I) = 1#
Next I
B(1) = 3#
B(N) = -1#
'利用下列子程序ASUB输入已知的方程组的系数矩阵
Call SPARSE(B(), N, X(), RSQ)
Print
Print Tab(5); "Sum - squared residual:", RSQ
Print
Print Tab(5); "计算出的方程组的解"
For I = 1 To 4
For J = I * 5 - 4 To I * 5
Print Tab((J - (I - 1) * 5) * 9); Format$(X(J), "#.####E+00");
Next J
Print
Next I
'将计算出的方程组的解乘以系数矩阵,以验证计算结果正确
Call ASUB(X(), BCMP())
Print
Print Tab(5); "计算出的方程组的解乘以系数矩阵的结果"
Print
Print Tab(7); "解乘以系数矩阵"; Tab(25); "方程组的右端向量"
For I = 1 To N
Print Tab(13); Format$(BCMP(I), "##.##"); Tab(32); Format$(B(I), "##.##")
Next I
End Sub
Sub ASUB(XIN(), XOUT())
N = 20
XOUT(1) = XIN(1) + 2# * XIN(2)
XOUT(N) = -2# * XIN(N - 1) + XIN(N)
For I = 2 To N - 1
XOUT(I) = -2# * XIN(I - 1) + XIN(I) + 2# * XIN(I + 1)
Next I
End Sub
Sub ATSUB(XIN(), XOUT())
N = 20
XOUT(1) = XIN(1) - 2# * XIN(2)
XOUT(N) = 2# * XIN(N - 1) + XIN(N)
For I = 2 To N - 1
XOUT(I) = 2# * XIN(I - 1) + XIN(I) - 2# * XIN(I + 1)
Next I
End Sub