moode.kurana ed LU Decomposition Lab Using MATLAB, solve for the x values of the
ID: 3168357 • Letter: M
Question
moode.kurana ed LU Decomposition Lab Using MATLAB, solve for the x values of the simultaneous linear equations below: 2x1 + 2x2 +x3-2 2x1 + x2 + 30 The function should be called "LUdecomp" and should retun an aray of x values. The function should contain subfunctions "solve" and "decomp". The subfunction "decomp" will: · Check if the A matrix is singular. If so, returm 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 caleulate 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.Explanation / Answer
decomp.m
function [flag,L,U,P] = decomp(A)
flag = false;
if det(A) == 0
flag = true;
L=0;U=0;P=0;
disp 'Error: A is singular';
else
[L,U,P] = lu(A);
end
end
solve.m
function [x] = solve(L,U,P,b)
x = inv(U)*inv(L)*P*b;
end
code.m
clear
clc
A = [1,1,1;
2,2,1;
2,1,0];
A
b = [5,2,-3]';
b
[flag,L,U,P] = decomp(A);
if flag == false
x = solve(L,U,P,b);
x
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.