Script
Save
Reset
MATLAB Documentation
1 %Create the coefficient matrix A and and the column matrix b of constants.
2 A = [1 2 3; 3 0 -1; 2 -1 1]
3 b = [9; 3; 8]
4 %Use the lu() command to find the LU decomposition of A, storing the lower and upper matrices
5 %in L and U, respectively.
6 [L, U] = lu(A)
7 %Solve the system of linear equations Ax=b using the LU decomposition. Store the intermediary
8 %solution in y. Store the solution for x in x1.
9 y = L\b
10 x1 = A\b
11 %Check that the solution x1 matches that found by directly using the backslash operator to solve
12 %the system Ax=b. Use the backslash operator to solve Ax=b in one step, storing the solution in x2.
13 x = A\b
? Run Script