use of gov.sandia.n2a.language.EvaluationException in project n2a by frothga.
the class Matrix method determinant.
public double determinant() throws EvaluationException {
int w = columns();
int h = rows();
if (h != w)
throw new EvaluationException("Can't compute determinant of non-square matrix.");
if (h == 1)
return get(0, 0);
if (h == 2)
return get(0, 0) * get(1, 1) - get(1, 0) * get(0, 1);
if (h == 3) {
return get(0, 0) * get(1, 1) * get(2, 2) - get(0, 0) * get(1, 2) * get(2, 1) - get(0, 1) * get(1, 0) * get(2, 2) + get(0, 1) * get(1, 2) * get(2, 0) + get(0, 2) * get(1, 0) * get(2, 1) - get(0, 2) * get(1, 1) * get(2, 0);
}
throw new EvaluationException("Can't compute deteminant of matrices larger then 3x3 (because we are lazy).");
}
use of gov.sandia.n2a.language.EvaluationException in project n2a by frothga.
the class MatrixSparse method load.
public void load(Reader stream, boolean units) throws EvaluationException {
try (BufferedReader reader = new BufferedReader(stream)) {
// Throw away "Sparse" line
String line = reader.readLine();
while (true) {
line = reader.readLine();
if (line == null)
break;
line = line.trim();
String[] pieces = line.split(",");
if (pieces.length < 3)
continue;
int r = Integer.valueOf(pieces[0].trim());
int c = Integer.valueOf(pieces[1].trim());
double v = Double.valueOf(pieces[2].trim());
set(r, c, v);
}
} catch (IOException error) {
throw new EvaluationException("Failed to convert input to matrix");
}
}
Aggregations