This is an old revision of the document!
Table of Contents
DM41X Matrix
Matrix functions in the Advantage Pac
Background
The matrix functionality isn't a standalone program, with a menu, like CFIT and PLY.
It's a collection of individual programs that can be used for many matrix tasks. Each one has to be called individually as needed.
There are many commands, the most used are those for
- Dimensioning a new matrix
MATDIM - Editing a matrix to enter values - there are 2 versions
- Real Matrix
MEDIT - Complex Matrix
CMEDIT
- Inverting a matrix
MINV - Transposing a matrix
TRNPS - Finding the determinant
MDET - Multiplying two matrices together
M*M - Solving a system of equations defined by 2 matrices
MSYS
Shortcuts to Matrix Commands
To make things easier it's best to use the DM41X CST custom command shortcut mechanism.
Start with a blank CST and add the commands you need. Then save this CST so that it's easy to switch to other CST setups, and then return to the Matrix setup later.
I have the following
| A | MATDIM | I | |
| B | MEDIT | J | |
| C | CMEDIT | K | |
| D | MINV | L | |
| E | M*M | M | |
| F | MDET | N | EMDIR |
| G | TRNPS | O | EMDIRX |
| H | MSYS | P | PURFL |
Matrices are saved in Extended Memory, and I put commands in CST to find and remove them once I'm finished: EMDIR, EMDIRX and PURFL
Basic Workflow
All matrix addressing is done via the ALPHA register
Dimension a new Matrix
- Put the
nameof the matrix in theALPHAregister.- Use single letters
A,B,Cetc. - these will create the matrix in Extended Memory - ALPHA A ALPHA
- Put the dimensions in the
Xregister- this is in the form
r.cccwith3decimal places for the column - for a
3×3:3.003(3 rows, 3 columns) - for a
4×2:4.002(4 rows, 2 columns) 3.003- puts the dimensions in the
Xregister ready forMATDIMto assign to the matrix named inALPHA
- Execute the
MATDIMcommand from theCSTmenuA- CST A
- This creates matrix
Ain extended memory
Populate a new Matrix
- Populate the matrix with values using
MEDITfrom theCSTmenuB
For a 3×3 matrix
| 1 1 -1 |
| 4 6 6 |
| 1 8 9 |
- CST B
1:1=1R/S1:2=1R/S1:3=1CHSR/S2:1=4R/S2:2=6R/S2:3=6R/S3:1=1R/S3:2=8R/S3:3=9R/S
Determinant
With A still in the ALPHA register use the MDET command from the CST menu F
- CST F
-50.000
- Matrix
Awill now be inLU Decompositionform. - It can be used in this form for some other functions, but it's possible to get it back to
normalform by Inverting twice usingMINVfromCSTmenuD- CST D
- CST D
- You can check the element values by using
MEDITagain, but just cycling through each with R/S and not changing any values- it's possible to set flag
08which prevents any changes to values
Multiplication
Using M*M
For matrix multiplication you need 3 matrix definitions:
- Matrix
Aand MatrixBare the two matrices to be multiplied- Matrix
Aand MatrixBare dimensioned withMATDIMand populated withMEDIT
- Matrix
Cis the matrix to hold the result- Matrix
Cis simply dimensioned withMATDIMand will be filled automatically by the functionM*M
To multiply two matrices together they must have the correct dimensions
- Columns in
Amust equal Rows inB - Results matrix
Cwill have the dimensionsRows of A x Columns of B
Create Matrix A
Follow the same procedure as above.
Make sure ALPHA has only the letter A
A different numerical example
A will be a 3×2 matrix
- use
MATDIMviaCSTmenu3.002CSTA
| 2 3 |
| 4 5 |
| 7 6 |
- Use
MEDITviaCSTmenu- CST B
1:1=2R/S1:2=3R/S2:1=4R/S2:2=5R/S3:1=7R/S3:2=6R/S
Create Matrix B
B will be a 2×2 matrix
Make sure ALPHA only has B and then dimension B with MATDIM from CST menu A
- ALPHA B ALPHA
2.002CSTA
| 2 3 |
| 4 5 |
* Use MEDIT via CST menu
- CST B
1:1=2R/S1:2=3R/S2:1=4R/S2:2=5R/S
We now have defined the matrices to be multiplied together.
Create Matrix C
We need a results matrix C
The dimensions of C will be rows of A and columns of B which is 3 rows and 2 columns : 3.002
Make sure ALPHA only has C and dimension C with MATDIM from CST menu A
- ALPHA C ALPHA
3.002CSTA
That's enough to create the results matrix
Multiply the matrices
- Put the matrix names in
ALPHAin the formMatrix 1,Matrix2,Results MatrixALPHA=A,B,C
- ALPHA A , B ,CALPHA
- Execute
M*Mfrom theCSTmenu- CST E
Cwill now hold the answer
View the result
- Put
Cin theALPHAregister - ALPHA C ALPHA
- Use
MEDITfrom theCSTmenu and cycle through the elements (it's a3×2matrix) - CST B
1:1= 16.000?R/S1:2= 21.000?R/S2:1= 28.000?R/S2:2= 37.000?R/S3:1= 38.000?R/S3:2= 51.000?R/S
The result in C is
| 16 21 |
| 28 37 |
| 38 51 |
System of Equations
A simple example first
Set of Equations
3 unknowns
3x + 4y + 6z = 39.7
2x - 4y - 3z = -7.0
y + 8z = 63.4
Matrix representation
Matrix A
| 3 4 6 |
| 2 -4 -3 |
| 0 1 8 |
- Dimensions
3.003
Matrix B
| 39.7 |
| -7.0 |
| 63.4 |
- Dimensions
3.001
Simultaneous Equations represented in Matrix Form
|A| x |C| = |B|
| 3 4 6 | | x | | 39.7 |
| 2 -4 -3 | x | y | = | -7.0 |
| 0 1 8 | | z | | 63.4 |
Create Matrix A
- ALPHA A ALPHA
3.003CST A (MATDIM)- CST B (
MEDIT)1:1=3 R/S1:2=4 R/S1:3=6 R/S2:1=2 R/S2:2=4 CHS R/S2:3=3 CHS R/S3:1=0R/S3:2=1R/S3:3=8R/S
Create Matrix B
- ALPHA B ALPHA
3.001CST A (MATDIM)- CST B (
MEDIT)1:1=39.7 R/S2:1=7 CHS R/S3:1=63.4 R/S
Run MSYS
- Put
A,BinALPHA- ALPHA A , B ALPHA
- Run
MSYS- the solution matrix forx,yandzwill be placed in MatrixB- CST H
Examine Matrix B
- Put
BinALPHA- ALPHA B ALPHA
- Run
MEDITfromCSTmenu- CST B (
MEDIT)1:1=1.500'R/S/2:1=-3.800R/S3:1=8.400'R/S
The solution
x = 1.5
y = -3.8
z = 8.4
Matrix A
Ais now in LU-decomposed format- It can be restored to normal by Inverting Twice
- Put
AinALPHA - Run
MINVviaCSTmenu twice- CST D CST D
Ais now back to normal and can be inspected and edited byMEDITvia theCSTmenu
Another way to solve a system
Instead of the MSYS function you could do it manually by entering Matrix A and Matrix B, and define Matrix C such that
A X C = B
C = B / A
C = A* X B where A* is Inverse A
Create Matrix C with dimensions 3.001 in the usual way then and do:
- Put
AinALPHA - Invert
AusingMINVfromCSTmenu (Ais replaced by its inverse) - Put
A,B,CinALPHA - Multiply using
M*M- this multiplies
Bby the inverse ofAwhich is effectively dividingBby the originalA
Cnow contains the solutions forx,yandz- Put
CinALPHA - Examine
CwithMEDIT1:1= 1.500R/S2:1= -3.800R/S3:1= 8.400R/s
- This preserves
Bunlike theMSYSmethod. - The Inverse of
Acan be reversed by repeatingMINVwithAinALPHA - We can even run
M*MonAandCto re-createB- Put
A,C,BinALPHA - Run
M*MfromCSTmenu Bwill be re-created
Complex Matrix
It is possible to define, edit and carry out operations with matrices containing Complex Numbers.
The matrix is defined with twice as many rows and columns as appears necessary, and edited with the function CMEDIT, in CST menu C
Example Definition
| 1+j2 5+j6 |
| 3+j4 7+j8 |
Two rows and two columns containing complex numbers, so the definition/dimension is 4.004
The numbers are actually saved as if in a larger real matrix as
| 1 -2 5 -6 |
| 2 1 6 5 |
| 3 -4 7 -8 |
| 4 3 8 7 |
The entry is via CMEDIT which asks for each Real and Imaginary part in turn
- ALPHA A ALPHA
4.004CST A- CST C
RE. 1:1=1R/SIM. 1:1=2R/SRE. 1:2=5R/SIM. 1:2=6R/SRE. 2:1=3R/SIM. 2:1=4R/SRE. 2:2=7R/SIM. 2:2=8R/S
Multiplication of Complex Matrices
Create a second matrix B of 2×1 which can be multiplied by A as A x B
| 3+j4 |
| 2+j6 |
Dimension 4.002
- ALPHA B ALPHA
4.002CST A- CST C
RE. 1:1=3R/SIM. 1:1=4R/SRE. 2:1=2R/SIM. 2:1=6R/S
Create a result matrix 'C' which will be a 2×1 complex with dimension 4.002
- ALPHA C ALPHA
4.002CST A
Multiply
- ALPHA A,B,C
- CST E
Inspect Result Matrix C
- ALPHA C
- CST C
RE. 1:1= -31.000R/SIM. 1:1= 52.000R/SRE. 2:1= -41.000R/SIM. 2:1= 82.000R/S
The result matrix is
| -31+j52 |
| -41+j82 |
Clearing Up Extended Memory
After creating and manipulating (and some finger trouble) there will be a bunch of files in Extended Memory.
Most will be simple matrix definitions with obvious names A, B, C etc. but occasionally you'll accidentally have run MATDIM with some nonsense in the ALPHA register and created a nonsensical filename in extended memory, which it's tricky to spell out correctly in ALPHA in order to run PURLF - this is where EMDIRX comes in.
To simplify clearing up I include EMDIR, EMDIRX and PURFL in the CST menu.
Assuming you have other files in Extended Memory, the quickest way is to find the number of files in EM with EMDIR.
- Run
EMDIRfromCSTmenu- CST N
- Count the files to find the number of the first file you've created using
MATDIM- i.e. the first one after your other EM files - Put this number in
x - Run
EMDIRXfromCSTmenu- CST O
- this puts the
nameof the specified-numbered file inALPHAand means you don't have to type it in yourself
- Run
PURFLfromCSTmenu to delete this filename- CST P
- Run
EMDIRXagain (with the same number inX)- If
Xreturns as non-zero we've found another junk-matrix file in EM andALPHAwill have its name - Run
PURFLagain
- Keep doing this until
EMDIRXreturns0.00inXwhich means there are no more files to delete- all your original files are still safe, as they are numbered below the number we were searching for