plu分解
python:
exchange函数如果不用np.copy会导致改完之后的两行是一样的,因为python传的是引用。
1 | import numpy as np |
全部分解
根据程序提示,输入1为plu分解,输入2为QR分解,输入3为household,输入4为givens,输入5为退出程序。
如果想修改矩阵查看某个分解对于不同矩阵的效果,请在Decompose.py中的main函数中找到对应分解(PLU,QR,Household,Givens),修改其中的matrix
如果不修改原始矩阵显示输出为如下所示:
Welcome to Decompose program
Input the Number of the Decompose
1.PLU 2.QR 3.Household 4.Givens 5.quit program
By the way,if you wanna to change original matrix, you need to alter it in the python file
Input Number:1
original PLU matrix:
[[ 1. 2. -3. 4.]
[ 4. 8. 12. -8.]
[ 2. 3. 2. 1.]
[-3. -1. 1. -4.]]
P:
[[0. 1. 0. 0.]
[0. 0. 0. 1.]
[1. 0. 0. 0.]
[0. 0. 1. 0.]]
L:
[[ 1. 0. 0. 0. ]
[-0.75 1. 0. 0. ]
[ 0.25 0. 1. 0. ]
[ 0.5 -0.2 0.33333333 1. ]]
U:
[[ 4. 8. 12. -8.]
[ 0. 5. 10. -10.]
[ 0. 0. -6. 6.]
[ 0. 0. 0. 1.]]
Input Number:2
origin QR matrix:
[[ 0. -20. -14.]
[ 3. 27. -4.]
[ 4. 11. -2.]]
Q:
[[ 0. -0.8 -0.6 ]
[ 0.6 0.48 -0.64]
[ 0.8 -0.36 0.48]]
R:
[[ 5. 25. -4.]
[ 0. 25. 10.]
[ 0. 0. 10.]]
Input Number:3
origin Household matrix:
[[ 0. -20. -14.]
[ 3. 27. -4.]
[ 4. 11. -2.]]
R:
[[ 5. 25. -4.]
[ 0. 25. 10.]
[ 0. 0. 10.]]
Q:
[[ 0. 0.6 0.8 ]
[-0.8 0.48 -0.36]
[-0.6 -0.64 0.48]]
Input Number:4
origin Givens matrix:
[[ 0. -20. -14.]
[ 3. 27. -4.]
[ 4. 11. -2.]]
R:
[[ 5. 25. -4.]
[ 0. 25. 10.]
[ 0. -0. 10.]]
Q:
[[ 0. 0.6 0.8 ]
[-0.8 0.48 -0.36]
[-0.6 -0.64 0.48]]
Input Number:5
GoodBye
注:其中的例子均为老师上课ppt中的原样例
python code
1 | import numpy as np |