예제 #1
0
// Vector matrix multiplication
Vector operator *(const Vector& v, const Matrix& m){
  int orig_size = v.GetSize();
  assert(m.GetNumberOfRows() == orig_size);
  int new_size = m.GetNumberOfCols();
  Vector new_v(new_size);
  for (int i=0; i<new_size; i++){
    for (int j=0; j<orig_size; j++){
      new_v[i] += v.Read(j)*m.mData[j][i];
    }
  }
  return new_v;
}
예제 #2
0
// Copy matrix and vector so that original matrix and vector
// specified are unchanged by Gaussian elimination
LinearSystem::LinearSystem(const Matrix& A, const Vector& b)
{
   // check matrix and vector are of compatible sizes
   int local_size = A.GetNumberOfRows();
   assert(A.GetNumberOfColumns() == local_size);
   assert(b.GetSize() == local_size);

   // set variables for linear system
   mSize = local_size;
   mpA = new Matrix(A);
   mpb = new Vector(b);
}
예제 #3
0
//Copy
Matrix::Matrix(const Matrix& otherMatrix){
  mNumRows = otherMatrix.GetNumberOfRows();
  mNumCols = otherMatrix.GetNumberOfCols();
  mData = new double*[mNumRows];
  for(int i=0; i<mNumRows; i++){
    mData[i] = new double [mNumCols];
  }
  for(int i=0; i<mNumRows; i++){
    for(int j=0; j<mNumCols; j++){
      mData[i][j] = otherMatrix.mData[i][j];
    }
  }
}