求助大神,迭代求方程组的解,帮忙看看那里错了
Private Sub Form_Click()Dim x() As Integer, y() As Integer, a() As Integer, b() As Integer, c() As Integer
ReDim x(11, 3), y(11, 3), a(11, 3), b(11, 3), c(11, 3)
x(0, 0) = 1.0026: y(0, 0) = 0: x(0, 1) = 1.145: y(0, 1) = -0.0059: x(0, 2) = 1.2299: y(0, 2) = -0.0094
x(1, 0) = 0.9712: y(1, 0) = -0.0052: x(1, 2) = 0.9872: y(1, 2) = -0.1242
x(2, 0) = 0.6792: y(2, 0) = -0.0386: x(2, 2) = 0.6907: y(2, 2) = -0.1581
x(3, 0) = 0.4473: y(3, 0) = -0.0559: x(3, 2) = 0.4538: y(3, 2) = -0.1759
x(4, 0) = 0.1654: y(4, 0) = -0.0549: x(4, 2) = 0.154: y(4, 2) = -0.1744
x(5, 0) = 0: y(4, 0) = 0: x(5, 2) = -0.12: y(5, 2) = 0
x(6, 0) = 0.1654: y(6, 0) = 0.0549: x(6, 2) = 0.154: y(6, 2) = 0.1744
x(7, 0) = 0.4473: y(7, 0) = 0.0559: x(7, 2) = 0.4538: y(7, 2) = 0.1759
x(8, 0) = 0.6792: y(8, 0) = 0.0386: x(8, 2) = 0.6907: y(8, 2) = 0.1581
x(9, 0) = 0.9712: y(9, 0) = 0.0052: x(9, 2) = 0.9872: y(9, 2) = 0.1242
x(10, 0) = 1.0026: y(10, 0) = 0: x(10, 1) = 1.145: y(10, 1) = -0.0059: x(10, 2) = 1.2299: y(10, 2) = -0.0094
x(1, 1) = 1: x(2, 1) = 1: x(3, 1) = 1: x(4, 1) = 1: x(5, 1) = 1: x(6, 1) = 1: x(7, 1) = 1: x(8, 1) = 1: x(9, 1) = 1:
y(1, 1) = 1: y(2, 1) = 1: y(3, 1) = 1: y(4, 1) = 1: y(5, 1) = 1: y(6, 1) = 1: y(7, 1) = 1: y(8, 1) = 1: y(9, 1) = 1:
Do
For i = 1 To 9
j = 1
a(i, j) = (x(i, j + 1) - x(i, j - 1)) ^ 2 / 0.32 + (y(i, j + 1) - y(i, j - 1)) ^ 2 / 0.32
b(i, j) = (x(i + 1, j) - x(i - 1, j)) * (x(i, j + 1) - x(i, j - 1)) / 0.32 + (y(i + 1, j) - y(i - 1, j)) * (y(i, j + 1) - y(i, j - 1)) / 0.32
c(i, j) = (x(i + 1, j) - x(i - 1, j)) ^ 2 / 0.08 + (y(i + 1, j) - y(i - 1, j)) ^ 2 / 0.08
bw = be = a(i, j) / 0.04
bs = bn = c(i, j) / 0.16
bp = a(i, j) / 0.02 + c(i, j) / 0.08
cpx = -b(i, j) * (x(i + 1, j + 1) - x(i + 1, j - 1) - x(i - 1, j + 1) + x(i - 1, j - 1)) / 0.16
cpy = -b(i, j) * (y(i + 1, j + 1) - y(i + 1, j - 1) - y(i - 1, j + 1) + y(i - 1, j - 1)) / 0.16
x(i, j) = (bw * x(i - 1, j) + be * x(i + 1, j) + bs * x(i, j - 1) + bn * x(i, j + 1) + cpx) / bp
y(i, j) = (bw * y(i - 1, j) + be * y(i + 1, j) + bs * y(i, j - 1) + bn * y(i, j + 1) + cpy) / bp
Next i
Loop While x(i, j) - (bw * x(i - 1, j) + be * x(i + 1, j) + bs * x(i, j - 1) + bn * x(i, j + 1) + cpx) / bp > 0.0001 And y(i, j) - (bw * y(i - 1, j) + be * y(i + 1, j) + bs * y(i, j - 1) + bn * y(i, j + 1) + cpy) / bp > 0.0001
For i = 1 To 9
j = 1
Print x(i, j), x(i, j)
Next i
End Sub
要求解的是18个方程,18个未知数的方程组的解。
利用迭代,给出初始值,Do loop循环,当上一个值减去下一个值达到一个极小量时,跳出循环。
可以先不管这些,看看语法有错吗,相当于二维数组x(i,j),其中j是1.用FOr语句写出18个方程,然后用DO语句循环迭代解这18个方程,最上面给出的是已知条件和初始迭代值(全选为1),可是最后输出的结果全是0,这是怎么回事?