Manually multiplying
(1+i)(3+i) + (2+i)(2+i) = 5+8i
(1-2i)(3+i) +(2-i)(2+i) = 10-5i

These two equations can be expressed in terms of the matrix equation MX = B, where
/ 1+i 2+i \ / 3+i \ / 5+8i \ M = | | X = | | and B = | | \1-2i 2-i / \ 2+i / \ 10-5i /
One should therefore be able to use complex piddles to obtain B by multiplying M times X, or alternatively obtain X by multiplying the inverse of M times B using the following code:
#! /usr/bin/perl -w use warnings; use strict; use PDL; use PDL::Complex; my $matrixM = pdl [ [ 1+1*i, 2+1*i], [ 1-2*i, 2-1*i] ]; my $matrixB_assigned_value = pdl [ 5+8*i, 10-5*i ]; my $matrixX_assigned_value = pdl [ 3+1*i, 2+1*i ]; my ($matrixB_computed_value, $matrixX_computed_value); print "Via Perl Data Language\n"; print "List assigned_values of matrices:\n"; print "\$matrixM = ", $matrixM,"\n"; print "\$matrixX_assigned_value = ", $matrixX_assigned_value,"\n"; print "\$matrixB_assigned_value = ", $matrixB_assigned_value,"<br>\n"; print "List computed values of matrices:\n"; print "\$matrixB_computed_value = ", $matrixM x $matrixX_assigned_value,"\n"; print "\$matrixX_computed_value = ", $matrixM->inv x $matrixB_assigned_value,"\n"; exit(0);


When the above code is executed, the following output is created:
Via Perl Data Language List assigned_values of matrices: $matrixM = [ [ [1 1] [2 1] ] [ [ 1 -2] [ 2 -1] ] ] $matrixX_assigned_value = [ [3 1] [2 1] ] $matrixB_assigned_value = [ [ 5 8] [10 -5] ] <br> List computed values of matrices: $matrixB_computed_value = [ [ [5 2] [8 3] ] [ [-1 -1] [ 4 1] ] ] $matrixX_computed_value = [ [ [ 5 -13] [ 0 21] ] [ [ 5 -6] [ 0 -7] ] ]
Notice how the assigned values for M, X, and B dutifully print as expected. However the computed values for X and B are strange. Please can you explain what I need to change to correctly compute the values of X and B in my little example.

In reply to 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":



  • 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, details, 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, summary, 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.