| | |
Solve a 2x2 linear equation matrix with Cramer's Rule
Please support our C++ advertiser: Intel Parallel Studio Home
This program was inspired by my college math 1 class. It takes the values of a1, a2, b1, b2, c1, c2 and solves, displays the equation and shows the work. It also stops if the equation is dependant or inconsistent (Zero division)
Cramer's Rule
if a1x+b1y=c1 and a2x+b2y=c2
then x=((c1*b2)-(c2*b1))/((a1*b2)-(a2*b1))
y=((a1*c2)-(a2*c1))/((a1*b2)-(a2*b1))
where (a1*b2)-(a2*b1)!=0
#Compiled on Dev-C++
#Comment or post bugs please
Cramer's Rule
if a1x+b1y=c1 and a2x+b2y=c2
then x=((c1*b2)-(c2*b1))/((a1*b2)-(a2*b1))
y=((a1*c2)-(a2*c1))/((a1*b2)-(a2*b1))
where (a1*b2)-(a2*b1)!=0
#Compiled on Dev-C++
#Comment or post bugs please
#include <iostream> #include <windows.h> using namespace std; int main(){ int Deter, DeterX, DeterY, A1, A2, B1, B2, C1, C2; int B1Sign, B2Sign, DeterX_Dem, DeterY_Dem; bool Det_Ind=false; SetConsoleTitle("Cramer's Rule"); cout<<"Program Written By Shawncplus To Solve a Linear Equation with Cramer's Rule"<< endl; cout<<"Please Enter a1: "; cin>>A1; cout<<"\nPlease Enter b1: "; cin>>B1; cout<<"\nPlease Enter c1: "; cin>>C1; cout<<"\nPlease enter a2: "; cin>>A2; cout<<"\nPlease enter b2: "; cin>>B2; cout<<"\nPlease Enter c2: "; cin>>C2; cout<<"The Equation is {\n"; B1Sign=B1*(-1); B2Sign=B2*(-1); if (B1>0){ cout<<"\t "<< A1 <<"x+"<<B1<<"y = "<< C1<< endl;} else if (B1<0){ cout<<"\t "<< A1 <<"x-"<<B1Sign<<"y = "<< C1<< endl;} if (B2>0){ cout<<"\t "<< A2 <<"x+"<<B2<<"y = "<< C2<< "\n\t\t} " <<endl;} else if (B2<0){ cout<<"\t "<< A2 <<"x-"<<B2Sign<<"y = "<< C2<< "\n\t\t} " << endl;} Deter=(A1*B2)-(A2*B1); DeterX=(C1*B2)-(C2*B1); DeterY=(A1*C2)-(A2*C1); if (Deter==0 && DeterX==0 && DeterY==0) { cout<<"System is Dependant (Infinite Solutions)"<< endl; Det_Ind = true; } else if (Deter==0 && (DeterX!=0 || DeterY!=0)){ cout<<"System is Inconsistent (System Set is \xE9 )"<< endl; Det_Ind = true; } cout<<"D = "<< Deter << endl; cout<<"D(x) = "<< DeterX << endl; cout<<"D(y) = "<< DeterY << endl; if (Det_Ind==true){ cout<<"Please press Enter to continue. . ."; cin.get(); cin.get(); return 0; } else if (Det_Ind==false){ DeterX_Dem=(DeterX/Deter); DeterY_Dem=(DeterY/Deter); cout<<"\nX = "<< DeterX<<"/"<< Deter <<" = "<< DeterX_Dem << endl; cout<<"Y = "<< DeterY<<"/"<< Deter <<" = "<< DeterY_Dem << endl; cout<<"Solution Set is {("<< DeterX_Dem <<","<< DeterY_Dem <<")}"<< endl; } cout<<"\n\nPlease press Enter to continue. . ."; cin.get(); cin.get(); return 0; }
Similar Threads
- Need To Solve The Equation (Java)
- Linear Equation(Need help on this and is really urgent please) (Python)
- solving linear equation in turbo c (C)
- solve equadratric equation in C (C)
- how to using borland c++ to draw a Mohr's circle and solve cubic equation? (C++)
| Thread Tools | Search this Thread |
api array arrays based binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game generator givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg sorting string strings temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets



