新人对VB的困惑!求达人解答,不胜感激!
我在用VB写高斯算法的问题,AX=B的方程组.A是一个10*10的矩阵,其主对角线的元素全是-10,其余的全为1,关于矩阵的赋值问题,老是提示我溢出错误,为什么??谢谢各位,俺在线等!!
Option Explicit
Dim a() As Double
Dim b() As Double
Public Function Guass(n As Integer) As Double
Dim k As Integer '未知数的个数
Dim i As Integer
Dim j As Integer
Dim StoreNum As Double '存数据
Dim StoreIndex As Integer '保存下标
Dim MultiNum As Double '保存乘子
For k = 1 To n - 1
For i = k + 1 To n '消元
MultiNum = a(i, k) / a(k, k) '计算乘子
For j = k + 1 To n
a(i, j) = a(i, j) - MultiNum * a(k, j)
Next
b(i) = b(i) - MultiNum * b(k)
Next
Next
'到此原函数的系数矩阵已经是上三角了
'下面要做的是回代,解保存在b()中
For i = n To 1 Step -1
StoreNum = 0
For j = i + 1 To n Step 1
StoreNum = StoreNum + a(i, j) * b(j)
Next
b(i) = (b(i) - StoreNum) / a(i, i)
Next
Guass = b
End Function
Private Sub command1_click()
Dim i As Integer, j As Integer
Dim a() As Double, b() As Double
For i = 0 To 9
For j = 0 To 9
Do While (i = j)
a(i, j) = -10
Loop
Do While (i > j & i < j)
a(i, j) = 1
Loop
Next
b(i) = 1
Next
Text1.Text = Guass(10)
End Sub