Matrices  1.0
Basic matrix library
 All Classes Files Functions Variables Friends
Functions
Matrix.cpp File Reference

Matrix class implementation file. More...

#include "Matrix.h"
#include <assert.h>

Functions

Matrix operator+ (const Matrix &lhs, const Matrix &rhs)
 
Matrix operator- (const Matrix &lhs, const Matrix &rhs)
 
Matrix operator* (const Matrix &lhs, const Matrix &rhs)
 
Matrix operator* (double s, const Matrix &mat)
 
Matrix operator* (const Matrix &mat, double s)
 
Matrix operator/ (const Matrix &mat, double s)
 
std::ostream & operator<< (std::ostream &outputStream, const Matrix &mat)
 Stream insertion operator.
 
std::istream & operator>> (std::istream &inputStream, Matrix &mat)
 Stream extraction operator.
 

Detailed Description

Matrix class implementation file.

Function Documentation

Matrix operator* ( const Matrix lhs,
const Matrix rhs 
)

This creates the product of two Matrices. The first Matrix must have the same number of columns as the second Matrix has rows.

Note that multiplication is declared as a friend. It could be declared as a normal method Matrix operator*(const Matrix& rhs);. The friend form provides a more symmetric view of the two Matrices being multiplied.

Parameters
lhsThe Matrix on the left hand side of the *.
rhsThe Matrix on the right hand side of the *.
Returns
The Matrix formed by lhs * rhs.
Matrix operator* ( double  s,
const Matrix mat 
)

This creates the product of a scalar and a Matrix.

Note that multiplication is declared as a friend. In this case a normal method Matrix operator*(const scalar s); only works for multiplication by a scalar on the right.

Parameters
sThe scalar value to multiply the Matrix by.
matThe Matrix to be scaled.
Returns
The Matrix formed by s*mat.
Matrix operator* ( const Matrix mat,
double  s 
)

This creates the product of a Matrix and a scalar.

Note that multiplication is declared as a friend. In this case a normal method Matrix operator*(const scalar s); only works for multiplication by a scalar on the right.

Parameters
matThe Matrix to be scaled.
sThe scalar value to multiply the Matrix by.
Returns
The Matrix formed by mat*s.
Matrix operator+ ( const Matrix lhs,
const Matrix rhs 
)

This performs addition of two Matrices. The two Matrices must have the same size

Note that addition is declared as a friend. It could be declared as a normal method Matrix operator+(const Matrix& rhs);. The friend form provides a more symmetric view of the two Matrices being added.

Parameters
lhsThe Matrix on the left hand side of the +.
rhsThe Matrix on the right hand side of the +.
Returns
The Matrix formed by lhs + rhs.
Matrix operator- ( const Matrix lhs,
const Matrix rhs 
)

This performs subtraction of two Matrices. The two Matrices must have the same size

Note that subtraction is declared as a friend. It could be declared as a normal method Matrix operator-(const Matrix& rhs);. The friend form provides a more symmetric view of the two Matrices being subtracted.

Parameters
lhsThe Matrix on the left hand side of the -.
rhsThe Matrix on the right hand side of the -.
Returns
The Matrix formed by lhs - rhs.
Matrix operator/ ( const Matrix mat,
double  s 
)

This creates the result of a Matrix divided by a scalar. Division by a scalar, s, is essentially the same as multiplcation (or scaling) by 1/s. Division by numbers close to 0 will result in NaN and Inf values and wildly unstable results as normal.

Note that division is declared as a friend. In this case a normal method Matrix operator/(const scalar s); would be probably OK, but inconsistent with other operators.

Parameters
matThe Matrix to be scaled.
sThe scalar value to divide the Matrix by.
Returns
The Matrix formed by mat/s.
std::ostream& operator<< ( std::ostream &  outputStream,
const Matrix mat 
)

Stream insertion operator.

Provides the ability to output Matrices to C++ streams, including std::cout and filestreams.

Note that the stream operators do not require special access to the Matrix internals, so are not members or friends.

Parameters
outputStreamthe stream to send the Matrix to.
matthe matrix to send to the stream.
Returns
The updated output stream.
std::istream& operator>> ( std::istream &  inputStream,
Matrix mat 
)

Stream extraction operator.

Provides the ability to read Matrices from C++ streams, including std::cin and filestreams. The size of the Matrix determines how much data is read from the stream.

Note that the stream operators do not require special access to the Matrix internals, so are not members or friends.

Parameters
inputStreamthe stream to read the Matrix from.
matthe matrix to read from the stream.
Returns
The updated input stream.