예제 #1
0
  public Matrix matrixAccuralize() { // 精确化矩阵
    int i, j;
    Matrix matrix = new Matrix(this);

    for (i = 0; i < matrix.getLine(); i++)
      for (j = 0; j < matrix.getRow(); j++)
        if (Math.abs(matrix.getElement(i, j)) <= matrix.getAccuracy()) matrix.setElement(i, j, 0.0);
    return matrix;
  }
예제 #2
0
  public static void matrixToPanel(JTextField[] jtfMatrix, Matrix matrix) {
    int i, j;
    DecimalFormat df = new DecimalFormat(String.valueOf(matrix.getAccuracy()).replace('1', '0'));

    for (i = 0; i < matrix.getLine(); i++)
      for (j = 0; j < matrix.getRow(); j++) {
        jtfMatrix[i * matrix.getRow() + j].setText(
            String.valueOf(df.format(matrix.getElement(i, j))));
      }
  }
예제 #3
0
  public static Matrix matrixMinus(Matrix matrix1, Matrix matrix2) { // 矩阵减法
    int i, j;
    Matrix matrix = new Matrix();

    for (i = 0; i < matrix1.getLine(); i++)
      for (j = 0; j < matrix1.getRow(); j++)
        matrix.setElement(i, j, matrix1.getElement(i, j) - matrix2.getElement(i, j));
    matrix.setLine(matrix1.getLine());
    matrix.setRow(matrix1.getRow());
    matrix.setAccuracy(matrix1.getAccuracy());
    return matrix;
  }
예제 #4
0
  public static Matrix matrixCopy(Matrix matrix) { // 矩阵复制
    int i, j;
    Matrix matrix_copy = new Matrix();

    matrix_copy.setLine(matrix.getLine());
    matrix_copy.setRow(matrix.getRow());
    matrix_copy.setAccuracy(matrix.getAccuracy());
    matrix_copy.setName(matrix.getName());
    for (i = 0; i < matrix.getLine(); i++)
      for (j = 0; j < matrix.getRow(); j++) matrix_copy.setMatrixArray(matrix.getMatrixArray());
    return matrix_copy;
  }
예제 #5
0
  public int matrixRank() // 矩阵的秩
      {
    int rank = 0, i, j;
    Matrix matrix = new Matrix();

    matrix = matrixLineSimplify();
    for (i = 0; i < matrix.getLine(); i++)
      for (j = 0; j < matrix.getRow(); j++)
        if (Math.abs(matrix.getElement(i, j)) > matrix.getAccuracy()) {
          rank++;
          break;
        }
    return rank;
  }
예제 #6
0
  public static Matrix matrixMultiply(Matrix matrix1, Matrix matrix2) { // 矩阵乘法
    int i, j, k;
    Matrix matrix = new Matrix();

    matrix.setLine(matrix1.getLine());
    matrix.setRow(matrix2.getRow());
    matrix.setAccuracy(matrix1.getAccuracy());
    for (i = 0; i < matrix.getLine(); i++)
      for (j = 0; j < matrix.getRow(); j++) matrix.setElement(i, j, 0.0);
    for (i = 0; i < matrix.getLine(); i++)
      for (j = 0; j < matrix.getRow(); j++)
        for (k = 0; k < matrix1.getRow(); k++)
          matrix.setElement(
              i, j, matrix.getElement(i, j) + matrix1.getElement(i, k) * matrix2.getElement(k, j));
    return matrix;
  }
예제 #7
0
 public Matrix(Matrix matrix) {
   this.matrixArray = Matrix.matrixArrayCopy(matrix.getMatrixArray());
   this.line = matrix.getLine();
   this.row = matrix.getRow();
   this.accuracy = matrix.getAccuracy();
 }