Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

moodle.louisiana.edu LUdecomp.pdf https://moodle.louisiana.edu/pluginfile.php/12

ID: 3168353 • Letter: M

Question

moodle.louisiana.edu LUdecomp.pdf https://moodle.louisiana.edu/pluginfile.php/1247266/mod res php/1320027/ LU Decomposition Lab Using MATLAB, solve for the x values of the simultaneous linear equations below: X1+X2+x3 = 5 2x1 + 2x2 t x 2 2x1 + X2 + 3 = 0 The function should be called "LUdecomp" and should return an array of x values. The function should contain subfunctions "solve" and "decomp". The subfunction "decomp" will: · · Check if the A matrix is singular. If so, return an error flag, display a message the matrix is singular, and exit the program. Decompose the A matrix, if not singular, into a lower and upper triangular matrix using Crout's method. - - The subfunction "solve" will accept the decomposed LU matrix and a b vector to calculate the solution vector, x. Upload the following to Moodle: 1. A screen capture of your program running, including the solution vector x. 2. A .m file of your code with descriptive comments. FS -F6

Explanation / Answer


function y=lu(A)

A=[1 1 1;2 2 1;2 1 3];
B=[5 2 0]';

if det(A)==0
error('Given matrix is Singular ')
end

[L, U]=lu(A)

('solution of the given matrix')

X=inv(U)*inv(L)*B

end

output:

L =

5.0000e-01 0 1.0000e+00
1.0000e+00 0 0
1.0000e+00 1.0000e+00 0


U =

2.0000e+00 2.0000e+00 1.0000e+00
0 -1.0000e+00 2.0000e+00
0 0 5.0000e-01


ans =

solution of the given matrix


X =

-21
18
8