# HW1-Shaowei Sun

## 2288 days ago by bigdata2016

1. LU decomposition

A = matrix(QQ, [[1, -1, 1, 2, 4, 7, -1],[2, -1, 0, 6, 4, 8, -2],[2, 0, 1, 4, 2, 6, 0],[1, 0, -1, 8, -1, -1, -3],[1, 1, 2, -2, -1, 1, 3],[1, 1, 6, 3, -1, 1, 4],[1, 1, 2, -2, 1, 1, 5]]) show(A)
 \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrrrrr} 1 & -1 & 1 & 2 & 4 & 7 & -1 \\ 2 & -1 & 0 & 6 & 4 & 8 & -2 \\ 2 & 0 & 1 & 4 & 2 & 6 & 0 \\ 1 & 0 & -1 & 8 & -1 & -1 & -3 \\ 1 & 1 & 2 & -2 & -1 & 1 & 3 \\ 1 & 1 & 6 & 3 & -1 & 1 & 4 \\ 1 & 1 & 2 & -2 & 1 & 1 & 5 \end{array}\right)
P, L, U = A.LU() show(P) show(L) show(U)
 \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrrrrr} 0 & 0 & 0 & 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 & 0 & 0 & 0 \\ 0 & 0 & 1 & 0 & 0 & 0 & 0 \\ 0 & 0 & 0 & 0 & 1 & 0 & 0 \end{array}\right) \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrrrrr} 1 & 0 & 0 & 0 & 0 & 0 & 0 \\ \frac{1}{2} & 1 & 0 & 0 & 0 & 0 & 0 \\ \frac{1}{2} & 1 & 1 & 0 & 0 & 0 & 0 \\ \frac{1}{2} & \frac{1}{3} & -\frac{5}{12} & 1 & 0 & 0 & 0 \\ \frac{1}{2} & 1 & 0 & 0 & 1 & 0 & 0 \\ 1 & \frac{2}{3} & -\frac{1}{12} & \frac{1}{5} & \frac{1}{5} & 1 & 0 \\ \frac{1}{2} & -\frac{1}{3} & \frac{5}{12} & -\frac{19}{35} & -\frac{3}{70} & -\frac{3}{14} & 1 \end{array}\right) \newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrrrrr} 2 & -1 & 0 & 6 & 4 & 8 & -2 \\ 0 & \frac{3}{2} & 2 & -5 & -3 & -3 & 4 \\ 0 & 0 & 4 & 5 & 0 & 0 & 1 \\ 0 & 0 & 0 & \frac{35}{4} & -2 & -4 & -\frac{35}{12} \\ 0 & 0 & 0 & 0 & 2 & 0 & 2 \\ 0 & 0 & 0 & 0 & 0 & \frac{4}{5} & -\frac{2}{5} \\ 0 & 0 & 0 & 0 & 0 & 0 & -\frac{2}{3} \end{array}\right)

2. Sovle Ax=b using LU-decomposition

b=matrix(QQ, [[1,2,3,4,5,6,7]]) b=transpose(b)
x=U^(-1)*L^(-1)*P^(-1)*b x
 [177/14] [ -15/7] [ 3] [ -12/7] [ 24/7] [-59/14] [ -17/7] [177/14] [ -15/7] [ 3] [ -12/7] [ 24/7] [-59/14] [ -17/7]
A*x==b
 True True