stickman has asked for the wisdom of the Perl Monks concerning the following question:

Can somebody provide an example of how to use Math::MatrixReal to solve a 4x4 or more unknowns equation? I have looked at the man page for it but am just not understanding how to use it to solve a problem. For example, if I have a matrix/vector like this:
[ 1 2 3 4 ] [ 1 ]
[ 1 2 3 4 ] [ 1 ]
[ 1 2 3 4 ] [ 1 ]
[ 1 2 3 4 ] [ 1 ]
How can I solve it and get the 4 unknowns?
TIA..

Replies are listed 'Best First'.
Re: Math::MatrixReal Example Help
by pc88mxer (Vicar) on Feb 18, 2008 at 16:07 UTC
    If your system of equations is non-singular, then you can just use the inverse method:

    my $matrix = Math::MatrixReal->new_from_string(...); my $ones = Math::MatrixReal->new_from_string("[ 1 1 1 1 ]"); my $inv = $matrix->inverse(); my $answer = $inv->multiply($ones);

    However, if your matrix is singular, (i.e. the determinant is zero), then there are two possibilities: there is no solution or there is an infinite number of solutions. In this case we use the LR-decomposition of the matrix. The Math::MatrixReal documentation has a big section on using the LR-decomposition to solve a system of equations, so just check that out.

Re: Math::MatrixReal Example Help
by zentara (Cardinal) on Feb 18, 2008 at 19:07 UTC
      very sweet..thank you!! I searched perlmonks for MatrixReal but nothing returned so I posted. If that would have returned as a result I would not have needed to. How could I have searched to find that??
        I misplaced my copy myself. I had to search for "Simultaneous Equations" to find the node. :-)

        I'm not really a human, but I play one on earth. Cogito ergo sum a bum
Re: Math::MatrixReal Example Help
by Anonymous Monk on Feb 18, 2008 at 15:54 UTC
    Why don't you start?