mvasamp1.cpp

Go to the documentation of this file.
00001 #include "cammva.h"
00002 #include <stdio.h>
00003 #include <iostream.h>
00004 //
00005 //######################################################################
00006 //
00007 // CAMmva Test Program #1
00008 //
00009 // This program sets up a and solves a linear system of equations.
00010 //
00011 //
00012 // Chris Anderson (C) UCLA 1997
00013 //######################################################################
00014 //
00015 int main(){
00016 
00017   CAMdoubleMatrix A(3,3);           // declare a matrix
00018   CAMdoubleVector b(3);             // declare vectors
00019   CAMdoubleVector x(3);  
00020   CAMdoubleVector residual(3);              
00021     
00022   long i,j;                         // variables for loop index
00023     
00024     
00025   for(i=1; i<= 3; i++)              // nested do-loop for initializing
00026   for(j=1; j<= 3; j++)              // the matrix A.
00027   {
00028     A(i,j)=1.0/(double(i) + double(j)); 
00029   }
00030     
00031   for(i=1; i<=3; i++)               // initialize b
00032   {
00033     b(i)=double(i);
00034   }
00035     
00036   x=A/b;                            // solve the system A*x=b for x
00037   residual=A*x - b;                 // compute the residual
00038     
00039                                     // set scientific notation output 
00040                                     // format
00041 
00042   cout.setf(ios::scientific, ios::floatfield); 
00043 
00044   cout << " The matrix A " << endl;
00045   cout << A;
00046   cout << " The vector b " << endl;
00047   cout << b;
00048   cout << " The solution of A*x=b " << endl;
00049   cout << x;
00050   cout << " The residual " << endl;
00051   cout << residual;
00052 
00053   cout << " Program End : Hit Any Key to Terminate " << endl;
00054   getchar();
00055   return 0;
00056 }
00057 
00058   

Generated on Wed Aug 6 12:58:49 2003 for Open-Sessame Framework by doxygen1.3