LU decomposition: Difference between revisions
m
→{{header|Perl 6}}: minor tweaks, remove some superstitious parentheses
Thundergnat (talk | contribs) (→{{header|Perl 6}}: Add Perl 6 example) |
Thundergnat (talk | contribs) m (→{{header|Perl 6}}: minor tweaks, remove some superstitious parentheses) |
||
Line 1,875:
die unless @a.&is-square;
my $n = +@a;
my @L = matrix-ident $n;▼
my @U = matrix-zero $n;▼
my @P = pivotize @a;
my @A = mmult @P, @a;
▲ my @L = matrix-ident $n;
▲ my @U = matrix-zero $n;
for ^$n -> $i {
for ^$n -> $j {
if $j >= $i {
@U[$i][$j] = @A[$i][$j] - [+] map { @U[$_][$j] * @L[$i][$_] }, ^$i
} else {
@L[$i][$j] = (@A[$i][$j] - [+] map { @U[$_][$j] * @L[$i][$_] }, ^$j) / @U[$j][$j];
Line 1,913:
sub is-square (@m) { so @m == all @m[*] }
sub matrix-zero ($n, $m = $n) { map
sub matrix-ident ($n) { map
sub mmult(@a,@b) {
|