-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.java
More file actions
119 lines (104 loc) · 3.1 KB
/
Copy pathMatrix.java
File metadata and controls
119 lines (104 loc) · 3.1 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
112
113
114
115
116
117
118
119
public class Matrix implements Operand
{
private Integer columns;
private Integer rows;
private Vector[] rowVectors;
public Matrix(){}
public Matrix(Double[][] matrix )
{
this.rows = matrix.length;
this.columns = matrix[0].length;
this.rowVectors = new Vector[this.rows];
for( int i = 0 ; i < this.rows ; i++)
{
this.rowVectors[i] = new Vector(matrix[i]);
}
}
public Matrix( String matrixString )
{
String[] vectorStrings = matrixString.split(":");
this.rows = vectorStrings.length;
this.rowVectors = new Vector[this.rows];
for(int i = 0; i < vectorStrings.length ; i++)
{
this.rowVectors[i] = new Vector(vectorStrings[i]);
}
this.columns = Integer.parseInt(this.rowVectors[0].getSize());
}
public Matrix( Vector[] rowVectors )
{
this.rowVectors = rowVectors;
this.rows = rowVectors.length;
this.columns = Integer.parseInt(rowVectors[0].getSize());
}
public Matrix getMinorMatrix( int row, int column )
{
Double[this.row-1][this.column-1] minor = new Double[][];
for(int i = 0 ; i < this.row ; i++ )
{
if (i == row ) continue;
for(int j = 0 ; j < this.columns ; j++)
{
if(j == column ) continue;
minor[i][j] = this.rowVectors[j].getComponent(i);
}
}
return minor;
}
public Vector getRowVectors(int element )
{
return this.rowVectors[element];
}
public Vector getColumnVectors(int element )
{
Double[] columnValues = new Double[this.rows];
for( int i = 0 ; i < columnValues.length ; i++ )
{
columnValues[i] = this.rowVectors[i].getComponent(element);
}
return new Vector(columnValues);
}
public int getNumberOfRows()
{
return this.rowVectors.length;
}
public int getNumberOfColumns()
{
return Integer.parseInt( this.rowVectors[0].getSize() );
}
public boolean isSquareMatrix()
{
Boolean returnBoolean = false;
if( this.rows == this.columns )
returnBoolean = true;
return returnBoolean;
}
public Double[][] matrixToArray()
{
Double[][] matrix = new Double[this.rows][this.columns];
for(int i = 0 ; i < this.rows ; i++ )
{
for( int j = 0 ; j < this.columns ; j++)
{
matrix[i][j] = this.rowVectors[i].getComponent(j);
}
}
return matrix;
}
@Override
public String getSize()
{
String returnString = this.columns + " x " + this.rows;
if( this.isSquareMatrix() )
returnString = Integer.toString( this.rows );
return returnString;
}
@Override
public void print()
{
for (int i = 0; i < this.rows ; i++)
{
this.rowVectors[i].print();
}
}
}