Page 250 - MATLAB an introduction with applications
P. 250
Numerical Methods ——— 235
–1
2. The spectral radius of the matrix (D + L) * U must have a modulus < 1 for the iteration to work
correctly. Think of the spectral radius (the largest value of the set of eigenvalue modules) as being the
greatest scalar factor that can be applied to a vector. If it is greater than 1, iteration on the corresponding
eigenvector will result in an infinite limit.
Complete MATLAB program for solving given system of equations is given below:
% The display consists of a table of x-values with iterates of x1, x2, ..., xn
% in each column.
A = [1 2 1;3 1 –1;1 –1 4];b = [0;0;3];
X0 = zeros(size(b)); % starting vector
tole = 1e–6;kstop = 30;% error tolerance and max. iterations
[n,n] = size(A);
P = tril(A);% lower triangular form
k = 0;r = b–A*X0;
r0 = norm(r);er = norm(r);
X = X0;
[L,U] = lu(P);
fprintf(‘iter#\tX(1)\t\tX(2)\n’);
while er>tole & k<kstop
fprintf(‘%d\t%f\t%f\n’,k,X(1),X(2));
k = k+1;
dx = L\r;
dx = U\dx;
X = X+dx;
r = b–A X;
*
er = norm(r)/r0;
erp(k) = norm(r)/r0;
end
X
plot(erp, ‘–p’);
grid on;
xlabel(‘Iteration #’);
ylabel(‘normalized error’);
Output of the program is as follows:
Final solution is X =
1.0e + 024 *
–1.7510
5.5007
1.8129