[Home] Restricted access for guests. The link to Java source code is disabled
Java source code of 'hephysics.matrix.MatrixOp'
package hephysics.matrix;
import java.util.Formatter;
import java.lang.Math;
/**
* Simple operations on matrices
* @author tonyj
*/
public class MatrixOp
{
private MatrixOp()
{
}
/**
* Invert matrix mIn and write it to matrix mOut.
* This method allows both arguments to be the same, e.g. inverse(this,this);
* This method currently only supports square matrices.
*/
public static void inverse(Matrix mIn, MutableMatrix mOut) throws InvalidMatrixException
{
int order = mIn.getNRows();
if (order != mIn.getNColumns()) throw new InvalidMatrixException("Matrix.inverse only supports square matrices");
if (order != mOut.getNColumns() && order != mOut.getNRows()) throw new InvalidMatrixException("mOut must be same size as mIn");
int[] ik = new int[order];
int[] jk = new int[order];
double[][] array = new double[order][order];
for (int i=0;i Math.abs(amax))
{
amax = array[i][j];
ik[k] = i;
jk[k] = j;
}
}
}
// Interchange rows and columns to put max in array[k][k]
if (amax == 0) throw new IndeterminateMatrixException();
{
int i = ik[k];
assert(k <= i);
if (i > k)
{
for (int j=0; j k)
{
for (int i=0; ik)
{
for (int i=0; ik)
{
for (int j=0; j=m.getNColumns()) break;
formatter.format(",");
}
if (++i>=m.getNRows()) break;
formatter.format("]\n ");
}
formatter.format("]");
return formatter.out().toString();
}
// ToDo: Clean up the code here cut and pasted from invert().
public static double det(Matrix mIn)
{
int order = mIn.getNRows();
if (order != mIn.getNColumns()) throw new InvalidMatrixException("Matrix.det only supports square matrices");
int[] ik = new int[order];
int[] jk = new int[order];
double[][] array = new double[order][order];
for (int i=0;i Math.abs(amax))
{
amax = array[i][j];
ik[k] = i;
jk[k] = j;
}
}
}
// Interchange rows and columns to put max in array[k][k]
if (amax == 0) return 0;
{
int i = ik[k];
assert (k <= i);
if (i > k)
{
for (int j=0; j k)
{
for (int i=0; itransposed(this,this);
* This method currently only supports square matrices.
*/
public static void transposed(Matrix mIn, MutableMatrix mOut)
{
int order = mIn.getNRows();
if (order != mIn.getNColumns()) throw new InvalidMatrixException("Matrix.transposed only supports square matrices");
if (order != mOut.getNColumns() && order != mOut.getNRows()) throw new InvalidMatrixException("mOut must be same size as mIn");
for (int i=0; i