gmacfadden has asked for the wisdom of the Perl Monks concerning the following question:
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
When the above code is executed, the following output is created:
(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
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:/ 1+i 2+i \ / 3+i \ / 5+8i \ M = | | X = | | and B = | | \1-2i 2-i / \ 2+i / \ 10-5i /
#! /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:
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.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] ] ]
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: PDL::Complex question
by drzowie (Initiate) on Apr 01, 2007 at 17:10 UTC | |
by etj (Deacon) on Jun 20, 2022 at 14:41 UTC | |
Re: PDL::Complex question
by Zaxo (Archbishop) on Mar 22, 2007 at 06:53 UTC | |
by Anno (Deacon) on Mar 22, 2007 at 13:53 UTC | |
Re: PDL::Complex question
by Anonymous Monk on Apr 05, 2007 at 06:29 UTC |
Back to
Seekers of Perl Wisdom