inverse of matrices... in cpp!
here is a sample script of a program i'm running that gives me the determinant of a matrix as well as it's inverse;
Code:
//main matrix v0.1
#
#
// ^^ those are the lines that are in the cpp compiler. i usually don't type em.
// just so you're not confused.
main()
{
cout << "[d11 d12]\n[d21 d22]\n\n";
//you'll love my var names
//the following doubles are vars for the outputted equation above
double d11;
// ^_^
cout << "d11=";
cin >> d11;
cout << "\n\n";
double d12;
cout << "d12=";
cin>> d12;
cout << "\n\n";
double d21;
cout << "d21=";
cin>> d21;
cout << "\n\n";
double d22;
cout << "d22=";
cin>> d22;
cout << "\n\n";
//determinant var
double dDet;
dDet=(d11*d22)-(d12*d21);
//in the next set of variables, the original values of the matrix will be
//made into a transverse or whatever the hell it's called.
double dInv11;
dInv11=d22;
double dInv12;
dInv12=d11*-1;
double dInv21;
dInv21=d21*-1;
double dInv22;
dInv22=d11;
// the next set converts the transverse values into the inverse by multiplying
// them by the determinant.
double dDetInv11;
dDetInv11=(1/dDet)*dInv11;
double dDetInv12;
dDetInv12=(1/dDet)*dInv12;
double dDetInv21;
dDetInv21=(1/dDet)*dInv21;
double dDetInv22;
dDetInv22=(1/dDet)*dInv22;
//outputs the answers
cout << "Determinant=";
cout << dDet;
cout << "\n\n";
cout << "Answer=[";
cout << dDetInv11;
cout << " ";
cout << dDetInv12;
cout << "]\n[";
cout << dDetInv21;
cout << " ";
cout << dDetInv22;
cout << "]";
system("PAUSE");
return 0;
}
it's a little sloppy, i apologize for the format. every time i tab, the cursor goes from the field to somewhere else on the page. this is freshly typed. (i haven't tried to compile it yet)
there are some extra variables that i added in because i was in a hurry when i wrote it, but i'm going to take those out when i get some time.
if any programmers have any suggestions for my coding, please post. i'll post the program for people to see how it works later when it's atleast v0.15 and compiled.