Matrices |
A matrix is a mathematical representation of two dimensional data. It provides a variety of operations to perform mathematical analysis of such data.
Matrix Addition![]()
os_num_matrix class provides the capability to represent and manipulate numerical 2 dimensional matrices.
The example code below shows how to use various methods supported by the os_num_matrix class.
#include <ospace/math.h<
int
main()
{
os_math_toolkit math_init;
const long TEST_SIZE = 5;
const double TEST_A = 2;
os_num_matrix< double > matrix_x( TEST_SIZE, TEST_SIZE, 0.0 );
os_num_matrix< double > matrix_y( TEST_SIZE, TEST_SIZE, 0.0 );
os_num_matrix< double > matrix_z( TEST_SIZE, TEST_SIZE, 0.0 );
int value = 1;
for ( int i = 0; i < TEST_SIZE; i++ )
{
for ( int j = 0; j < TEST_SIZE; j++ )
{
matrix_x( i, j ) = value;
matrix_y( i, j ) = value;
value++;
}
}
cout << "===== matrix contents =====" << endl;
cout << "matrix x" << endl << matrix_x << endl;
cout << "matrix y" << endl << matrix_y << endl;
cout << "matrix z" << endl << matrix_z << endl;
cout << "===== basic scalar ops =====" << endl;
matrix_z = matrix_x + TEST_A;
cout << "z=x+a = " << endl << matrix_z << endl;
matrix_z = matrix_x - TEST_A;
cout << "z=x-a = " << endl << matrix_z << endl;
matrix_z = matrix_x * TEST_A;
cout << "z=x*a = " << endl << matrix_z << endl;
matrix_z = matrix_x / TEST_A;
cout << "z=x/a = " << endl << matrix_z << endl;
cout << "===== basic matrix ops =====" << endl;
matrix_z = matrix_x + matrix_y;
cout << "z=x+y = " << endl << matrix_z << endl;
matrix_z = matrix_x - matrix_y;
cout << "z=x-y = " << endl << matrix_z << endl;
matrix_z = matrix_x * matrix_y;
cout << "z=x*y = " << endl << matrix_z << endl;
matrix_z = matrix_x / matrix_y;
cout << "z=x/y = " << endl << matrix_z << endl;
cout << "===== matrix ops =====" << endl;
matrix_z = matrix_x * matrix_y + matrix_x / matrix_y - matrix_x * matrix_y;
cout << "z=x*y+x/y-x*y = " << endl << matrix_z << endl;
return 0;
}
Copyright©1994-2013 Recursion
Software LLC
All Rights Reserved - For use by licensed users only.