Matrix library | ru |
This program is a sorce code of matrix library. It includes two classes Matrix and MatrixException. The program demonstrates object-orienting programming, exception handling, operators overloading, working with dinamical memory. The code can be used for mathematical problems where you need use matrices and/or vectors.
Creation of the matrices (constructors)
Matrix M(3,3); - creates matrix 3x3.
Matrix M(2,2 ,1,0,0,1);- creates matrix 2x2 and fill it's elements. So M is matrix which has ones on diagonal and zeros on the other positions.
Note: All init elements of the constructor should have type double or type int
Let's see on example
Matrix M(2,2, 1.0,1,0,1). Such creation and initialization will produces difficult to find error because first initialization element has type double but all the others have type int.
You should use ALL initialization elements as well. If you creates matrix 3x3 use 9 initializaton numbers or don't use them at all.
Matrix M(3) such initialization produces matrix 1x1 with initialization element equals 3
Access to matrix elements and getting dimensions of the matrix
For getting number of rows of the matrix use GetRows() member, analogous use GetCols() member for getting number of columns.
Example
To get access to matrix elements use overload () operator. Matrix elements zero index based.
Example
Operators
This library uncludes only simple operations such as addition, substruction, multiplication, division, matrix trasposition, inversion, division/mutiplication by number, addition/substracton with a number (if matrix has dimensions 1x1), unary +, unary -. All of the operations have natural notation. For transposition you can use T function or unary *
Example
Type transformation
It's possible to transformate the matrix to double type if matrix has dimensions 1x1
Example
Exceptions
The code includes MatrixException class which is use when some operator impossible to execute.
Example
Output
Addition isn't possible