
please wait
|
|
|
|
|
|
|
|
This program will calculate the exp of a matrix A (0,0)(0,0)(0,0) (0,0)(0,0)(0,0) (0,0)(0,0)(0,0) (1.1,2.2)(1.1,2.2)(1.1,2.2) (1.1,2.2)(1.1,2.2)(1.1,2.2) (1.1,2.2)(1.1,2.2)(1.1,2.2) |
using double* instead of double** or vector<double> instead? You are making this way too complicated and high risk unless its an exercise to learn or remember why pointers are a lot of trouble. Imagine if you could copy the thing with just a memcpy instead of one at a time in a loop? Imagine if you could transpose in place and flip the row/col values and be done with it? Imagine if to add 2 matrix it was just a for loop? To allocate it, no double loop, to deallocate it, no double loop? |
|
|
|
|
vectors make it even nicer. vector<int> matrix(nc*nr); now you have matrix.size() which is nc*nr (you still need nc and nr, so you know rows and cols, in you class) now you can increase its size (say, for ax=b RREF solver, append a column) using push_back() (you still have rearrange the data, probably transpose, add a row, transpose back to add a column). Now you can copy it: matrix = othermatrix; //vector has copy built out already, so your copy operator in your class is just data = other.data, numrows = other.numrows, numcols = other.numcols, nothing else, very simple. and many other things, and it handles all the dynamic memory for you. |