Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public FractionMatrix multiply(FractionMatrix that)
- {
- Fraction sum = new Fraction( 0, 1 );
- if (this.numberColumns() != that.numberRows())
- throw new MatrixException("incompatible matrix dimensions");
- Fraction[][] product = new Fraction[this.numberRows()][that.numberColumns()];
- FractionMatrix tempProduct = new FractionMatrix( product );
- for (int row = 0; row < tempProduct.numberRows(); row++)
- {
- for (int col = 0; col < tempProduct.numberColumns(); col++)
- {
- for( int a = 0; a < this.numberRows(); a++ )
- {
- for( int b = 0; b < that.numberColumns(); b++ )
- {
- sum = sum.add( this.get( a, b ).multiply( that.get( b, a ) ) );
- }
- }
- product[row][col] = sum;
- sum = new Fraction( 0 , 1 );
- }
- }
- return new FractionMatrix( product );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement