Android Open Source - simple-matrix Rational Basic






From Project

Back to project page simple-matrix.

License

The source code is released under:

MIT License

If you think the Android project simple-matrix listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.alexkang.x3matrixcalculator.calculations;
/*from  w  w  w  .  java  2 s.  co m*/
public class RationalBasic {
  
  public static Rational[][] transpose(Rational[][] matrix) {
    Rational[][] result = new Rational[matrix.length][matrix[0].length];
    
    for (int i=0; i<matrix.length; i++) {
      for (int j=0; j<matrix[0].length; j++) {
        result[j][i] = matrix[i][j];
      }
    }
    
    return result;
  }
  
  public static Rational[][] add(Rational[][] matrix1, Rational[][] matrix2) {
    Rational[][] sum = new Rational[matrix1.length][matrix1[0].length];
    for (int i=0; i<sum.length; i++) {
      for (int j=0; j<sum[0].length; j++) {
      sum[i][j] = RationalCalc.addRat(matrix1[i][j], matrix2[i][j]);
      }
    }
    return sum;
  }
  
  public static Rational[][] sub(Rational[][] matrix1, Rational[][] matrix2) {
    for (int i=0; i<matrix2.length; i++) {
      for (int j=0; j<matrix2[0].length; j++) {
        matrix2[i][j] = RationalCalc.mulRat(new Rational(-1), matrix2[i][j]);
      }
    }
    return add(matrix1, matrix2);
  }
  
  public static Rational[][] mul(Rational[][] matrix1, Rational[][] matrix2) {
    Rational[][] product = new Rational[matrix1.length][matrix2[0].length];
    
    for (int i=0; i<matrix1.length; i++) {
      for (int j=0; j<matrix2[0].length; j++) {
        Rational element = new Rational(0);
        for (int k=0; k<matrix1[0].length; k++) {
          element = RationalCalc.addRat(element, 
              RationalCalc.mulRat(matrix1[i][k], matrix2[k][j])
              );
        }
        product[i][j] = element;
      }
    }
    
    return product;
  }
}




Java Source Code List

com.alexkang.x3matrixcalculator.DisplayResultActivity.java
com.alexkang.x3matrixcalculator.MainActivity.java
com.alexkang.x3matrixcalculator.MatrixRational.java
com.alexkang.x3matrixcalculator.Matrix.java
com.alexkang.x3matrixcalculator.SettingsActivity.java
com.alexkang.x3matrixcalculator.calculations.Advanced.java
com.alexkang.x3matrixcalculator.calculations.Basic.java
com.alexkang.x3matrixcalculator.calculations.RationalAdvanced.java
com.alexkang.x3matrixcalculator.calculations.RationalBasic.java
com.alexkang.x3matrixcalculator.calculations.RationalCalc.java
com.alexkang.x3matrixcalculator.calculations.Rational.java