Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IVIAI 940 LAD . FIVVICIII 4 Download the LiveScript MAT343lab3ex4.mix and run it in MATLAB. Then complete the following exercise. Enter the matrix A and
IVIAI 940 LAD . FIVVICIII 4 Download the LiveScript MAT343lab3ex4.mix and run it in MATLAB. Then complete the following exercise. Enter the matrix A and the vector b in MATLAB 5 3 -16 -2 A = b = 4 20 4 7 -8 48 1. Enter [L, U, P] = lu(A) to find the LU factorization of the matrix PA. Verify that PA = LU by computing P*A-L*U (assign this to variable ans1). 2. Use the LU factorization you found in part (1) to solve the system Ax = b: first use the "\\" command to solve the system Ly = Pb (store the solution in the variable y) and then solve the system Ux = y. Call the computed solution x_lu. 3. The exact solution to the system Ax = b is the vector x = [-9 8 -4 -1] . Enter the vector x and compare your solution x_lu from part (2) with the exact solution x by computing norm(x_lu-x) (assign this to variable ans2) . NOTE: the norm function gives the magnitude of the vector, that is, for a vector a = (aj, a2, ...,a,), the norm of a is defined as norm(a) = va,ta;+ ... + a Thus the command norm(x_lu-x) measures how close the computed solution x_lu is to the exact solution x. You should expect a very small number. Don't forget to include your name as a comment in your script.2 XEnter the matrix A and the vector b 3 4 A= [5,3, -1, -1; -9, -7,6,3; -8, -9,-6,4;-4,4,7,-8]; 5 b=[-16; -2;20;48]; 6 % Calculate LU factorization 7 [L,U, P ]=14(A); 8 P*A; 9 L*U; 10 % Compute PA-LU 11 ansi=(P*A) - (L*U); 12 13 % Solve the system Ax=b using LU factorization calculated above 14 A=L*U; 15 y=L\\(P*b); 16 X=U\\; 17 % Enter the vector x and compare the solution x_lu with exact solution x using norm function 18 x_lu= round (x) ; 19 x = [-9,8,-4,-1] "; 20 ans2 = norm(x_lu-x); 216 Is A entered correctly? 0% (9%) Variable A has an incorrect value. 0 Is I: entered correctly? 8% (8%) 0 Is ans1 computed correctly? 8% (8%) 0 Is y computed correctly? 25% (25%) 0 Is x_|u computed comedy? 25% [25%) 0 Is x entered correctly? 3% (8%) 0 Is an52 computed correctly? 1m [17%)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started