|
TNTmips Downloads Menu

|
invmat.sml
################################################################
# InvertMatrix(matrixOut, matrixIn)
################################################################
clear();
class MATRIX h1, h2, h3;
h1 = CreateMatrix(2,2); # create two matrices
h2 = CreateMatrix(2,2);
h3 = CreateMatrix(2,2);
# fill the matrices values known to produce matrix with an inverse
SetMatrixItem( h1, 0, 0, 1.0 );
SetMatrixItem( h1, 0, 1, 2.0 );
SetMatrixItem( h1, 1, 0, 3.0 );
SetMatrixItem( h1, 1, 1, 4.0 );
# print the resulting matrix
printf( "matrix before inverse\n" );
PrintMatrixToConsole( h1 );
# now calculate the inverse of h1
InvertMatrix( h2, h1 );
# print the inverse matrix
# result should be | -2.0 1.0 |
# | 1.5 -.5 |
printf( "matrix after inverse\n" );
PrintMatrixToConsole( h2 );
# now multiply matrix 1 by it's inverse
# result matrix h3 should be identity matrix
MultiplyMatrix( h3, h1, h2 );
printf( "matrix times it's inverse\n" );
PrintMatrixToConsole( h3 );
# destroy the matrices
DestroyMatrix(h1);
DestroyMatrix(h2);
DestroyMatrix(h3);
©MicroImages, Inc. 2013 Published in the United States of America
11th Floor - Sharp Tower, 206 South 13th Street, Lincoln NE 68508-2010 USA
Business & Sales: (402)477-9554 Support: (402)477-9562 Fax: (402)477-9559
Business info@microimages.com
Support support@microimages.com
Web webmaster@microimages.com
| |