HW 2_solutions.pdf - MATH 472 Homework 2 Winter 2018 Due...

This preview shows page 1 - 6 out of 9 pages.

MATH 472 : Homework 2 Winter 2018 Due 10:00 on Thursday, February 8. Solved Problems 1. (10 Points) Section 2.1, Exercise 4 (a) 3 - 4 - 2 | 3 6 - 6 1 | 2 - 3 8 2 | - 1 (II)-2(I) -------→ (III)-(-1)(I) 3 - 4 - 2 | 3 0 2 5 | - 4 0 4 0 | 2 (III)-2(II) ------→ 3 - 4 - 2 | 3 0 2 5 | - 4 0 0 - 10 | 10 Therefore, x 3 = - 1 , x 2 = 1 2 ( - 4 - 5 x 3 ) = 1 2 and x 1 = 1 3 (3 + 4 x 2 + 2 x 3 ) = 1 . (b) 2 1 - 1 | 2 6 2 - 2 | 8 4 6 - 3 | 5 (II)-3(I) -----→ (III)-2(I) 2 1 - 1 | 2 0 - 1 1 | 2 0 4 - 1 | 1 (III)-(-4)(II) --------→ 2 1 - 1 | 2 0 - 1 1 | 2 0 0 3 | 9 Therefore, x 3 = 3 , x 2 = - (2 - x 3 ) = 1 and x 1 = 1 2 (2 - x 2 + x 3 ) = 2 . 2. (10 Points) Section 2.1, Computer Problem 2 %Constructs the Hilbert matrix of size ’n’ function HM=hilbert_matrix(n) HM=zeros(n); for i=1:n for j=1:n HM(i,j)=1/(i+j-1); end end %Section 2.1, Computer Problem 2 %Construct and provide the data na=2; nb=5; nc=10; Ha=hilbert_matrix(na);ba=ones(na,1); Hb=hilbert_matrix(nb);bb=ones(nb,1); Hc=hilbert_matrix(nc);bc=ones(nc,1); %Solve the system xa=naive_GE(Ha,ba) %For verification, we provide also the solution estimated by MATLAB xa_real=transpose(Ha\ba) xb=naive_GE(Hb,bb) xb_real=transpose(Hb\bb) xc=naive_GE(Hc,bc) xc_real=transpose(Hc\bc) >> Comp_21_2 xa = 1
-2.0000 6.0000 xa_real = -2.0000 6.0000 xb = 1.0e+03 * 0.0050 -0.1200 0.6300 -1.1200 0.6300 xb_real = 1.0e+03 * 0.0050 -0.1200 0.6300 -1.1200 0.6300 xc = 1.0e+06 * Columns 1 through 8 -0.0000 0.0010 -0.0238 0.2402 -1.2610 3.7832 -6.7258 7.0004 Columns 9 through 10 -3.9377 0.9237 xc_real = 1.0e+06 * Columns 1 through 8 -0.0000 0.0010 -0.0238 0.2402 -1.2612 3.7835 -6.7263 7.0008 Columns 9 through 10 -3.9380 0.9237 3. (10 Points) Section 2.2, Exercise 2 (c) 1 - 1 1 2 0 2 1 0 1 3 4 4 0 2 1 - 1 (III) - 1 (I) ------→ 1 - 1 1 2 0 2 1 0 0 4 3 2 0 2 1 - 1 (III) - 2 (II) -------→ (IV) - 1 (II) 1 - 1 1 2 0 2 1 0 0 0 1 2 0 0 0 - 1 2
Therefore, L := 1 0 0 0 0 1 0 0 1 2 1 0 0 1 0 1 and U := 1 - 1 1 2 0 2 1 0 0 0 1 2 0 0 0 - 1 . In order to verify the correctness of the result, you can use MATLAB for calculating the product LU . 4. (10 Points) Section 2.2, Computer Problem 1 %We calculate the LU factorisation of the matrix ’A’. %Input: the matrix ’A’ %Output: the lower triangular matrix ’L’ and the upper triangular matrix ’U’. function [L,U]=LU_fact(A) [m,n]=size(A); L=eye(n); for j = 1 : n-1 if abs(A(j,j))<eps; error(’zero pivot encountered’); end for i = j+1 : n L(i,j) = A(i,j)/A(j,j); %Remember to change the starting index from ’j+1’ to ’j’ for k = j:n A(i,k) = A(i,k) - L(i,j)*A(j,k); end end end U=A; end %Section 2.2, Computer Problem 1 %Provide the data A2a=[3 1 2; 6 3 4; 3 1 5]; A2b=[4 2 0; 4 4 2; 2 2 3]; A2c=[1 -1 1 2; 0 2 1 0; 1 3 4 4; 0 2 1 -1]; [L2a,U2a]=LU_fact(A2a) %Verification: The matrix Ver2_ has to have all its elements equal to 0 Ver2a=A2a - L2a*U2a [L2b,U2b]=LU_fact(A2b) Ver2b=A2b - L2b*U2b [L2c,U2c]=LU_fact(A2c) Ver2c=A2c - L2c*U2c >> Comp_22_1 L2a = 1 0 0 2 1 0 1 0 1 U2a = 3
3 1 2 0 1 0 0 0 3 Ver2a = 0 0 0 0 0 0 0 0 0 L2b = 1.0000 0 0 1.0000 1.0000 0 0.5000 0.5000 1.0000 U2b = 4 2 0 0 2 2 0 0 2 Ver2b = 0 0 0 0 0 0 0 0 0 L2c = 1 0 0 0 0 1 0 0 1 2 1 0 0 1 0 1 U2c = 1 -1 1 2 0 2 1 0 0 0 1 2 0 0 0 -1 Ver2c = 0 0 0 0 0 0 0 0 0 0 0 0 4
0 0 0 0

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture