How to resolve the algorithm Gauss-Jordan matrix inversion step by step in the Factor programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Gauss-Jordan matrix inversion step by step in the Factor programming language

Table of Contents

Problem Statement

Invert matrix   A   using Gauss-Jordan method. A   being an   n × n   matrix.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Gauss-Jordan matrix inversion step by step in the Factor programming language

Source code in the factor programming language

USING: kernel math.matrices math.matrices.elimination
prettyprint sequences ;

! Augment a matrix with its identity. E.g.
!
! 1 2 3                        1 2 3 1 0 0
! 4 5 6  augment-identity  ->  4 5 6 0 1 0
! 7 8 9                        7 8 9 0 0 1

: augment-identity ( matrix -- new-matrix )
    dup first length <identity-matrix>
    [ flip ] bi@ append flip ;

! Note: the 'solution' word finds the reduced row echelon form
! of a matrix.

: gauss-jordan-invert ( matrix -- inverted )
    dup square-matrix? [ "Matrix must be square." throw ] unless
    augment-identity solution

    ! now remove the vestigial identity portion of the matrix
    flip halves nip flip ;

{
    { -1 -2 3 2 }
    { -4 -1 6 2 }
    {  7 -8 9 1 }
    {  1 -2 1 3 }
} gauss-jordan-invert simple-table.


  

You may also check:How to resolve the algorithm Pointers and references step by step in the AutoHotkey programming language
You may also check:How to resolve the algorithm Execute Brain step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Semiprime step by step in the ALGOL W programming language
You may also check:How to resolve the algorithm Base64 decode data step by step in the Ecstasy programming language
You may also check:How to resolve the algorithm Chinese remainder theorem step by step in the Mathematica / Wolfram Language programming language