Biomechanical Joint Model
 Author: Anderson Maciel

sample_linalg.cpp

Go to the documentation of this file.
00001 // sample code for using amaury's linear algebra library
00002 
00003 #include <linalg.h>
00004 
00005 using namespace LinAlg;
00006 using namespace std;
00007 
00008 
00009 #define DOUBLE_PRECISION   // let's use doubles instead of floats
00010 // bounds checking can be activated by using compilation flag BOUNDS_CHECK
00011 #include "linalg.h"
00012 
00013 void main()
00014 {
00015    // vector stuff
00016    
00017    VEC A;                           // define an empty vector
00018    VEC B(dimspace);                 // define a vector with usual size 3 (default val = 0);
00019    VEC C = B;
00020    VEC D(dimspace, "1.0 4.5 -10");
00021    VEC E(dimspace, 0.1234);         // assign a default val
00022    float array_floats[] = {1., 10., 100.};
00023    VEC F(array_floats, dimspace);  // note the reverse order when using floats
00024 
00025    cout << "A = " << A << " B = " << B <<" C = " << C <<" D = " << D <<" E = " << E
00026         << " F = " << F << endl;
00027 
00028    // usual operations
00029    A = D;                // A is resized as its default size is 0, contents is lost when resizing
00030    A += A;
00031    A *= 0.5;
00032    B = -C + D*10 - E/3;
00033    
00034 
00035    // array of vectors stuff
00036    VECArray VA(3, 1, 1, 55);   // define a one-dimensional array of 3 vectors with val -5
00037    VECArray VB = -VA;          // copy constructor
00038    VECArray VC(4,4,4,100,2);   // define a 4x4x4 array of vectors of dim 2 with val 100
00039    VECArray VD(512);           // define an array of 512 vectors of size 3 with val 0
00040       
00041    // VECArray is a container so it can be used with std classes
00042    // copy(VA.begin(), VA.end(), ostream_iterator<REAL>(cout, " "));
00043 
00044    // usual operations are defined
00045    cout << endl << -VA + 2.5*abs(VB)/6 << endl;
00046    
00047    // one-dim array access
00048    cout << " dot product of " << VA[0] << " and " << VB[0] << " = " 
00049         << dot_prod(VA[0], VB[0]) << endl;
00050 
00051    // 3-dim array access
00052    //cout << sqrt(VC(idx3(2,2,2)));
00053 }
00054 
00055 

Generated on Thu Dec 1 10:13:40 2005 for COME - Biomechanical Joint Model by  doxygen 1.4.5