User Tools

Site Tools


mmbasic:solving_simultaneous_equations_in_mmbasic

Solving Simultaneous Equations using MMBasic Matrices

Some background
Matrices - solving two simultaneous equations
Solving Systems of Linear Equations Using Matrices

To solve these three equations in three unknowns using Matrices

x + 2y + 3z = 3
2x + 4y + 5z = 4
3x + 5y + 6z = 5

The coefficient array is 1 2 3 2 4 5 3 5 6

The answer array is 3 4 5

To solve using MMBasic Matrix arithmetic.

OPTION BASE 1
DIM C(3),B(3,3)
DIM A(3,3)=(1,2,3,2,4,5,3,5,6), X(3)=(3,4,5)
MATH M_INVERSE A(),B()
MATH M_PRINT B()
MATH V_MULT B(),X(),C()
PRINT "SOLUTIONS ARE "
PRINT
MATH V_PRINT C()
END

 1.0000,   -3.0000,    2.0000
-3.0000,    3.0000,   -1.0000
 2.0000,   -1.0000,    0.0000

SOLUTIONS ARE

x=1.0000,   y=-2.0000,    z=2.0000

Originally posted here: https://www.thebackshed.com/forum/ViewTopic.php?TID=17777&P=23#237154

Credit: toml_12953

mmbasic/solving_simultaneous_equations_in_mmbasic.txt · Last modified: by Gerry