Anonymous user
Cramer's rule: Difference between revisions
m
→version 2: added a better way to express the equations.
m (→version 2: shrunk a function.) |
m (→version 2: added a better way to express the equations.) |
||
Line 2,436:
values= '-3 -32 -47 49' /*values of each matrix row of numbers.*/
variables= substr('abcdefghijklmnopqrstuvwxyz', 27 - words(values) ) /*variable names.*/
call makeM ' 2 -1 5
do y=1 for sz; $= /*display the matrix (linear equations)*/
do x=1 for sz; $= $
end /*y*/ /* [↑] right─justify matrix elements.*/
end /*x*/ /* [↑] obtain value of the equation. */
say; say
Line 2,449:
end /*i*/
end /*j*/
say
end /*k*/
exit 0 /*stick a fork in it, we're all done. */
Line 2,455:
makeL: $=; do x=1 for sz; do y=1 for sz; $= $ !.x.y; end; end; return $ /*matrix─►list*/
mSize: arg _; do sz=0 for 1e3; if sz*sz==_ then return; end; say 'error,bad matrix';exit 9
psign: parse arg num; if left(num, 1)\=='-' & x>1 then return "+"num; return num
/*──────────────────────────────────────────────────────────────────────────────────────*/
det: procedure; parse arg a b c d 1 nums; call mSize words(nums);
if sz==2 then return a*d - b*c
do j=1 for sz
Line 2,469 ⟶ 2,470:
end /*j*/
aa= aa - (-1 ** odd) * @.i.1 * det($)
end; /*i*/; return aa
/*──────────────────────────────────────────────────────────────────────────────────────*/
makeM: procedure expose @. values mat sz w
#= 0;
do j=1 for sz; wv= max(wv, length( word( values, j) ) )
do k=1 for sz; #= #+1; @.k.j= word(mat, #); w= max(w, length(@.k.j)
end /*k*/
end; /*j*/; w= w + 1; return</lang>
{{out|output|text= when using the internal default inputs:}}
<pre>
2*w -1*x +5*y +1*z =
3*w +2*x +2*y -6*z =
1*w +3*x +3*y -1*z =
5*w -2*x -3*y +3*z =
w = 2
x = -12
y = -4
z = 1
</pre>
|