首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

有关雅克比迭代的有关问题

2012-03-15 
有关雅克比迭代的问题各位前辈,小弟分别用VB.NET和matlab编了雅克比迭代计算程序,可是运行出来的结果却有

有关雅克比迭代的问题
各位前辈,小弟分别用VB.NET和matlab编了雅克比迭代计算程序,可是运行出来的结果却有偏差,已知matlab的结果是正确的,想请教各位帮忙给看看VB.NET版的程序哪里有问题。谢谢各位了!!
matlab版的:

Assembly code
          clear allclca=[2028.977 0 0 0 0 0 0 0;...    214.036 2126.041 0 0 0 0 0 0;...    117.6175 117.6175 2535.178 0 0 0 0 0;...    107.6837 107.6837 107.6837 2467.399 0 0 0 0;...    92.44788 92.44788 92.44788 92.44788 2375.027 0 0 0;...    156.3591 156.3591 156.3591 156.3591 83.33392 2343.634 0 0;...    152.769 152.769 152.769 152.769 303.2207 303.2207 2444.594 0;...    95.47997 95.47997 95.47997 95.47997 95.47997 95.47997 95.47997 2237.363;]t=[98.78857 215.5781 119.2549 62.34533 94.91241 158.5648 154.924 96.82684]d=[0 0 0 31.94817 0 0 9.221128 3.941186]c=(t-d)'zz=a\cA=a;b=c;D=0;n=1;%-------------------------Jacobi迭代------------------------%for i=1:8    x(i)=0;endfor i=1:8    y(i)=b(i);    for j=1:i-1        y(i)=y(i)-A(i,j)*x(j);    end    for j=i+1:8        y(i)=y(i)-A(i,j)*x(j);    end    y(i)=y(i)/A(i,i);    if abs(x(i)-y(i))>0        D=abs(x(i)-y(i));    endendfor i=1:8    x(i)=y(i);endwhile D>=0.001                  %循环条件,误差小于0.001    D=0;    n=n+1;                      %总循环次数for i=1:8    y(i)=b(i);    for j=1:i-1        y(i)=y(i)-A(i,j)*x(j);    end    for j=i+1:8        y(i)=y(i)-A(i,j)*x(j);    end    y(i)=y(i)/A(i,i);    if abs(x(i)-y(i))>0        D=abs(x(i)-y(i));    endendfor i=1:8    x(i)=y(i);endendn;x

运行结果为:x =

  Columns 1 through 7

  0.0487 0.0965 0.0403 0.0042 0.0326 0.0538 0.0370

  Column 8

  0.0281

以下为vb.net版的:
VB.NET code
 Public Function Jacobi(ByVal a(,) As Double, ByVal b() As Double, ByVal n As Integer)        Dim x(), D As Double        Dim y() As Double        Dim i, j As Integer        ReDim Preserve x(n), y(n)        For i = 0 To n            x(i) = 0        Next        For i = 0 To n            y(i) = b(i)            For j = 0 To (i - 1)                y(i) = y(i) - a(i, j) * x(j)            Next            For j = (i + 1) To n                y(i) = y(i) - a(i, j) * x(j)            Next            y(i) = y(i) / a(i, i)            If Math.Abs(x(i) - y(i)) > 0 Then                D = Math.Abs(x(i) - y(i))            End If        Next        For i = 0 To n            x(i) = y(i)        Next        Do While D >= 0.001            D = 0            For i = 0 To n                y(i) = b(i)                For j = 0 To (i - 1)                    y(i) = y(i) - a(i, j) * x(j)                Next                For j = (i + 1) To n                    y(i) = y(i) - a(i, j) * x(j)                Next                y(i) = y(i) / a(i, i)                If Math.Abs(x(i) - y(i)) > 0 Then                    D = Math.Abs(x(i) - y(i))                End If            Next            For i = 0 To n                x(i) = y(i)            Next        Loop        Jacobi = x    End Function

运行结果为:
  0.048688856192823 0.0948903844893924 0.0403787912386672 0.0422911135065462 0.0326346869549203 0.0539362563014407 0.0370861813589856 0.0281852904964822 

注意第二个参数偏差比较大!

[解决办法]
你的程序我没细看,也没时间仔细看。我说说我的看法,矩阵求逆,矩阵相乘,矩阵转置,这三个运算都能实现了,估计就没问题了吧。
我不知道我理解的对不对,还有个线性化问题,一般写成x=x0+dx,y=y0+dy...的形式,然后化为dx,dy,。。的函数,每次矩阵除法运算之后把dx,dy,。。加到上一次的结果之上
不知道是不是这样?
这种多重for循环的检查起来很费劲,还是要靠自己调试的,我有c#的求逆,乘积,转置的程序,如果你需要,我可以贴上

热点排行