jacobi1.m

来自「国外计算机科学教材系列 numerial method using matla」· M 代码 · 共 50 行

M
50
字号
function [V,D]=jacobi1(A,epsilon)%Input - A is an nxn matrix%      - epsilon the is tolerance%Output - V is the nxn matrix of eigenvectors%       - D is the diagonal nxn matrix of eigenvalues%Initialize V, D, and parameters% NUMERICAL METHODS: MATLAB Programs%(c) 1999 by John H. Mathews and Kurtis D. Fink%To accompany the textbook:%NUMERICAL METHODS Using MATLAB,%by John H. Mathews and Kurtis D. Fink%ISBN 0-13-270042-5, (c) 1999%PRENTICE HALL, INC.%Upper Saddle River, NJ 07458D=A;[n,n]=size(A);V=eye(n);state=1;%Calculate row p and column q of the off-diagonal element%of greatest magnitude in A[m1 p]=max(abs(D-diag(diag(D))));[m2 q]=max(m1);p=p(q);while (state==1)   %Zero out Dpq and Dqp   t=D(p,q)/(D(q,q)-D(p,p));   c=1/sqrt(t^2+1);   s=c*t;   R=[c s;-s c];   D([p q],:)=R'*D([p q],:);   D(:,[p q])=D(:,[p q])*R;   V(:,[p q])=V(:,[p q])*R;   [m1 p]=max(abs(D-diag(diag(D))));   [m2 q]=max(m1);   p=p(q);   if (abs(D(p,q))<epsilon*sqrt(sum(diag(D).^2)/n))      state=0;   endendD=diag(diag(D));

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?