-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathReduce_Row_Echelon_Form.java
More file actions
111 lines (104 loc) · 2.44 KB
/
Copy pathReduce_Row_Echelon_Form.java
File metadata and controls
111 lines (104 loc) · 2.44 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
//REDUCE ROW ECHELON FORM CODE WRITTEN BY Deep_Jani
//REDUCE ROW ECHELON FORM CODE WRITTEN BY Deep_Jani
import java.util.Scanner;
public class Reduce_row_echelon_form2
{
public static double[][] rref(double[][] m,int x,int y)
{
double[][] rref = new double[x][y];
int flag;
double temp2;
//LOOP FOR COPYING MATRIX
for (int r = 0; r < x; r++)
{
for (int c = 0; c < y; c++)
{
rref[r][c] = m[r][c];
}
}
//LOOP FOR ZERO ROWS TO BOTTOM
for (int r = 0; r < x-1; r++)
{
flag=0;
for (int c = 0; c < y; c++)
{
if(rref[r][c]==0) {flag++;}
}
if(flag==y)
{
for(int j = 0; j < y; j++)
{
temp2=rref[r][j];
rref[r][j]=rref[r+1][j];
rref[r+1][j]=temp2;
}
}
}
for (int p = 0; p < x; p++)
{
//FOR GETTING PIVOT
if(p >= y)break;
double pv = rref[p][p];
if (pv != 0)
{
for (int i = 0; i < y; i++)
{
rref[p][i] = rref[p][i] / pv;
}
}
//FOR MAKING ZEROES UNDER PIVOT
for (int r = 0; r < x; r++)
{
if (r != p)
{
double temp = rref[r][p];
for (int i = 0; i < y; i++)
{
rref[r][i] = rref[r][i] - temp * rref[p][i];
}
}
}
}
return rref;
}
public static void main(String[] args)
{
Scanner dj = new Scanner(System.in);
System.out.println("ENTER THE NO. OF ROWS : ");
int m = dj.nextInt();
System.out.println("ENTER THE NO. OF COLUMNS : ");
int n = dj.nextInt();
double[][] a = new double[m][n];
System.out.println("ENTER THE ELEMENTS of ARRAY : ");
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
a[i][j] = dj.nextDouble();
}
}
double[][] b = new double[m][n];
b = rref(a,m,n);
b = rref(b,m,n);
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
System.out.printf(a[i][j]+" " );
}
System.out.println("/n");
}
System.out.println("/n");
System.out.println("/n");
System.out.println("/n");
System.out.println("/n");
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
System.out.printf(b[i][j]+" " );
}
System.out.println("/n");
}
}
}