1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Decomposing A into L and U (matrices)

  1. Mar 11, 2006 #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.
  2. jcsd
  3. Mar 11, 2006 #2


    User Avatar
    Science Advisor

    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
  4. Mar 11, 2006 #3
    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.
  5. Mar 11, 2006 #4
    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.
  6. Mar 13, 2006 #5


    User Avatar
    Science Advisor

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook