Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

RowColumnSparseMatrix.cpp

Go to the documentation of this file.
00001 // RowColumnSparseMatrix.cpp: implementation of the RowColumnSparseMatrix class.
00002 //
00004 
00005 #include "RowColumnSparseMatrix.h"
00006 
00008 // Construction/Destruction
00010 
00011 RowColumnSparseMatrix::RowColumnSparseMatrix(int nRows, int nCols)
00012 :SparseMatrix(nRows,nCols)
00013 {
00014 
00015 }
00016 
00017 RowColumnSparseMatrix::~RowColumnSparseMatrix()
00018 {
00019         for(int i = 0; i < matrix.size(); i++)
00020         {
00021                 delete matrix[i];
00022         }
00023 }
00024 
00025 bool RowColumnSparseMatrix::AddElement(int row, int col, int value)
00026 {
00027         // create a matrix element
00028         RowColumnSparseMatrix::MatrixElement *elem = new RowColumnSparseMatrix::MatrixElement(row,col,value);
00029         // push it onto the list
00030         matrix.push_back(elem);
00031 
00032         return true;
00033 }
00034 
00035 void RowColumnSparseMatrix::OrderElements()
00036 {
00037         return;
00038 }
00039 
00040 bool RowColumnSparseMatrix::RightVectorMultiply(double *colVector, int length)
00041 {
00042         // check for size compatibility
00043         if(length != nCols)
00044         {
00045                 return false;
00046         }
00047 
00048         // temporarily stores result of multiplication
00049         double *sums = new double[nCols];
00050         for(int i = 0; i < nCols; i++)
00051         {
00052                 sums[i] = 0.0;
00053         }
00054 
00055         for(int index = 0; index < matrix.size(); index++)
00056         {       
00057                 int mI = matrix[index]->GetRow();
00058                 int mJ = matrix[index]->GetCol();
00059                 double mElem = matrix[index]->GetValue();
00060 
00061                 sums[mI] += mElem*colVector[mJ];
00062         }
00063 
00064         for(int i = 0; i < nCols; i++)
00065         {
00066                 colVector[i] = sums[i];
00067         }
00068         delete [] sums;
00069 
00070         return true;
00071 }
00072 

Generated on Mon Nov 3 09:38:13 2003 by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002