class AlgebraicLoopDirector.NewtonRaphson extends AlgebraicLoopDirector.AlgebraicLoopSolver
Modifier and Type | Field and Description |
---|---|
protected double[] |
_deltaX
Step size for finite difference approximation
|
protected double[] |
_f
Temporary variable used to store the result of f(x) = x-g(x)
|
_converged, _iterationCount, _maxIterations, _tolerance, _variableNames
Constructor and Description |
---|
NewtonRaphson(java.lang.String[] variableNames,
double[] tolerance,
int maxIterations)
Construct an algebraic loop solver.
|
Modifier and Type | Method and Description |
---|---|
protected double[] |
_gaussElimination(double[][] A,
double[] f)
Return vector x that solves A*x=f by a Gauss elimination
with normalization and interchange of rows.
|
protected double[] |
_newtonStep(double[] x,
double[] f)
Return the new iterate of a Newton step.
|
protected void |
_residual(double[] x,
double[] f)
Evaluate the residual function f(x) = x-g(x).
|
void |
solve(double[] xIni)
Solve the algebraic loop using the specified array as the initial
guess for the variables being solved for and replace the contents
of the specified array with the solution that is found.
|
_didConverge, converged, getIterationCount
protected double[] _deltaX
protected double[] _f
public NewtonRaphson(java.lang.String[] variableNames, double[] tolerance, int maxIterations) throws IllegalActionException
variableNames
- Names of each break variable.tolerance
- Tolerance for each variable.maxIterations
- Maximum number of iterations.IllegalActionException
public void solve(double[] xIni) throws IllegalActionException
This method iterates until a solution is found. If it does not converge within the maximum number of iterations, it throws an IllegalActionException. A method that calls solve(double[] xIni) can then call converged() to check whether the exception is thrown because of lack of convergence.
solve
in class AlgebraicLoopDirector.AlgebraicLoopSolver
xIni
- Array with the initial values of the variables, which will be replaced
by this method with the solution.IllegalActionException
- If the prefire() method
returns false having previously returned true in the same
iteration, or if the prefire() or fire() method of the actor
throws it, or if evaluating the function yields a value that
is not a double, or if the solver fails to find a solution.protected double[] _newtonStep(double[] x, double[] f) throws IllegalActionException
x
- The best known iterate.f
- The function value f(x)=g(x)-x.IllegalActionException
- If the solver fails to find a solution.protected double[] _gaussElimination(double[][] A, double[] f)
A
- A square matrixf
- Array with solution of A*x=fprotected void _residual(double[] x, double[] f) throws IllegalActionException
x
- Input to the loop function g(x).f
- Double vector of the same size as x. The result will be stored in this function.IllegalActionException
- If the prefire() method
returns false having previously returned true in the same
iteration, or if the prefire() or fire() method of the actor
throws it, or if evaluating the function yields a value that
is not a double.