Matrix help!

Hello,
I'm having a bit of a problem. I need to write a program that will read a matrix from text file, display the matrix, then reduce it to RREF and display the reduced matrix. I have part of the code that gets it to display the original matrix but I have no idea how to get it to RREF. Any help will be really appreciated. Thanks!!!

Here is the matrix

2 9 -1 3 0 81
1 2 2 0 -6 -23
5 7 2 -1 3 100
8 -1 -4 -2 9 71
3 3 8 1 9 178

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <fstream> //connects program to fstream
#include <iostream> //connects program to iostream
#include <cmath> //connects program to cmath
using namespace std; //ALlows programmer to use namespace

int rows, columns; //creates variables to hold numbers for matrix
int firstNum, num; //creates variables to solve problems in matrix

int main() //Main is the beginning of the actual program
{//Start Main

//This gets the number of rows and columns that you will need
cout << "How many unknowns? "<<endl; //Allows the user to input data into array
    cin >> rows; //adds in rows
	columns = rows + 1;
cout<<endl;
cout<<"Your matrix is "<<endl<<endl;
   
float Matrix[rows][columns]; //this creates the first matrix that the user inputs
float SolvedMatrix[rows][columns]; //this creates the solved matrix

//This puts data into the actual matrix
ifstream Infile; //allows programmer to use files
Infile.open("matrixdata.txt"); //opens file for reading
for (int i = 0; i < rows; i++) //start for rows
{//start for
   for (int n = 0; n < columns; n++) //start for columns
   {//start for
       Infile>>Matrix[i][n];
   }//end for
}//end for
Infile.close(); //closes the file
firstNum = Matrix[0][0]; //this finds the first number of the array

for (int i = 0; i < rows; i++) //this for loop displays the first matrix for the user
{//start for
   for (int n = 0; n < columns; n++)
   {//start for
       cout << Matrix[i][n] << " ";
   }//end for
   cout <<endl;
}//end for

cout << endl; //this puts a space inbetween the unsolved matrix and the solved matrix


//This solves the first row of the matrix
for (int i = 0; i < columns; i++)
{
   num = Matrix[0][i];
   SolvedMatrix[0][i] = num / firstNum; //this is the equation to solve the first line of the matrix
}

//This solves the next rows of the matrix
for (int i = 1; i < rows; i++)
{//start for
   for (int n = 0; n < columns; n++)
   {//start for
      firstNum = Matrix[i][0] * -1; //this makes the first number negative of each row
      num = Matrix[i][n]; //this finds the number being solved
      SolvedMatrix[i][n] = (num / firstNum) + SolvedMatrix[0][n]; //this is the equation to solve the matrix
   }//end for
}//end for


cout<<"The solved matrix is "<<endl<<endl;

//This displays the new Matrix
for (int i = 0; i < rows; i++)
{//start for
   for (int n = 0; n < columns; n++)
   {//start for
       cout << SolvedMatrix[i][n] << " ";
   }//end for
   cout << " " << endl;
}//end for

return 0; //Program returns nothing
}//End Main


I've managed to get this far, but I'm having a problem with getting the math correct. the most bottom right number should be a nine. Done on paper.
Last edited on
edited. any insight?
Topic archived. No new replies allowed.