3

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]

>> 

1 Answers1

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.

flawr
  • 10,814
  • 3
  • 41
  • 71
  • thanks! this works on matlab very well. Do you know if there is a sparse command on a TI inspire cx cas? – user9546999 Mar 25 '18 at 21:28
  • Probably not. And there is no reason to expect the TIs `lu`-function to behave the same as MATLABs. But you could check out the [manual](https://education.ti.com/en/guidebook/details/en/3F30BA6FDA6F49608C44BB4B5F3746FA/ti-nspirecasreferenceguide-2) of your calculator. If I understand that correctly it seems that your calculator is always using partial pivoting. – flawr Mar 25 '18 at 22:33