Advertisement
Guest User

Untitled

a guest
Mar 28th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.00 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.         FractionMatrix tempProduct = new FractionMatrix( product );
  8.         for (int row = 0; row < tempProduct.numberRows(); row++)
  9.         {
  10.             for (int col = 0; col < tempProduct.numberColumns(); col++)
  11.             {
  12.                 for( int a = 0; a < this.numberRows(); a++ )
  13.                 {
  14.                     for( int b = 0; b < that.numberColumns(); b++ )
  15.                     {
  16.                         sum = sum.add( this.get( a, b ).multiply( that.get( b, a ) ) );
  17.                     }
  18.                 }
  19.                 product[row][col] = sum;
  20.                 sum = new Fraction( 0 , 1 );
  21.             }
  22.         }
  23.         return new FractionMatrix( product );
  24.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement