Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
You can install PDL-LinearAlgebra if you want to do linear algebra over complexes. Here is an example (note that if you load PDL::LinearALgebra the x operator (matrix multiplication in PDL) is overriden by the BLAS matrix multiplication and thus is complex aware. Here is a perldl session:
perldl> use PDL::Complex perldl> use PDL::LinearAlgebra perldl> $matrixM = cplx pdl [ [ 1+1*i, 2+1*i], [ 1-2*i, 2-1*i] ]; perldl> p $matrixM [ [1 +1i 2 +1i] [1 -2i 2 -1i] ] perldl> $matrixB_assigned_value = cplx pdl [ 5+8*i, 10-5*i ]; perldl> p $matrixB [ [ 5 +8i] [10 -5i] ] perldl> msolve($matrixM,$matrixB) [ [3+1i] [2+1i] ] [ [ 1 -2i 2 -1i] [-0.2 +0.6i 1.8 -0.4i] ] [2 2] 0 perldl> scalar msolve($matrixM,$matrixB) [ [3+1i] [2+1i] ] perldl> $matrixM->minv x $matrixB [ [3 +1i] [2 +1i] ]
In the last result we see from the amount of space between the real and imaginary part that the result is less precise.
----------------------------------------------------------- perldl> help minv minv Compute inverse of a general square matrix using LU factorization. Supports inplace and threading. Uses getrf and getri or cgetrf and cgetri from Lapack and return "inverse, info" in array context. PDL(inv) = minv(PDL) my $a = random(10,10); my $inv = minv($a); Docs from /usr/lib/perl5/PDL/LinearAlgebra.pm perldl> help msolve msolve Solve linear system of equations using LU decomposition. A * X = B Returns X in scalar context else X, LU, pivot vector and info. B is overwrited by X if its inplace flag is set. Supports threading. Uses gesv or cgesv from Lapack. (PDL(X), (PDL(LU), PDL(pivot), PDL(info))) = msolve(PDL(A), PDL(B) +) my $a = random(5,5); my $b = random(10,5); my $X = msolve($a, $b); Docs from /usr/lib/perl5/PDL/LinearAlgebra.pm

In reply to Re: PDL::Complex question by Anonymous Monk
in thread PDL::Complex question by gmacfadden

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-24 04:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found