# Matrix - operator multiplication of two matrices Matrix...

This preview shows pages 1–2. Sign up to view the full content.

// This file contains the definition of the class Matrix / #include "Matrix.h" # // ----------------------------------------------------------------------- default constructor // a default matrix is an identity matrix / Matrix::Matrix(void) { M for (int x = 0; x < 4; x++) for (int y = 0; y < 4; y++) { if (x == y) m[x][y] = 1.0; else m[x][y] = 0.0; } } // ----------------------------------------------------------------------- copy constructor c for (int x = 0; x < 4; x++) f for (int y = 0; y < 4; y++) f m[x][y] = mat.m[x][y]; m } // ----------------------------------------------------------------------- destructor d Matrix::~Matrix (void) {} M // ----------------------------------------------------------------------- assignment operator a Matrix& return (*this); r for (int x = 0; x < 4; x++) f for (int y = 0; y < 4; y++) f m[x][y] = rhs.m[x][y]; m return (*this); } // -----------------------------------------------------------------------

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: operator* // multiplication of two matrices / Matrix Matrix::operator* (const Matrix& mat) const { Matrix product; p for (int y = 0; y < 4; y++) for (int x = 0; x < 4; x++) { double sum = 0.0; d for (int j = 0; j < 4; j++) sum += m[x][j] * mat.m[j][y]; product.m[x][y] = sum; p } return (product); } // ----------------------------------------------------------------------- operator/ // division by a scalar / Matrix Matrix::operator/ (const double d) { for (int x = 0; x < 4; x++) f for (int y = 0; y < 4; y++) f m[x][y] = m[x][y] / d; m return (*this); } // ----------------------------------------------------------------------- set_identity // set matrix to the identity matrix / void v Matrix::set_identity(void) { for (int x = 0; x < 4; x++) for (int y = 0; y < 4; y++) { if (x == y) m[x][y] = 1.0; else m[x][y] = 0.0; } }...
View Full Document

## This note was uploaded on 02/19/2010 for the course CS 390 taught by Professor Hu during the Spring '10 term at Westminster UT.

### Page1 / 2

Matrix - operator multiplication of two matrices Matrix...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online