Main Page | Namespace List | Alphabetical List | Class List | File List | Class Members | File Members

Matrix.cpp File Reference

#include "Matrix.h"

Include dependency graph for Matrix.cpp:

Go to the source code of this file.

Functions

Matrix operator+ (const Matrix &mat1, const Matrix &mat2)
Matrix operator- (const Matrix &mat1, const Matrix &mat2)
Matrix operator * (const Matrix &mat1, const Matrix &mat2)
bool operator== (const Matrix &mat1, const Matrix &mat2)
ostream & operator<< (ostream &os, const Matrix &mat)


Function Documentation

Matrix operator * const Matrix mat1,
const Matrix mat2
 

Exceptions:
Bad_Dimensions thrown if the matrix dimensionsdo not fit

Definition at line 134 of file Matrix.cpp.

References Matrix::_lines, Matrix::_ncols, Matrix::_nlines, Matrix::column(), and Matrix::line().

00135 {
00136     if (mat1._ncols != mat2._nlines) 
00137         throw Matrix::Bad_Dimensions();
00138 
00139     int nl = mat1._nlines;
00140     int nc = mat2._ncols;
00141     Matrix mat(nl, nc); 
00142     for (int i = 0; i < nl; ++i)
00143         for (int j = 0; j < nc; ++j)
00144             mat._lines[i][j] = mat1.line(i) * mat2.column(j);
00145     return mat;
00146 }

Here is the call graph for this function:

Matrix operator+ const Matrix mat1,
const Matrix mat2
 

Exceptions:
Bad_Dimensions thrown if the matrix dimensions are different

Definition at line 102 of file Matrix.cpp.

References Matrix::_lines, Matrix::_ncols, and Matrix::_nlines.

00103 {
00104     if (mat1._nlines != mat2._nlines || mat1._ncols != mat2._ncols) 
00105         throw Matrix::Bad_Dimensions();
00106 
00107     int nl = mat1._nlines;
00108     int nc = mat1._ncols;
00109     Matrix mat(nl, nc);    
00110     for (int i = 0; i < nl; ++i)
00111         mat._lines[i] = mat1._lines[i] + mat2._lines[i];
00112     return mat;
00113 }

Matrix operator- const Matrix mat1,
const Matrix mat2
 

Exceptions:
Bad_Dimensions thrown if the matrix dimensions are different

Definition at line 118 of file Matrix.cpp.

References Matrix::_lines, Matrix::_ncols, and Matrix::_nlines.

00119 {
00120     if (mat1._nlines != mat2._nlines || mat1._ncols != mat2._ncols) 
00121         throw Matrix::Bad_Dimensions();
00122 
00123     int nl = mat1._nlines;
00124     int nc = mat1._ncols;
00125     Matrix mat(nl, nc);    
00126     for (int i = 0; i < nl; ++i)
00127         mat._lines[i] = mat1._lines[i] - mat2._lines[i];
00128     return mat;
00129 }

ostream& operator<< ostream &  os,
const Matrix mat
 

We print each line of the matrix as an MVector on a single line. The whole matrix is also encolsed within square brackets.

Definition at line 196 of file Matrix.cpp.

References Matrix::_lines, and Matrix::_nlines.

00197 {
00198     os << "[\n";
00199     for (int i = 0; i < mat._nlines; ++i)
00200         os << "  " << mat._lines[i] << '\n';
00201     os << ']';
00202     return os;
00203 }

bool operator== const Matrix mat1,
const Matrix mat2
 

Note:
We use MVector equality

Definition at line 151 of file Matrix.cpp.

References Matrix::_lines, and Matrix::_nlines.

00152 {
00153     if (mat1._nlines != mat2._nlines) return false;
00154     for (int i = 0; i < mat1._nlines; ++i)
00155         if (mat1._lines[i] != mat2._lines[i]) return false;
00156     return true;
00157 }


Generated on Mon Dec 12 18:25:43 2005 for Vectors_and_Matrices by  doxygen 1.4.3