| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1839 人关注过本帖
标题:求助大神,迭代求方程组的解,帮忙看看那里错了
只看楼主 加入收藏
a498818532
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2016-4-6
结帖率:0
收藏
已结贴  问题点数:20 回复次数:1 
求助大神,迭代求方程组的解,帮忙看看那里错了
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,这是怎么回事?
搜索更多相关主题的帖子: 方程组 
2016-04-06 10:15
chen3523
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:33
帖 子:223
专家分:1165
注 册:2013-2-12
收藏
得分:20 
问题在:dim x() As Integer。运行下列代码,你自知
Private Sub Form_Load()
Dim x(2) As Integer, c(1)
x(0) = 0.123
x(1) = 1.233
c(0) = 0.224
MsgBox "x(0)=" & x(0) & "  x(1)=" & x(1) & "  c(0)=" & c(0)
End Sub


[此贴子已经被作者于2016-4-7 10:30编辑过]


调试失败3次后,关机睡觉,当醒来时多有收获。
2016-04-06 17:11
快速回复:求助大神,迭代求方程组的解,帮忙看看那里错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.039373 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved