LU Decomposition




On Wed, 21 Oct 2009, Dotan Cohen wrote:

< 2009/10/20 Raymond Toy <raymond.toy at stericsson.com>:
< > Dotan Cohen wrote:
< >>> Try
< >>>
< >>> ? lu_factor;
< >>>
< >>>
< >>
< >> Naturally, I found lu_factor and get_lu_factor which were mentioned in
< >> the man pages. However, I cannot figure out exactly how to use them.
< >> lu_factor(M); did not work, and it is not clear to me from the man
< >> pages exactly what I need to do. It looks like I need to use lu_factor
< >> first and then enter that output into get_lu_factor, but I cannot
< >> figure out how to do that.
< >>
< > Oh. ?Here's what I did. ?The description of get_lu_factor seems clear to me.
< >
< > (%o48) matrix([1,2],[3,4])
< > (%i49) lu_factor(%);
< > (%o49) [matrix([1,2],[3,-2]),[1,2],generalring]
< > (%i50) get_lu_factors(%);
< > (%o50) [matrix([1,0],[0,1]),matrix([1,0],[3,1]),matrix([1,2],[0,-2])]
< >
< > And %o50[1] . %o50[2] . %o50[3] gives the original matrix.
< >
< 
< Thanks, Ray. I think I found the problem, I was using the matrix
< identifier (M) instead of the % symbol:
< 
< 
< (%i1) M=matrix([1,2],[3,4]);
<                                      [ 1  2 ]
< (%o1)                            M = [      ]
<                                      [ 3  4 ]

Maxima uses '=' to test syntactic equality and declare unevaluated
equations. You can see this because Maxima has output 'both sides' of
your input line, while the rule is that Maxima will only output the
result of the final command on an input line (which, for assignment, is
the right-hand side--you can see this below). The assignment operator is ':'.


(%i18) M : matrix([1,2],[3,4]);
(%o18) matrix([1,2],[3,4])
(%i19) Mlu : lu_factor(M);
(%o19) [matrix([1,2],[3,-2]),[1,2],generalring]
(%i20) [P,L,U] : get_lu_factors(Mlu);
(%o20) [matrix([1,0],[0,1]),matrix([1,0],[3,1]),matrix([1,2],[0,-2])]

(%i17) ? =

 -- Operator: =
     The equation operator.

     An expression `<a> = <b>', by itself, represents an unevaluated
     equation, which might or might not hold.  Unevaluated equations
     may appear as arguments to `solve' and `algsys' or some other
     functions.

     The function `is' evaluates `=' to a Boolean value.  `is(<a> =
     <b>)' evaluates `<a> = <b>' to `true' when <a> and <b> are
     identical.

Leo
-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.