How to resolve the algorithm Cramer's rule step by step in the Racket programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cramer's rule step by step in the Racket programming language

Table of Contents

Problem Statement

Given

which in matrix format is

Then the values of

x , y

{\displaystyle x,y}

and

z

{\displaystyle z}

can be found as follows:

Given the following system of equations:

solve for

w

{\displaystyle w}

,

x

{\displaystyle x}

,

y

{\displaystyle y}

and

z

{\displaystyle z}

, using Cramer's rule.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Cramer's rule step by step in the Racket programming language

Source code in the racket programming language

#lang racket
(require math/matrix)

(define sys
  (matrix [[2 -1 5 1]
           [3 2 2 -6]
           [1 3 3 -1]
           [5 -2 -3 3]]))

(define soln
  (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 (cramers-rule M soln)
  (let ([denom (matrix-determinant M)]
        [nvars (matrix-num-cols M)])
    (letrec ([roots (λ (position)
                      (if (>= position nvars)
                          '()
                          (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)


  

You may also check:How to resolve the algorithm Repeat a string step by step in the 360 Assembly programming language
You may also check:How to resolve the algorithm Factorial step by step in the beeswax programming language
You may also check:How to resolve the algorithm Seven-sided dice from five-sided dice step by step in the Liberty BASIC programming language
You may also check:How to resolve the algorithm Formatted numeric output step by step in the ARM Assembly programming language
You may also check:How to resolve the algorithm Parametric polymorphism step by step in the Common Lisp programming language