addmat.sml
################################################################
# AddMatrix(matrixOut, matrixLeft, matrixRight)
################################################################
clear();
class MATRIX h1, h2, h3;
h1 = CreateMatrix(2,2); # create three matrices
h2 = CreateMatrix(2,2);
h3 = CreateMatrix(2,2);
# fill the matrices with some values
numeric r, c, a;
for r = 0 to 1 {
for c = 0 to 1 {
SetMatrixItem( h1, r, c, r + c );
SetMatrixItem( h2, r, c, (r + c) * 2 );
SetMatrixItem( h3, r, c, (r + c) * 3 );
}
}
AddMatrix(h3, h1, h2 ); # now add h1 to h2, result is h3
printf( "%s\n", "add h1 + h2" ); # print the resulting matrix h3
for r = 0 to 1 {
for c = 0 to 1 {
a = GetMatrixItem( h3, r, c );
printf( "%8.4f ", a );
}
printf( "%s\n", " " );
}
# 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
|