Conjugate transpose: Difference between revisions

m
→‎{{header|Perl}}: future-proof for 5.36
m (→‎{{header|J}}: change label on the example matrices here)
m (→‎{{header|Perl}}: future-proof for 5.36)
Line 2,387:
In general, using two or more modules which overload operators can be problematic. For this task, using both Math::Complex and Math::MatrixReal gives us the behavior we want for everything except matrix I/O, i.e. parsing and stringification.
<syntaxhighlight lang="perl">use strict;
use warnings;
use English;
use Math::Complex;
Line 2,429 ⟶ 2,430:
sub identity {
my $N = shift;
my $m = new Math::MatrixReal->new($N, $N);
$m->one();
return $m;
Line 2,435 ⟶ 2,436:
 
sub example1 {
my $m = new Math::MatrixReal->new(2, 2);
$m->assign(1, 1, cplx(3, 0));
$m->assign(1, 2, cplx(2, 1));
Line 2,444 ⟶ 2,445:
 
sub example2 {
my $m = new Math::MatrixReal->new(3, 3);
$m->assign(1, 1, cplx(1, 0));
$m->assign(1, 2, cplx(1, 0));
Line 2,458 ⟶ 2,459:
 
sub example3 {
my $m = new Math::MatrixReal->new(3, 3);
$m->assign(1, 1, cplx(0.70710677, 0));
$m->assign(1, 2, cplx(0.70710677, 0));
2,392

edits