0

here i have 2 files

and im getting a wrong echlon form of the matrix...please help;

Linear_Equation.java:

```
package mypack;
import java.io.*;
public class Linear_Equation{
public static void main(String args[])throws IOException{
int i,j;
matrix mat1=new matrix();
int mtx[][]=new int[3][4];
mat1.accept();
mat1.display();
mtx=mat1.echolonform();
System.out.println("\nThe answer is:");
for(i=0;i<3;i++)
{
System.out.println("\n");
for(j=0;j<4;j++)
System.out.print(" "+ mtx[i][j]);
}
}
}
```

classfile.java:

```
package mypack;
import java.io.*;
class matrix
{
int mat1[][]=new int[3][4];
void accept()throws IOException
{
int i,j,ch;
InputStreamReader instream = new InputStreamReader(System.in);
BufferedReader stdin = new BufferedReader(instream);
System.out.println("\nEnter the coefficients and the constants for the 3 equations ");
for(i=0;i<3;i++)
{
for(j=0;j<4;j++)
{
System.out.println("M["+i+"]["+j+"]=");
ch=Integer.parseInt(stdin.readLine());
mat1[i][j]=ch;
}
}
}
void display()
{
int i,j;
System.out.println("\nThe matrix is:\n");
for(i=0;i<3;i++)
{
System.out.println("\n");
for(j=0;j<4;j++)
System.out.print(" "+ mat1[i][j]);
}
}
int[][] echolonform()
{
int i=0,j,k,n;
for(i=0;i<3;i++)
{
int temp=mat1[i][i];
for(j=0;j<4;j++)
mat1[i][j]=mat1[i][j]/temp;
for(k=0;k<3;k++)
{
temp=mat1[k][i];
if(i!=k)
{
for(n=0;n<3;n++)
{
mat1[k][n]=mat1[k][n]-(temp*(mat1[i][n]));
}
}
}
}
return mat1;
}
}
```

the output is::

```
Enter the coefficients and the constants for the 3 equations
M[0][0]=
2
M[0][1]=
-3
M[0][2]=
1
M[0][3]=
1
M[1][0]=
1
M[1][1]=
2
M[1][2]=
1
M[1][3]=
-1
M[2][0]=
3
M[2][1]=
-1
M[2][2]=
3
M[2][3]=
4
The matrix is:
2 -3 1 1
1 2 1 -1
3 -1 3 4
The answer is:
1 0 0 0
0 1 0 0
0 0 1 1
```

the answer should be

```
1 0 0 -3
0 1 0 -1
0 0 1 4
```

please help!!

*Edited 3 Years Ago by mike_2000_17*: Fixed formatting