All pastes #483445 Raw Edit

Miscellany

public java v1 · immutable
·published 2007-05-11 19:02 UTC
rendered paste body
	public static Fraction det( Fraction m[][] )	{		int countSwap = 0;		for( int i = 0; i < m.length; i++ )		{			if( m[i][i].equals( 0 ) )				for( int j = i + 1; j < m[i].length; j++ )					if( !m[j][i].equals( 0 ) )					{						m = swapLine( j, i, m );						countSwap++;						break;					}			for( int j = i; j < m.length; j++ )			{		 		if( i != j )				{					Fraction addFra = m[i][i].inv( ).mult( new Fraction( -1 ) ).mult( m[j][i] );					if( addFra.getDenominator( ) == 0 )						return null;					m = addLine( i, j, addFra, m );				}			}		}		Fraction ret = new Fraction( 1 );		for( int k = 0; k < m.length; k++ )			ret = ret.mult( m[k][k] );		if( countSwap % 2 != 0 )			ret = ret.mult( new Fraction( -1 ) );		return ret;	}