Decomposing A into L and U (matrices)

  • Thread starter Thread starter physicsCU
  • Start date Start date
  • Tags Tags
    Matrices
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 3K views
physicsCU
Messages
198
Reaction score
1
I need to write a program to take A and make the lower and upper triangular matrices for it.

My idea is to use if statements, since what I am doing is setting U(i,j) equal to A(i,j) if i <= j and U(i,j) = 0 if i > j

For L(i,j), its equal to A(i,j) if i > j, 1 if i = j and 0 if i < j.

Any ideas how to do this? I am stumped on how to get the i and j parts working.
 
Physics news on Phys.org
I guess it depends on what language. If it were fortran (it's been a long time) I'd say you have to do a nested for...next loop.

For i=1 to #_of_colums
For j=1 to #_of_rows
Blah blah blah
Next j
Next i
 
this is matlab, sorry.

i came to the same conclusion, but i guess i will have to do a nested for loop. I hate those. Oh well.

I think this will work, I will try to write the program today, but two other labs are due soon as well.
 
Just wanted to update that I wrote the program the way we both thought of, and it worked the right way right off the bat!

That is a first for me i think!

Overall its a quick little loop and I would be willing to share it once my lab is turned in.