Cramer's rule: Difference between revisions

Line 2,311:
 
=={{header|Racket}}==
<syntaxhighlight lang="racket">#lang typed/racket
#lang racket
(require math/matrix)
 
(define sys
{{incorrect|Racket|Doesn't really use Cramer's rule}}
(matrix [[2 -1 5 1]
[3 2 2 -6]
[1 3 3 -321]
[5 -2 -3 3]]))
 
(define soln
<syntaxhighlight lang="racket">#lang typed/racket
(require math/ (col-matrix [-3 -32 -47 49]))
 
(define (matrix-set-column M new-col idx)
(matrix-augment (list-set (matrix-cols M) idx new-col)))
 
(define A (matrix [[2 cramers-1 5rule M 1]soln)
(let ([denom (matrix-determinant M)]
[3 2 2 -6]
[1nvars (matrix-num-cols 3 3 -1M)])
(letrec ([roots (λ (position)
[5 -2 -3 3]]))
(if (>= 49])position nvars)
-47 '()
(cons (/ (matrix-determinant
(matrix-set-column M soln position))
denom)
(roots (add1 position)))))])
(map cons '(w x y z) (roots 0)))))
 
(cramers-rule sys soln)
(define B (col-matrix [ -3
</syntaxhighlight>
-32
-47
49]))
 
(matrix->vector (matrix-solve A B))</syntaxhighlight>
{{out}}
 
<pre>'#((w . 2) (x . -12) (y . -4) (z . 1))</pre>
 
=={{header|Raku}}==
8

edits