Numeric Vectors


os_num_vector class provides the capability to represent and manipulate numerical vectors. Operations supported include additional, subtraction, multiplication, division, indexing and others.

The following example code shows how to use various methods supported by the os_num_vector class.

Example <ospace/math/examples/numvector.cpp>
#include <ospace/math.h>


int
main()
  {
  os_math_toolkit math_init;

  const long TEST_SIZE = 10;
  const double TEST_A = 2;

  os_num_vector< double > vec_x( TEST_SIZE, 0.0 );
  os_num_vector< double > vec_y( TEST_SIZE, 0.0 );
  os_num_vector< double > vec_z( TEST_SIZE, 0.0 );

  for ( int i = 0; i < TEST_SIZE; i++ )
    {
    vec_x[ i ] = i + 1;
    vec_y[ i ] = i + 1;
    }

  cout << "===== vector contents =====" << endl;
  cout << "vector x" << endl << vec_x << endl;
  cout << "vector y" << endl << vec_y << endl;
  cout << "vector z" << endl << vec_z << endl;


  cout << "===== basic scalar ops =====" << endl;

  vec_z = vec_x + TEST_A;
  cout << "z=x+a = " << endl << vec_z << endl;

  vec_z = vec_x - TEST_A;
  cout << "z=x-a = " << endl << vec_z << endl;

  vec_z = vec_x * TEST_A;
  cout << "z=x*a = " << endl << vec_z << endl;

  vec_z = vec_x / TEST_A;
  cout << "z=x/a = " << endl << vec_z << endl;


  cout << "===== basic vector ops =====" << endl;

  vec_z = vec_x + vec_y;
  cout << "z=x+y = " << endl << vec_z << endl;

  vec_z = vec_x - vec_y;
  cout << "z=x-y = " << endl << vec_z << endl;

  vec_z = vec_x * vec_y;
  cout << "z=x*y = " << endl << vec_z << endl;

  vec_z = vec_x / vec_y;
  cout << "z=x/y = " << endl << vec_z << endl;


  cout << "===== vector ops =====" << endl;

  vec_z = vec_x * vec_y + vec_x / vec_y - vec_x * vec_y;
  cout << "z=x*y+x/y-x*y = " << endl << vec_z << endl;


  return 0;
  }

Copyright©1994-2013 Recursion Software LLC
All Rights Reserved - For use by licensed users only.