Decomposing A into L and U (matrices)

  • Thread starter Thread starter physicsCU
  • Start date Start date
  • Tags Tags
    Matrices
AI Thread Summary
The discussion focuses on creating lower and upper triangular matrices from a given matrix A using programming. The proposed method involves using conditional statements to assign values to U and L matrices based on their indices. A nested loop structure is suggested for implementation, particularly in MATLAB. The user successfully wrote the program as planned, achieving the desired outcome on the first attempt. They express willingness to share the code after completing their lab assignments.
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.
 
Sweeeeeeeeeettt.
 
Back
Top