QR decomposition: Difference between revisions
Content added Content deleted
SqrtNegInf (talk | contribs) (Added Perl example) |
|||
Line 2,037: | Line 2,037: | ||
{{works with|PARI/GP|2.6.0 and above}} |
{{works with|PARI/GP|2.6.0 and above}} |
||
<lang parigp>matqr(M)</lang> |
<lang parigp>matqr(M)</lang> |
||
=={{header|Perl}}== |
|||
Letting the <code>PDL</code> module do all the work. |
|||
<lang perl>use strict; |
|||
use warnings; |
|||
use PDL; |
|||
use PDL::LinearAlgebra qw(mqr); |
|||
my $a = pdl( |
|||
[12, -51, 4], |
|||
[ 6, 167, -68], |
|||
[-4, 24, -41], |
|||
[-1, 1, 0], |
|||
[ 2, 0, 3] |
|||
); |
|||
my ($q, $r) = mqr($a); |
|||
print $q, $r, $q x $r;</lang> |
|||
{{out}} |
|||
<pre>[ |
|||
[ -0.84641474 0.39129081 -0.34312406] |
|||
[ -0.42320737 -0.90408727 0.029270162] |
|||
[ 0.28213825 -0.17042055 -0.93285599] |
|||
[ 0.070534562 -0.014040652 0.001099372] |
|||
[ -0.14106912 0.016655511 0.10577161] |
|||
] |
|||
[ |
|||
[-14.177447 -20.666627 13.401567] |
|||
[ 0 -175.04254 70.080307] |
|||
[ 0 0 35.201543] |
|||
] |
|||
[ |
|||
[ 12 -51 4] |
|||
[ 6 167 -68] |
|||
[ -4 24 -41] |
|||
[ -1 1 0] |
|||
[ 2 0 3] |
|||
]</pre> |
|||
=={{header|Perl 6}}== |
=={{header|Perl 6}}== |