I have managed to do the determinant and have a person enter their own matrix and that works fine. I am trying to use the inverse by making a second matrix "matb" and use it as the inverse as seen below. mat[3][3]
was my declared matrix and the numbers are selected by the user, im using :
#include<math.h>
at the top but i cant see why my code won't let me use the values from "mat" to set matb
:
int matb[3][3]= { {(mat[1][1] * mat[2][2]) - (mat[1][2] * mat[2][1]) , (mat[1][2] * mat[2][0]) - (mat[1][0] * mat[2][2]) ,(mat[1][0] * mat[2][1]) - (mat[1][1] * mat[2][0]) } , { (mat[0][2] * mat[2][1]) - (mat[0][1] * mat[2][2]) ,(mat[0][0] * mat[2][2]) - (mat[0][2] * mat[2][0]) ,(mat[0][1] * mat[2][0]) - (mat[0][0] * mat[2][1]) } , { (mat[0][1] * mat[1][2]) - (mat[0][2] * mat[1][1]), (mat[0][2] * mat[1][0]) - (mat[0][0] * mat[1][2]),(mat[0][0] * mat[1][1] )- (mat[0][1] * mat[1][0]) } };
It is a long bit of code but mathematically it is correct so im assuming it is something in the code that i have done wrong.
I don't get any compiling error, when i print it to screen, it comes up as a string of letters and numbers, and when used in further calculations the further calculations are very wrong indeed.
This isnt a duplicate as i am not trying to print the inverse, i just printed it to check the code is correct, and it isnt.
int matb[3][3]= { { mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1], mat[1][2] * mat[2][0] - mat[1][0] * mat[2][2], mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0] }, { mat[0][2] * mat[2][1] - mat[0][1] * mat[2][2], mat[0][0] * mat[2][2] - mat[0][2] * mat[2][0], mat[0][1] * mat[2][0] - mat[0][0] * mat[2][1] }, { mat[0][1] * mat[1][2] - mat[0][2] * mat[1][1], mat[0][2] * mat[1][0] - mat[0][0] * mat[1][2], mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0] } };
cout << matb[x][y] << endl; //somethings wrong, not doing it properly
for (x = 0; x < 3; x++)
for (y = 0; y < 3; y++)
{
matbt[y][x] = matb[x][y]; // wrong from matb
}
inverse = determinant*matbt[3][3];
cout << inverse << endl;
That is my code, the rest is the standard return(0) _getch() ect