## Chapter 10

## Q. 10.4

Use MATLAB to compute the LU factorization and find the solution for the same linear system analyzed in Examples 10.1 and 10.2:

\begin{bmatrix} 3 & -0.1 & -0.2 \\ 0.1 & 7 & -0.3 \\ 0.3 & -0.2 & 10 \end{bmatrix} \begin{Bmatrix} x_{1} \\ x_{2} \\ x_{3} \end{Bmatrix} = \begin{Bmatrix} 7.85 \\ -19.3 \\ 71.4 \end{Bmatrix}## MATLAB Verified Solution

## Script Files

The coefficient matrix and the right-hand-side vector can be entered in standard fashion as

>> A = [3 −.1 −.2;.1 7 −.3;.3 −.2 10];

>> b = [7.85; −19.3; 71.4];

Next, the LU factorization can be computed with

>> [L,U] = lu(A)

L =

1.0000 0 0

0.0333 1.0000 0

0.1000 −0.0271 1.0000

U =

3.0000 −0.1000 −0.2000

0 7.0033 −0.2933

0 0 10.0120

This is the same result that we obtained by hand in Example 10.1. We can test that it is correct by computing the original matrix as

>> L*U

ans =

3.0000 −0.1000 −0.2000

0.1000 7.0000 −0.3000

0.3000 −0.2000 10.0000

To generate the solution, we first compute

>> d = L\b

d =

7.8500

−19.5617

70.0843

And then use this result to compute the solution

>> x = U\d

x =

3.0000

−2.5000

7.0000

These results conform to those obtained by hand in Example 10.2.