-1

I'm trying to use LU method to solve Ax=B, and when I do start doing so, using:

(P, L, U := LUDecomposition(A))

to create my three different matrices (P, L, U) I get the error

Error, cannot split rhs for multiple assignment which doesn't make sense since LUDecomposition creates 3 matrices, which correspond to my P, L, U.

David Buck
  • 3,752
  • 35
  • 31
  • 35
Teresa
  • 1

1 Answers1

0

If you do either of the following then the call will return an expression sequence of containing three Matrices, and it will work for input A a Matrix.

with(LinearAlgebra):

P, L, U := LUDecomposition(A);

Or,

P, L, U := LinearAlgebra:-LUDecomposition(A);

But if you don't load the LinearAlgebra package and you also don't use the long-form name of that package's export then you're simply making a function call to an undefined name.

And, if you are in fact accidentally simply calling the undefined name LUDecomposition (because you have not used one of the mentioned methods for calling the package export of that name), then the result will be an unevaluated function call. And you cannot assign that single thing to three names on the left-hand-side of an assignment statement.

restart;

A := Matrix([[1,2],[3,5]]):

# Look, this next one does no computation.
# The return value is a single thing, an unevaluated
# function call.

LUDecomposition(A);

                             /[1  2]\
              LUDecomposition|[    ]|
                             \[3  5]/

P, L, U := LUDecomposition(A);
   Error, cannot split rhs for multiple assignment

But this would return the actual result,

LinearAlgebra:-LUDecomposition(A);

              [1  0]  [1  0]  [1   2]
              [    ], [    ], [     ]
              [0  1]  [3  1]  [0  -1]

And so those three Matrices could be assigned to three names.

P, L, U := LinearAlgebra:-LUDecomposition(A);

                      [1  0]  [1  0]  [1   2]
           P, L, U := [    ], [    ], [     ]
                      [0  1]  [3  1]  [0  -1]

Another way to do it is to first load the whole package, so that you can utilize the short-form command name,

with(LinearAlgebra):

LUDecomposition(A);

              [1  0]  [1  0]  [1   2]
              [    ], [    ], [     ]
              [0  1]  [3  1]  [0  -1]

P, L, U := LUDecomposition(A);

                      [1  0]  [1  0]  [1   2]
           P, L, U := [    ], [    ], [     ]
                      [0  1]  [3  1]  [0  -1]
acer
  • 6,671
  • 15
  • 15