Advertisement
Guest User

Multiply

a guest
Mar 29th, 2015
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. public FractionMatrix multiply(FractionMatrix that)
  2.     {
  3.         Fraction sum = new Fraction( 0, 1 );
  4.         if (this.numberColumns() != that.numberRows())
  5.             throw new MatrixException("incompatible matrix dimensions");
  6.         Fraction[][] product = new Fraction[this.numberRows()][that.numberColumns()];
  7.         int constant = this.numberRows();
  8.         for (int row = 0; row < this.numberRows(); row++)
  9.         {
  10.             for (int col = 0; col < that.numberColumns(); col++)
  11.             {
  12.                 for( int a = 0; a <= constant; a++ )
  13.                 {
  14.                         sum = sum.add( this.get( row, a ).multiply( that.get( a, col ) ) );
  15.                         System.out.println( sum );
  16.                 }
  17.                 product[row][col] = sum;
  18.                 sum = new Fraction( 0 , 1 );
  19.             }
  20.         }
  21.         return new FractionMatrix( product );
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement