# 472 Homework 4 - Math 472 Section 002 Professor Joseph...

• Homework Help
• 7
• 100% (3) 3 out of 3 people found this document helpful

This preview shows page 1 - 5 out of 7 pages.

Math 472 Section 002Professor Joseph Conlon Homework 411/11/2016Problem 1
A.)%Function: LUFact 11/11/2016, Math 472%Returns L and U matrices of LU factorization of tridiagonal matrix A by taking input vectors a, d, e of Afunction [L, U]=LUFact(a, d, e)N = length(a);d1=d;a1=a;e1=e;a1(1)=a(1);for i=2:Ne1(i-1) = e(i-1)/a1(i-1);a1(i) = a(i) - (e(i-1)/a1(i-1))*d(i-1); endL = diag(e1,-1)+eye(6);U = diag(a1)+diag(d1,+1);endB.)>> x=[7, 3, 6, -3, 5, 8]x =7 3 6 -3 5 8>> y=[-4, 3, 6, 5, -3]y =-4 3 6 5 -3>> z=[-4, 8, 5, -6, -2]z =-4 8 5 -6 -2>> [L,U]=LUFact(x, z, y)L =
1.0000 0 0 0 0 0-0.5714 1.0000 0 0 0 0 0 4.2000 1.0000 0 0 00 0 -0.2174 1.0000 0 00 0 0 -2.6136 1.0000 00 0 0 0 0.2809 1.0000>> UU =7.0000 -4.0000 0 0 0 00 0.7143 8.0000 0 0 00 0 -27.6000 5.0000 0 00 0 0 -1.9130 -6.0000 00 0 0 0 -10.6818 -2.00000 0 0 0 0 8.5617Problem 3%Function: GS 11/11/2016, Math 472
%Gauss-Seidel Elimination for k iterationsfunction x=GS(N, k)b=zeros(N,1);x=ones(N,1);m=floor(sqrt(N));for j=1:Nb(j)=(j*(1+(j/N)))/(N^2);endz= 1/(4+(3/N));for n=1:kx(1)= z*(b(1)+x(2)+x(1+m));for i=2:mx(i)=z*(b(i)+x(i-1)+x(i+1)+x(i+m));endfor i=m+1:N-mx(i)=z*(b(i)+x(i-m)+x(i-1)+x(i+1)+x(i+m));endfor i= N-m+1:N-1x(i)=z*(b(i)+x(i-m)+x(i-1)+x(i+1));endx(N)=z*(b(N)+x(N-m)+x(N-1));endA.)