public void sort(SquaredMatrix a) { int[] temp = new int[3]; int[][] elements = a.getElements(); for (int i = 0; i < elements.GetLength(0) - 1; i++) { int j; j = 0; for (; j < elements.GetLength(0) - 1; j++) { if (elements[j][2] > elements[j + 1][2]) { //make a swap //put array record j into temp holder temp[0] = elements[j][0]; temp[1] = elements[j][1]; temp[2] = elements[j][2]; //copy j + 1 into j elements[j][0] = elements[j + 1][0]; elements[j][1] = elements[j + 1][1]; elements[j][2] = elements[j + 1][2]; //copy temp into j + 1 elements[j + 1][0] = temp[0]; elements[j + 1][1] = temp[1]; elements[j + 1][2] = temp[2]; } } } }
public void print(SquaredMatrix a) { for (int i = 0; i < a.getSize(); i++) { for (int j = 0; j < a.getSize(); j++) { //(a[i][j] + " "); } } }
public SquaredMatrix initMatrix(int sz) { SquaredMatrix squaredMatrix = new SquaredMatrix(sz); for (int i = 0; i < sz; i++) { for (int j = 0; j < sz; j++) { //("Please enter each element !"); } } this.squaredMatrix = squaredMatrix; return(this.squaredMatrix); }
public SquaredMatrix multiplyMatrix(SquaredMatrix b) { SquaredMatrix res = new SquaredMatrix(size); for (int i = 0; i < size; i++) { for (int j = 0; j < size; j++) { res.setElementAtIndexes(i, j, 0); for (int k = 0; k < size; k++) { int x = this.getElementAtIndexes(i, j) * b.getElementAtIndexes(i, j); res.setElementAtIndexes(i, j, x); } } } return(res); }
public LinearSystem(SquaredMatrix coe, Vector v) { if (coe.Size != v.Dimension) { throw (new ArgumentException()); } Vector[] vectors = new Vector[coe.Size + 1]; for (int i = 0; i < coe.Size; i++) { vectors[i] = coe.Cols[i]; } vectors[coe.Size] = v; this.LMatrix = new Matrix(vectors); this.size = this.LMatrix.Col - 1; }
public void GaussJordanAlgorithm_Caluclate_EqualsExpected() { var mat = new SquaredMatrix <Double, DoubleField>(2); mat[0, 0] = 2; mat[0, 1] = 3; mat[1, 0] = 4; mat[1, 1] = 4; var expected = new SquaredMatrix <Double, DoubleField>(3); expected[0, 0] = 1; expected[0, 1] = 0; expected[1, 0] = 1; expected[1, 1] = 0; var result = mat.GaussJordanAlgorithmNew(); }