How do I initialize the Matrix class?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How do I initialize the Matrix class?

niles-5

I'm new to C++ and would like to use the liboctave stuff.

How can I do the following simple Octave operation in
C++ using liboctave?

%%%%%%%%%%%%%%%%%%%%%%%%%%
a = [1 2];
b = [3 4; 5 6];
c = a*b;
%%%%%%%%%%%%%%%%%%%%%%%%%%

Here's a guess:

//////////////////////////
#include <iostream.h>
#include <config.h>
#include <Matrix.h>

main()
{
  RowVector a(2), c(2); // Can't I set the value of 'a'
  a.elem(0) = 1;        // in the constructor??
  a.elem(1) = 2;

  Matrix b(2,2);
  b.elem(0,0) = 3;
  b.elem(0,1) = 4;
  b.elem(1,0) = 5;
  b.elem(1,1) = 6;

  c = a * b;

  cout << "a = ["  << a << "]" << endl;
  cout << "b = \n" << b << endl;
  cout << "c = ["  << c << "]" << endl;
}

//////////////////////////


        Thanks,
        Rick Niles.