OK I have a funtion in my matrix program to multiply one row by a multiplie and then subtract that row from another row. here is the definition:
where Array[][] represents the elements of the matrix.Code:void Matrix::elimination(float multiple, int row1, int row2) { // subtracts multiple*row1 from row2 float temp; for(y = 0; y < b; y++) { temp = Array[row2-1][y] - (multiple*Array[row1-1][y]); Array[row2-1][y] = temp; } }
The problem: I've tried two matrices - in one it works, in the other it doesn't do anything.
With the matrix:
1 1 3 -1 0 0
-1 1 1 1 1 -4
0 1 2 2 -1 0
I put in the parameters for elimination: (-1, 1, 2), which subtracts the -1 times the first row from the second row. (adds row 1 to row 2).
and I get the following matrix as output:
1 1 3 -1 0 0
0 2 4 0 1 -4
0 1 2 2 -1 0
which is what I wanted to get (to make the first entry of row 2 a zero)
but if I use this matrix:
2 1 3
1 2 3
4 2 1
and use elimination(1/2, 1, 2) to subtract 1/2 the first row from the second, it gives the exact same matrix as output!
it SHOULD give this:
2 1 3
0 1.5 1.5
4 2 1
What could be causing this?
here is the rest of the code for reference (case 'a' is where I tested the elimination method)
http://dydx.no-ip.com:8080/matrix.h
http://dydx.no-ip.com:8080/matrix.cpp