Homework Assignment #4

Homework Assignment #4 - %Michael Carlson %September 11th,...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
%Michael Carlson %September 11th, 2006 %Assignment #4 %This is an implementation of the Jacobi Iterative method N = input('Enter maximum number of iterations:'); A = input('Enter matrix A:'); b = input('Enter matrix b:'); TOL = input('Enter the tolerance:'); % Intial Values n = size(A,1); L = zeros(n); U = zeros(n); k = 1; x(:,1) = zeros(n,1); for i = 1:n D(i,i) = A(i,i); end for i = 2:n for j = 1:i-1 L(i,j) = -A(i,j); end end for i = 1:n-1 for j = i+1:n U(i,j) = -A(i,j); end end % Jacobi Iterative Method T = inv(D)*(L+U); c = inv(D)*b; while k <= N x(:,k+1) = T*x(:,k) + c; if norm(x(:,k+1)-x(:,k),inf) < TOL disp('The procedure was successful') k
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
x = x(:,k+1) return end k = k+1; end if norm(x(:,k)- x(:,k-1),inf) > TOL | k > N disp('Maximum number of iterations exceeded') end A.) >> jacobi Enter maximum number of iterations:2 Enter matrix A:[3 -1 1; 3 6 2; 3 3 7] Enter matrix b:[1; 0; 4] Enter the tolerance:10^(-3) Maximum number of iterations exceeded >> x x = 0 0.33333333333333 0.14285714285714 0 0 -0.35714285714286 0 0.57142857142857 0.42857142857143 B.) >> jacobi Enter maximum number of iterations:2 Enter matrix A:[10 -1 0; -1 10 -2; 0 -2 10] Enter matrix b:[9; 7; 6] Enter the tolerance:10^(-3) Maximum number of iterations exceeded >> format long >> x x = 0 0.90000000000000 0.97000000000000 0 0.70000000000000 0.91000000000000 0 0.60000000000000 0.74000000000000 C.) >> jacobi Enter maximum number of iterations:2 Enter matrix A:[10 5 0 0; 5 10 -4 0; 0 -4 8 -1; 0 0 -1 5] Enter matrix b:[6; 25; -11; -11]
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/01/2009 for the course PSTAT 120A taught by Professor Mackgalloway during the Spring '08 term at UCSB.

Page1 / 9

Homework Assignment #4 - %Michael Carlson %September 11th,...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online