Cramer's rule: Difference between revisions

m
modified the task to solve for 4 unknown variables and updated the examples
m (→‎{{header|Perl 6}}: generic algorithm for matrix determinant)
m (modified the task to solve for 4 unknown variables and updated the examples)
Line 18:
:<math>
\begin{cases}
2x 2w- 3y x+5y+ z = 4-3 \\
x - 3w+2x+2y - 2z 6z= -632 \\
w+3x - 4y + 3y-z = 5-47 \\
5w-2x-3y+3z=49 \\
\end{cases}
</math>
 
solve for <math>w</math>, <math>x</math>, <math>y</math> and <math>z</math>, using Cramer's rule.
 
=={{header|Perl 6}}==
Line 58 ⟶ 59:
 
my @matrix = (
[2, -31, 5, 1],
[13, - 2, - 2, -6],
[31, -4 3, 3, -1],
[5, -2, -3, 3],
);
 
my @free_terms = (4-3, -32, -647, 549);
my ($w, $x, $y, $z) = |cramers_rule(@matrix, @free_terms);
 
say "w = $w";
say "x = $x";
say "y = $y";
Line 71 ⟶ 74:
{{out}}
<pre>
xw = 2
yx = 1-12
zy = 3-4
z = 1
</pre>
 
Line 110 ⟶ 114:
 
var matrix = [
[2, -31, 5, 1],
[13, - 2, - 2, -6],
[31, -4 3, 3, -1],
[5, -2, -3, 3],
]
 
var free_terms = [4-3, -32, -647, 549]
var (w, x, y, z) = cramers_rule(matrix, free_terms)...;
 
say "w = #{w}"
say "x = #{x}"
say "y = #{y}"
Line 123 ⟶ 129:
{{out}}
<pre>
xw = 2
yx = 1-12
zy = 3-4
z = 1
</pre>
2,747

edits