Develop debug and test a program in MATLAB that solves a sys
Develop, debug, and test a program (in MATLAB) that solves a system of linear equations Ax = b using LU decomposition. The code should be able to solve for arbitrary rectangular n times n matrix A and right hand-side b. Organize your code such a way that both matrix A and vector b are the input parameters and x is your output vector. Consider the possibility that matrix A is rank-deficient and the system does not have the solution. This can only happen if the rows are linear dependent. If this happen, make your program display the error message like \"error: matrix is rank deficient\" and stop. If possible, solve the following systems of linear equations with your own program: [0 1 -1 1 3 2 -1 2 1][x_1 x_2 x_3] = [4 4 8] [1 1 0 1 3 2 0 2 2][x_1 x_2 x_3] = [1 0 1] [2 2 1 3 2 -1 -1 3 1 -1 -1 4 3 3 4 1] [x_1 x_2 x_3 x_4] = [1 3 0 9] Check you results by substituting x into Ax and compare it with b. If your code is correct, Ax should be identical to b. If your code can not solve the problem, see whether you can invert the matrix using MATLAB internal procedure, inv(A). If you can, then the problem definitely has the solution and something is wrong with your code. Also, compare with the Gauss Seidel by solving each set of equations. See if you can get Gauss Seidel to converge and talk about the advantages and disadvantages of each method.
Solution
MATLAB code:
A=input(\'Enter A matrix values:\')
B=input(\'Enter B matrix values:\')
x=A\\B
check=A*x
if x==NaN
disp(\'error: matrix is rank dificient\')
break;
elseif x==0
disp(\'error: matrix is rank dificient\')
break;
else
end
sample outputs:
Enter A matrix values:[0 1 -1;1 3 2;-1 2 1]
A =
0 1 -1
1 3 2
-1 2 1
Enter B matrix values:[4;4;8]
B =
4
4
8
x =
-3.0000
3.0000
-1.0000
check =
4.0000
4.0000
8.0000
>>

