Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Help On Inverese Matrix

by Anonymous Monk
on Jul 18, 2001 at 01:15 UTC ( [id://97456]=perlquestion: print w/replies, xml ) Need Help??

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

I am new into perl.

I decided to use MatrixReal module to find inverse of a given matrix.

#! /usr/local/bin/perl -w use strict; use Math::MatrixReal; sub INVERT_MATRIX { my $matrix =Math::MatrixReal->new_from_string(<<'MATRIX'); [ 0 1 2 ] [ 3 4 5 ] [ 6 7 8 ] MATRIX print $matrix; my $inverse = $matrix->decompose_LR->invert_LR ; print $inverse;

when I try to print inverese matrix as it was given in the book I get the following output:

% myprog [ 0.000000000000E+00 1.000000000000E+00 2.000000000000E+00 ] [ 3.000000000000E+00 4.000000000000E+00 5.000000000000E+00 ] [ 6.000000000000E+00 7.000000000000E+00 8.000000000000E+00 ] Use of uninitialized value in print at myprog line 34.

can somebody tell me what I did wrong?

by the way I do have a [ and a ] surrounding those numbers properly

this web app won't accept it in that region due to that

Code tags by Ovid

Replies are listed 'Best First'.
Re: Help On Inverse Matrix
by Ea (Chaplain) on Jul 18, 2001 at 12:53 UTC
    This is not the answer you are looking for, but an alternative module for dealing with matrices is the Perl Data Language. The module PDL::Slatec has a function called matinv , which is gives the inverse of a square matrix like so, ($inv) = matinv($mat) (pretty much stolen from the docs)

    You will probably lose a little time installing and learning how to form the matrix, but if you are regularly involved in Numerical Funny Business, it might be worth it in the long run. The web page is http://pdl.perl.org/ which will explain the module and lead you to a low traffic mailing list with lotsa helpful people.

      PDL::Slatec uses bundled parts of LINPACK and some of BLAS. To use the more up-to-date LAPACK with PDL, I don't think there's a better option than Greg Vanuxem's PDL::LinearAlgebra, which has an excellent PDL-ish (and in fact quite MATLAB-reminiscent) wrapping interface.
Re: Help On Inverese Matrix
by no_slogan (Deacon) on Jul 18, 2001 at 02:27 UTC
    Your matrix is singular. There is no inverse. Try a different matrix.
Re: Help On Inverese Matrix
by ariels (Curate) on Jul 18, 2001 at 09:08 UTC
    Further to no_slogan's answer, you can see your matrix is singular by noting that (this is algebraic notation, not Perl!)
    2*[3,4,5] - [0,1,2] = [6,7,8]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://97456]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-25 12:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found