I am looking for a way to do a LU decomposition on matlab or a ti inspire cx cas where the row of diagonal 1s is on the upper triangular matrix. I want matrix A to decompose to
L2 = [2 0 0; -0.5 3.5 0; 3 1 -3]
U = [1 1 -3; 0 1 2; 0 0 1]
but i can't get the code to do this correctly just using transposes. Thanks.
Code:
clc
A = [ 2, 2, -6 ; -0.5, 3, 8.5; 3, 4, -10];
[L2,U,P] = lu(A')
L2'
U'
Output:
L2 =[
1.0000 0 0;
-0.3333 1.0000 0;
-0.3333 0.4000 1.0000]
U =[
-6.0000 8.5000 -10.0000;
0 5.8333 0.6667;
0 0 -0.6000]
P =[
0 0 1;
0 1 0;
1 0 0]
ans =[
1.0000 -0.3333 -0.3333;
0 1.0000 0.4000;
0 0 1.0000]
ans =[
-6.0000 0 0;
8.5000 5.8333 0;
-10.0000 0.6667 -0.6000]
>>
答案 0 :(得分:3)
It seems you do not want any pivoting to happen. You can achieve this by using the pivoting threshold for sparse matrices:
A = [ 2, 2, -6 ; -0.5, 3, 8.5; 3, 4, -10];
L = [2 0 0; -0.5 3.5 0; 3 1 -3]
U = [1 1 -3; 0 1 2; 0 0 1]
[l,u,p] = lu(sparse(A.'),0);
Lnew = full(u).'
Unew = full(l).'
After that Lnew
is the same as L
(up to rounding stuff) and the same holds for Unew
and U
.