net.aerith.misao.util
Class SimultaneousEquation

java.lang.Object
  |
  +--net.aerith.misao.util.SimultaneousEquation

public class SimultaneousEquation
extends java.lang.Object

The SimultaneousEquation represents a simultaneous equation. It has a function to solve the equation.

For example, in the case of the simultaneous equations:

     a x + b y + c = 0
     d x + e y + f = 0
 
the coefficient matrix will be set as:
     SimultaneousEquation se = new SimultaneousEquation(2);
     se.coef[0][0] = a;
     se.coef[0][1] = b;
     se.coef[0][2] = c;
     se.coef[1][0] = d;
     se.coef[1][1] = e;
     se.coef[1][2] = f;
 
and the answer will be obtained as:
     se.solve();
     x = se.getAnswer(0);
     y = se.getAnswer(1);
 

Note that this class does not support the case that a coefficient is 0.


Field Summary
 double[][] coef
          The coefficient matrix.
protected  int dimension
          The dimension of the equations, which is the number of variables, or the number of equations.
 
Constructor Summary
SimultaneousEquation(int dimension)
          Constructs a default SimultaneousEquation, with the number of equations.
 
Method Summary
 double getAnswer(int i)
          Gets the answer of i-th variable.
 void solve()
          Solves this simultaneous equation.
private  void solve(int k)
          Solves the specified equation in this simultaneous equation.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

coef

public double[][] coef
The coefficient matrix. The number of rows is dimension and the number of columns is dimension + 1. The right edge term of each equation i, coef[i][dimension], is a constant term.

dimension

protected int dimension
The dimension of the equations, which is the number of variables, or the number of equations.
Constructor Detail

SimultaneousEquation

public SimultaneousEquation(int dimension)
Constructs a default SimultaneousEquation, with the number of equations. All the values in the coefficient matrix are set as 0.
Parameters:
dimension - the number of equations.
Method Detail

getAnswer

public double getAnswer(int i)
Gets the answer of i-th variable. Before to invoke this method, the method solve must be invoked.
Parameters:
i - the index of variable to get the answer.

solve

public void solve()
Solves this simultaneous equation. The answer of the i-th equation will be in coef[i][i+1].

Note that this method does not support the case that a coefficient is 0.


solve

private void solve(int k)
Solves the specified equation in this simultaneous equation. This method is invoked recurrsively.
Parameters:
k - the index of equation to solve.