matlab数值分析程序--高等数学,数值代数的matlab实现-文字版, matlab电子书, 和matlab 有关的电子书:

5.4.3 雅可比方法的MATLAB程序

5.4.3  雅可比方法的MATLAB程序

用雅可比方法计算对称矩阵的特征值和对应的特征向量的MATLAB主程序

function [k,Bk,V,D,Wc]=jacobite(A,jd,max1)

[n,n]=size(A);Vk=eye(n);Bk=A;state=1;k=0;P0=eye(n);

Aij=abs(Bk-diag(diag(Bk)));[m1 i]=max(Aij);

[m2 j]=max(m1);i=i(j);

while ((k<=max1)&(state==1))

k=k+1,aij=abs(Bk-diag(diag(Bk)));[m1 i]=max(abs(aij));

[m2 j]=max(m1);i=i(j),j,Aij=(Bk-diag(diag(Bk)));

mk=m2*sign(Aij(i,j)),

Wc=m2,Dk=diag(diag(Bk));Pk=P0;

c=(Bk(j,j)-Bk(i,i))/(2*Bk(i,j)),

t=sign(c)/(abs(c)+sqrt(1+c^2)),

pii=1/( sqrt(1+t^2)), pij=t/( sqrt(1+t^2)),

Pk(i,i)=pii;Pk(i,j)=pij;

Pk(j,j)=pii; Pk(j,i)=-pij;

Pk,B1=Pk'*Bk;B2=B1*Pk; Vk=Vk*Pk,Bk=B2,

if(Wc>jd)

state=1;

else

       return

end

Pk;Vk;Bk=B2;Wc;

end

if(k>max1)

disp('请注意迭代次数k已经达到最大迭代次数max1,迭代次数k,对称矩阵Bk,以特征向量为列向量的矩阵V,特征值为对角元的对角矩阵D如下:')

else

disp('请注意迭代次数k,对称矩阵Bk,以特征向量为列向量的矩阵V,特征值为对角元的对角矩阵D如下:') 

end

Wc;k=k; V=Vk;Bk=B2;D=diag(diag(Bk));[V1,D1] =eig(A,'nobalance')

 

例5.4.2  用雅可比方法的MATLAB程序计算矩阵的特征值和对应的特征向量).

解 (1)保存名为jacobite.m为M文件;

(2)输入MATLAB程序

 >> A=[12 -56 3 -1;-56 7 2 0;3 2 5 1;-1 0 1 12];

[k,B,V,D,Wc]=jacobite(A,0.001,100)

(3)运行后屏幕显示如下:

k =        i =         j =          mk =         Wc =

1         2          1             -56            56

c =                          t =

  -0.04464285714286            -0.95635313919972

pii =                         pij =

   0.72270271801843            -0.69115901308510

Pk =

   0.72270271801843   0.69115901308510                  0                  0

  -0.69115901308510   0.72270271801843                  0                  0

                  0                  0   1.00000000000000                  0

                  0                  0                  0   1.00000000000000

Vk =

   0.72270271801843   0.69115901308510                  0                  0

  -0.69115901308510   0.72270271801843                  0                  0

                  0                  0   1.00000000000000                  0

                  0                  0                  0   1.00000000000000

Bk =

  65.55577579518456                  0   0.78579012788509  -0.72270271801843

  -0.00000000000001 -46.55577579518456   3.51888247529217  -0.69115901308510

   0.78579012788509   3.51888247529217   5.00000000000000   1.00000000000000

  -0.72270271801843  -0.69115901308510   1.00000000000000  12.00000000000000

k =   i =     j =     mk =                      Wc =

 2     3      2        3.51888247529217          3.51888247529217

c =                         t =

  -7.32558932518824          -0.06793885568129

pii =                       pij =

   0.99770011455446          -0.06778260409592

Pk =

   1.00000000000000                  0                  0                  0

                  0   0.99770011455446   0.06778260409592                  0

                  0  -0.06778260409592   0.99770011455446                  0

                  0                  0                  0   1.00000000000000

Vk =

   0.72270271801843   0.68956942653035   0.04684855775127                  0

  -0.69115901308510   0.72104058455581   0.04898667221449                  0

                  0  -0.06778260409592   0.99770011455446                  0

                  0                  0                  0   1.00000000000000

Bk =

  65.55577579518456  -0.05326290114092   0.78398290060672  -0.72270271801843

  -0.05326290114093 -46.79484464383285                  0  -0.75735203062627

   0.78398290060672   0.00000000000000   5.23906884864829   0.95085155680318

  -0.72270271801843  -0.75735203062627   0.95085155680318  12.00000000000000

k =    i =    j =        mk =                      Wc =

  3     4      3          0.95085155680318          0.95085155680318

c = t =

  -3.55519802380213  -0.13796227443116

pii =                       pij =

   0.99061693994324          -0.13666776612460

Pk =

   1.00000000000000                  0                  0                  0

                  0   1.00000000000000                  0                  0

                  0                  0   0.99061693994324   0.13666776612460

                  0                  0  -0.13666776612460   0.99061693994324

Vk =

   0.72270271801843   0.68956942653035   0.04640897492032   0.00640268773403

  -0.69115901308510   0.72104058455581   0.04852702732712   0.00669489906143

                  0  -0.06778260409592   0.98833863446096   0.13635344591842

                  0                  0  -0.13666776612460   0.99061693994324

Bk =

  65.55577579518456  -0.05326290114092   0.87539690801061  -0.60877636330628

  -0.05326290114093 -46.79484464383285   0.10350561019562  -0.75024575103880

   0.87539690801061   0.10350561019562   5.10788720522532  -0.00000000000000

  -0.60877636330628  -0.75024575103880  -0.00000000000000  12.13118164342297

k =     i =       j =       mk =                      Wc =

  4       1       3           0.87539690801061         0.87539690801061

c =                        t =

 -34.52598931799430          -0.01447880833914

pii =                       pij =

   0.99989519853186          -0.01447729093877

Pk =

   0.99989519853186                  0  -0.01447729093877                  0

                  0   1.00000000000000                  0                  0

   0.01447729093877                  0   0.99989519853186                  0

                  0                  0                  0   1.00000000000000

Vk =

   0.72329885394465   0.68956942653035   0.03594133368062   0.00640268773403

  -0.69038403871280   0.72104058455581   0.05852805174080   0.00669489906143

   0.01430846595712  -0.06778260409592   0.98823505512105   0.13635344591842

  -0.00197857901214                  0  -0.13665344314206   0.99061693994324

Bk =

  65.56845049923633  -0.05175883827808  -0.00000000000000  -0.60871256264964

  -0.05175883827809 -46.79484464383285   0.10426586517177  -0.75024575103880

  -0.00000000000000   0.10426586517177   5.09521250117356   0.00881343252823

  -0.60871256264964  -0.75024575103880   0.00881343252823  12.13118164342297

k =      i =      j =      mk =                      Wc =

    5      4      2         -0.75024575103880          0.75024575103880

c =                               t =

  39.27114962375084                 0.01272992971264

pii =                              pij =

   0.99991898429114                  0.01272889838836

Pk =

   1.00000000000000                  0                  0                  0

                  0   0.99991898429114                  0  -0.01272889838836

                  0                  0   1.00000000000000                  0

                  0   0.01272889838836                  0   0.99991898429114

Vk =

   0.72329885394465   0.68959505973603   0.03594133368062  -0.00237529014628

  -0.69038403871280   0.72106738763160   0.05852805174080  -0.00248369566525

   0.01430846595712  -0.06604148348220   0.98823505512105   0.13720519702737

  -0.00197857901214   0.01260946237032  -0.13665344314206   0.99053668440964

Bk =

  65.56845049923633  -0.05950288535679  -0.00000000000000  -0.60800441437674

  -0.05950288535680 -46.80439521951078   0.10436960328590   0.00000000000000

  -0.00000000000000   0.10436960328590   5.09521250117356   0.00748552889860

  -0.60800441437674   0.00000000000000   0.00748552889860  12.14073221910090

k =     i =       j =        mk =                    Wc =

  6      4         1         -0.60800441437674          0.60800441437674

c =                                t =

 -43.93694931878409                 -0.01137847012503

pii =                               pij =

   0.99993527149402                 -0.01137773361366

Pk =

   0.99993527149402                  0                  0   0.01137773361366

                  0   1.00000000000000                  0                  0

                  0                  0   1.00000000000000                  0

  -0.01137773361366                  0                  0   0.99993527149402

Vk =

   0.72327906130899   0.68959505973603   0.03594133368062   0.00585436528595

  -0.69031109235777   0.72106738763160   0.05852805174080  -0.01033854058294

   0.01274645560931  -0.06604148348220   0.98823505512105   0.13735911385404

  -0.01324851347145   0.01260946237032  -0.13665344314206   0.99045005670500

Bk =

  65.57536865930122  -0.05949903382392  -0.00008516835377  -0.00000000000000

  -0.05949903382393 -46.80439521951078   0.10436960328590  -0.00067700797883

  -0.00008516835377   0.10436960328590   5.09521250117356   0.00748504437150

  -0.00000000000000  -0.00067700797883   0.00748504437150  12.13381405903603

k =     i =     j =       mk =                      Wc =

   7     3      2          0.10436960328590           0.10436960328590

c =                                 t =

   -2.486337309269764e+002           -0.00201098208240

pii =                               pij =

   0.99999797798167                   -0.00201097801616

Pk =

   1.00000000000000                  0                  0                  0

                  0   0.99999797798167   0.00201097801616                  0

                  0  -0.00201097801616   0.99999797798167                  0

                  0                  0                  0   1.00000000000000

…………………………………………………………………………

请注意迭代次数k,对称矩阵Bk,以特征向量为列向量的矩阵V,特征值为对角元的对角矩阵D如下:

V1 =

   0.68990429476497  -0.03732423222484   0.00588594854431  -0.72291377173450

   0.72058252860300  -0.05998661236737  -0.01028322161977   0.69069289931337

  -0.06802029759277  -0.98795368410472   0.13841044442471  -0.01277912569225

   0.01288885768193   0.13768088498200   0.99030407443219   0.01325486405899

D1 =

 -46.80463661419736                  0                  0                  0

                  0   5.09541442877727                  0                  0

                  0                  0  12.13382202426702                  0

                  0                  0                  0  65.57540016115307

k =

    10

B =

  65.57540016045945   0.00000000000175  -0.00020481967566   0.00000014862836

   0.00000000000175 -46.80463661419739   0.00000062739984   0.00000000000000

  -0.00020481967566   0.00000062739984   5.09541442947090  -0.00000000000737

   0.00000014862836  -0.00000000000000  -0.00000000000737  12.13382202426704

V =

   0.72291389811507   0.68990429521617   0.03732177568689   0.00588595055487

  -0.69069269613201   0.72058252932816   0.05998894273570  -0.01028322354062

   0.01278247108107  -0.06802028564977   0.98795364164379   0.13841044446122

  -0.01325533307898   0.01288885601755  -0.13768084024946   0.99030407439520

D =

  65.57540016045945                   0                  0                  0

                  0  -46.80463661419739                  0                  0

                  0                   0   5.09541442947090                  0

                  0                   0                  0  12.13382202426704

Wc =

    6.920584967017158e-004


欢迎转载,转载请注明来自一手册:http://yishouce.com/book/3/3050403.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1