Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- #define SIZE 15
- using namespace std;
- float M[SIZE][SIZE];
- int vars;
- void display ( ) {
- for (int i = 0; i < vars; i++) {
- for (int j = 0; j <= vars; j++)
- cout << M[i][j] << "\t";
- cout << endl;
- }
- }
- void gauss ( ) {
- for (int i = 0; i < vars; i++) {
- for (int j = i + 1; j < vars; j++) {
- float banisher = M[j][i] / M[i][i];
- for (int k = i; k <= vars; k++)
- M[j][k] -= banisher * M[i][k];
- }
- }
- cout << endl << endl;
- cout << "After Basic Gauss Elimination" << endl;
- display ( );
- // Normalization
- for (int i = 0; i < vars; i++) {
- float div = M[i][i];
- for (int j = i; j <= vars; j++)
- M[i][j] /= div;
- }
- }
- void jordan ( ) {
- for (int i = vars - 1; i >= 0; i--) {
- for (int j = i - 1; j >= 0; j--) {
- float banisher = M[j][i] / M[i][i];
- for (int k = i; k <= vars; k++)
- M[j][k] -= banisher * M[i][k];
- }
- }
- }
- int main ( ) {
- // Getting Input
- cout << "Number of Equations: ";
- cin >> vars;
- cout << "Enter the Augmented Matrix" << endl;
- for (int i = 0; i < vars; i++)
- for (int j = 0; j <= vars; j++)
- cin >> M[i][j];
- system ("cls");
- cout << "Your Input" << endl;
- display( );
- // Forward Elimination
- gauss( );
- cout << endl << endl;
- cout << "Row Echelon Form" << endl;
- display( );
- // Backward Elimination
- jordan( );
- cout << endl << endl;
- cout << "Reduced Row Echelon Form" << endl;
- display( );
- cout << endl << endl << endl;
- cout << "RESULT" << endl;
- for (int i = 0; i < vars; i++)
- cout << "X" << i + 1 << " = " << M[i][vars] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement