Graphics Programs Reference
In-Depth Information
Solution of Part (2) The problemwith the Jacobimethodisthat it insists onfinding all
the eigenvalues and eigenvectors. It is also incapable of exploiting banded structures
of matrices. Thus the program listedbelowdoes much more workthan necessary for
the problemathand. Moreefficient methodsofsolutionwill be introduced laterin
thischapter.
% Example 9.3 (Jacobi method)
n = 10;
% Number of interior nodes.
A=zeros(n);B=zeros(n);
%StartconstructingAandB.
fori=1:n
A(i,i) = 6; B(i,i) = 2;
end
A(1,1) = 5; A(n,n) = 7;
fori=1:n-1
A(i,i+1) = -4; A(i+1,i) = -4;
B(i,i+1) = -1; B(i+1,i) = -1;
end
fori=1:n-2
A(i,i+2) = 1; A(i+2,i) = 1;
end
[H,T] = stdForm(A,B); % Convert to std. form.
[eVals,Z] = jacobi(H); % Solve by Jacobi method.
X = T*Z; % Eigenvectors of orig. prob.
fori=1:n %Normalizeeigenvectors.
xMag = sqrt(dot(X(:,i),X(:,i)));
X(:,i) = X(:,i)/xMag;
end
[eVals,X] = sortEigen(eVals,X); % Sort in ascending order.
eigenvalues = eVals(1:3)'
% Extract 3 smallest
eigenvectors = X(:,1:3)
% eigenvalues & vectors.
Running the program resultedinthe following output:
>> eigenvalues =
0.1641
0.4720
0.9022
eigenvectors =
0.1641
-0.1848
0.3070
0.3062
-0.2682
0.3640
0.4079
-0.1968
0.1467
0.4574
0.0099
-0.1219
Search WWH ::




Custom Search