Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Would a non-PDL solution be of use to you? Here’s an example showing Math::Matrix and Math::Complex working together:

#! /usr/bin/perl use strict; use warnings; use Math::Complex; use Math::Matrix; package Math::Matrix { our $Precision = 3; sub print_complex { my ($self, @args) = @_; print @args if @args; for (@$self) { my @z; for (@$_) { my ($re, $im) = @{$_->{cartesian}}; push @z, sprintf "%s%.*f%s%.*fi", ($re < 0 ? '' : ' ') +, $Precision, $re, ($im < 0 ? '' : '+') +, $Precision, $im; } print '| ', join(' ', @z), " |\n"; } } } package main; my $matrix_2x2 = new Math::Matrix( [ 1+1*i, 2+1*i ], [ 1-2*i, 2-1*i ] ); $matrix_2x2 ->print_complex("\n\$matrix_2x2:\n\n"); $matrix_2x2->invert()->print_complex("\nInverse of \$matrix_2x2:\n\n") +; $Math::Matrix::Precision = 5; my $matrix_3x3 = new Math::Matrix( [ 1+1*i, 2+1*i, 3+1*i ], [ 1-2*i, 2-1*i, -2+1*i ], [ -1+1*i, 2+1*i, -1+1*i ] ); $matrix_3x3 ->print_complex("\n\$matrix_3x3:\n\n"); $matrix_3x3->invert()->print_complex("\nInverse of \$matrix_3x3:\n\n") +;


$matrix_2x2: | 1.000+1.000i 2.000+1.000i | | 1.000-2.000i 2.000-1.000i | Inverse of $matrix_2x2: | -0.353-0.412i -0.118+0.529i | | 0.529+0.118i 0.176-0.294i | $matrix_3x3: | 1.00000+1.00000i 2.00000+1.00000i 3.00000+1.00000i | | 1.00000-2.00000i 2.00000-1.00000i -2.00000+1.00000i | | -1.00000+1.00000i 2.00000+1.00000i -1.00000+1.00000i | Inverse of $matrix_3x3: | 0.05235+0.14079i 0.13718+0.23105i -0.31949-0.16968i | | 0.09747-0.15162i 0.08303-0.01805i 0.26715+0.02888i | | 0.22383-0.07040i -0.06859-0.11552i -0.09025+0.08484i |

BTW, is a useful site for checking operations on complex-number matrices.

Hope that helps,

Athanasius <°(((><contra mundum

In reply to Re: problem with complex matrix multiplication using PDL by Athanasius
in thread problem with complex matrix multiplication using PDL by smh

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

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others lurking in the Monastery: (5)
    As of 2018-03-23 07:46 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (288 votes). Check out past polls.