s04 - Ma 449: Numerical Applied Mathematics Model Solutions...

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

View Full Document Right Arrow Icon
Ma 449: Numerical Applied Mathematics Model Solutions to Homework Assignment 4 Prof. Wickerhauser Exercise 6 of Section 3.4, p.138. >> X=[1 1 1 ; 1 2 4 ; 1 3 9 ] X = 1. 1. 1. 1. 2. 4. 1. 3. 9. >> Y=[6;5;2] Y = 6. 5. 2. >> ABC=inv(X)*Y = ABC = 5. 2. -1. Exercise 11 of Section 3.4, p.138. >> A=[1 2 0 0 ; 2 3 -1 0 ; 0 4 2 3 ; 0 0 2 -4] A = 1 2 0 0 2 3 -1 0 0 4 2 3 0 0 2 -4 >> b=[7 9 10 12]' b = 7 9 10 12 >> A\b ans = 1 3 2 -2 You may also solve this by forward elimination and back substitution. Algorithm 1 of Section 3.4, p.140. MATLAB Program: % Tridiagonal matrix solver % Indexing: % % Diagonals of the matrix: Right-hand side: % D(1) C(1) B(1) % A(1) D(2) C(2) B(2)
Background image of page 1

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

View Full DocumentRight Arrow Icon
% A(2) D(3) C(3) . % ... . % A(n-2) D(n-1) C(n-1) . % A(n-1) D(n) B(n) % function X = trisol(A,D,C,B) n=length(B); % Forward elimination: for i=1:n-1 A(i) = A(i)/D(i); % Overwrite the eliminated coefficient A(i) with L D(i+1) = D(i+1) - A(i)*C(i); % M(i+1,i+1) -= M(i+1,i)*M(i,i+1)/M(i,i) B(i+1) = B(i+1) - A(i)*B(i); % B(i+1) -= M(i+1,i)*B(i)/M(i,i) end % Back substitution: X(n) = B(n)/D(n); % X(n) = B(n)/M(n,n) for i=n-1:-1:1 X(i)=(B(i)-C(i)*X(i+1))/D(i); % X(i)=(B(i)-M(i,i+1)*X(i+1))/M(i,i) end INPUT: subd=[1,1,1]; diag=[4,5,6,7]; supd=[-1,-1,-1]; rhs=[1,0,0,0]; x=trisol(subd, diag, supd, rhs) OUTPUT: x = 0.2385 -0.0462 0.0075 -0.0011 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Exercise 4(a,b) of Section 3.5, p.153. >> A=[4 2 1; 2 5 -2; 1 -2 7]; [L,U,P]=lu(A) L = U = P = 1.0000 0 0 4.0000 2.0000 1.0000 1 0 0 0.5000 1.0000 0 0 4.0000 -2.5000 0 1 0 0.2500 -0.6250 1.0000 0 0 5.1875 0 0 1 >> B=[1 -2 7; 4 2 1; 2 5 -2]; [L,U,P]=lu(B) L = U = P = 1.0000 0 0 4.0000 2.0000 1.0000 0 1 0 0.5000 1.0000 0 0 4.0000 -2.5000 0 0 1 0.2500 -0.6250 1.0000 0 0 5.1875 1 0 0 Exercise 2(a) of Section 3.6, p.165. MATLAB PROGRAM [from the textbook's website, in "jacobi.m"]:
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/16/2010 for the course MATH 449 taught by Professor Wickerhauser during the Fall '09 term at Washington University in St. Louis.

Page1 / 8

s04 - Ma 449: Numerical Applied Mathematics Model Solutions...

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