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

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Cramer's rule step by step in the Wren 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 Wren programming language

Source code in the wren programming language

import "./matrix" for Matrix

var cramer = Fn.new { |a, d|
    var n = a.numRows
    var x = List.filled(n, 0)
    var ad = a.det
    for (c in 0...n) {
        var aa = a.copy()
        for (r in 0...n) aa[r, c] = d[r, 0]
        x[c] = aa.det/ad
    }
    return x
}

var a = Matrix.new([
    [2, -1,  5,  1],
    [3,  2,  2, -6],
    [1,  3,  3, -1],
    [5, -2, -3,  3]
])

var d = Matrix.new([
    [- 3],
    [-32],
    [-47],
    [ 49]
])

var x = cramer.call(a, d)
System.print("Solution is %(x)")


  

You may also check:How to resolve the algorithm Partition an integer x into n primes step by step in the Rust programming language
You may also check:How to resolve the algorithm Read entire file step by step in the Emacs Lisp programming language
You may also check:How to resolve the algorithm Next highest int from digits step by step in the Delphi programming language
You may also check:How to resolve the algorithm Program termination step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Sorting algorithms/Stooge sort step by step in the Scala programming language