HW1-Shaowei Sun

1909 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) 
       
P, L, U = A.LU() show(P) show(L) show(U) 
       


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