LU decomposition: Difference between revisions

m
→‎{{header|Perl 6}}: minor tweaks, remove some superstitious parentheses
(→‎{{header|Perl 6}}: Add Perl 6 example)
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 ( { [ flat 0 xx $n ] } ), ^$m }
 
sub matrix-ident ($n) { map ( { [ flat 0 xx $_, 1, 0 xx $n - 1 - $_ ] } ), ^$n }
 
sub mmult(@a,@b) {
10,339

edits