IGLib
1.7.2
The IGLib base library EXTENDED - with other lilbraries and applications.
|
Base class for single variable nonlinear exuation solvers. More...
Public Member Functions | |
ZeroFinderBase (IRealFunction function, double toleranceFunctionValue, int maxIterations, double maxStepSize, double numericalDifferentiationStep) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (IRealFunction function, double initialGuess, double toleranceFunctionValue, int maxIterations, double maxStepSize, double numericalDifferentiationStep) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (IRealFunction function, double initialGuess, double toleranceFunctionValue, int maxIterations) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (IRealFunction function) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (DlgFunctionValue function, DlgFunctionValue functionDerivative, double toleranceFunctionValue, int maxIterations, double maxStepSize, double numericalDifferentiationStep) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (DlgFunctionValue function, DlgFunctionValue functionDerivative, double initialGuess, double toleranceFunctionValue, int maxIterations, double maxStepSize, double numericalDifferentiationStep) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (DlgFunctionValue function, DlgFunctionValue functionDerivative, double initialGuess, double toleranceFunctionValue, int maxIterations) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (DlgFunctionValue function, DlgFunctionValue functionDerivative) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
ZeroFinderBase (DlgFunctionValue function) | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
void | SetFunction (DlgFunctionValue valueDelegate, DlgFunctionValue derivativeDelegate) |
Sets definition of the function whose zeros are searched for. More... | |
virtual double | FunctionValue (double x) |
calculates and returns value of the function whose zeros are searched for at the specified value of independent variable. More... | |
virtual double | FunctionDerivative (double x) |
calculates and returns derivative of the function whose zeros are searched for at the specified value of independent variable. More... | |
virtual double | NumericalFunctionDerivative (double x) |
Calculates and returns numerical derivative of the function whose zero is searched for. More... | |
abstract void | Solve () |
Tries to find problem solution according to settings and solution data. More... | |
Static Public Member Functions | |
static void | ExampleNewton () |
Example where a nonlinear equation equation is solved by a solver class for finding zeros of a function by the Newton's method. More... | |
static void | ExampleNewton (DlgFunctionValue function, DlgFunctionValue functionDerivative) |
Example where a nonlinear equation equation is solved by a solver class for finding zeros of a function by the Newton's method. More... | |
static double | ExampleFunction (double x) |
Example function whose zero is searched for in the example. More... | |
static double | ExampleFunctionDerivative (double x) |
Derivative of the example function whose zero is searched for in the example. More... | |
Protected Member Functions | |
virtual void | ResetSolutionData () |
Resets output data that contains information about the solution and solution procedure. More... | |
virtual void | ResetProblemDependentData () |
Resets data that is not valid any more when problem changes. More... | |
virtual void | ResetSolutionAndProblemDependentData () |
Resets the following data: More... | |
Protected Attributes | |
int | _outputLevel = DefaultOutputLevel |
int | _maxIterations = DefaultMaxIterations |
double | _toleranceFunctionValue = DefaultToleranceFunctionValue |
double | _initialGuess = DefaultInitialGuess |
double | _maxStepSize = DefaultMaxStepSize |
double | _stepReductionFactor = DefaultStepReductionFactor |
int | _maxStepReductions = DefaultMaxStepReductions |
double | _numericalDifferentiationStep = DefaultNumericalDifferentiationStep |
IRealFunction | _function |
int | _numIterations = 0 |
int | _numFunctionEvaluations = 0 |
int | _numDerivativeEvaluations = 0 |
double | _solution = double.NaN |
double | _functionValueInSolution = double.NaN |
bool | _isSolutionObtained = false |
bool | _recordLastFunctionValue = true |
double | _lastFunctionArgument = double.NaN |
Static Protected Attributes | |
static int | _defaultOutputLevel = 0 |
static int | _defaultMaxiIterations = 1000 |
static double | _defaultInitialGuess = 0 |
static double | _defaultToleranceFunctionValue = 1.0e-6 |
static double | _defaultMaxStepSize = double.MaxValue |
static double | _defaultStepReductionFactor = 4.0 |
static int | _defaultMaxStepReductions = 20 |
static double | _defaultNumericalDifferentiationStep = 1.0e-4 |
Properties | |
static int | DefaultOutputLevel [get, set] |
Default output level for nonlinear equation solvers. More... | |
static int | DefaultMaxIterations [get, set] |
Default value for the maximal number of iterations. More... | |
static double | DefaultInitialGuess [get, set] |
Default value for the initial guess in solvers for finding zeros of nonlinear functions. More... | |
static double | DefaultToleranceFunctionValue [get, set] |
Default tolerance on absolute value of the function in solution. More... | |
static double | DefaultMaxStepSize [get, set] |
Default value for maximal step size. More... | |
static double | DefaultStepReductionFactor [get, set] |
Default value for step reduction factor. More... | |
static int | DefaultMaxStepReductions [get, set] |
Default value for maximal number of step reductions. More... | |
static double | DefaultNumericalDifferentiationStep [get, set] |
Default value for the step size for numerical differentiation. More... | |
virtual int | OutputLevel [get, set] |
Level of console output for nonlinear equation solvers. More... | |
virtual int | MaxIterations [get, set] |
Maximal number of iterations. More... | |
virtual double | ToleranceFunctionValue [get, set] |
Tolerance on absolute value of the function in solution. More... | |
double | InitialGuess [get, set] |
Initial guess for finding function zero. More... | |
virtual double | MaxStepSize [get, set] |
Default value maximal step size. More... | |
virtual double | StepReductionFactor [get, set] |
Step reduction factor. More... | |
virtual int | MaxStepReductions [get, set] |
Maximal number of step reductions. More... | |
virtual double | NumericalDifferentiationStep [get, set] |
Step size for numerical differentiation. More... | |
IRealFunction | Function [get, set] |
virtual int | NumIterations [get, protected set] |
Number of iterations performed up to the current point. More... | |
virtual int | NumFunctionEvaluations [get, protected set] |
Number of function evaluations performed by the solution algorithm up to the current point. More... | |
virtual int | NumDerivativeEvaluations [get, protected set] |
Number of function derivative evaluations performed by the solution algorithm up to the current point. More... | |
virtual double | Solution [get, protected set] |
Calculated solution of the problem (i.e. zero of the function whose value is calculated by the FunctionValue method). More... | |
double | FunctionValueInSolution [get, protected set] |
Value of the function whose zero is searched for in the calculated approximate solution. More... | |
bool | IsSolutionObtained [get, protected set] |
Flag specifying whether the problem has been successfully solved. More... | |
Private Member Functions | |
ZeroFinderBase () | |
Constructs a new solver for finding zeros of nonlinear functions. More... | |
Private Attributes | |
double | _lastFunctionValue = double.NaN |
Base class for single variable nonlinear exuation solvers.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. May also contain method for derivative calculation. |
maxIterations | Maximal number of iteratioins. |
If less or equal to 0 then the default value is taken.
maxStepSize | Maximal step size. |
If less or equal to 0 then default value is taken.
numericalDifferentiationStep | Step size for numerical differentiation (when used internally). |
If less or equal to 0 then the default value is used.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. May also contain method for derivative calculation. |
initialGuess | Initial guess. |
toleranceFunctionValue | Tolerance on absolute function value in solution. |
If less or equal to 0 then the default value is taken.
maxIterations | Maximal number of iteratioins. |
If less or equal to 0 then the default value is taken.
maxStepSize | Maximal step size. |
If less or equal to 0 then default value is taken.
numericalDifferentiationStep | Step size for numerical differentiation (when used internally). |
If less or equal to 0 then the default value is used.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. May also contain method for derivative calculation. |
initialGuess | Initial guess. |
toleranceFunctionValue | Tolerance on absolute function value in solution. |
If less or equal to 0 then the default value is taken.
maxIterations | Maximal number of iteratioins. |
If less or equal to 0 then the default value is taken.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. |
|
inlineprivate |
Constructs a new solver for finding zeros of nonlinear functions.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. |
functionDerivative | Derivative of the function whose zeros are searched for. |
If null then derivatives will be calculated by numerical differentiation when necessary.
toleranceFunctionValue | Tolerance on absolute function value in solution. |
If less or equal to 0 then the default value is taken.
maxIterations | Maximal number of iteratioins. |
If less or equal to 0 then the default value is taken.
maxStepSize | Maximal step size. |
If less or equal to 0 then default value is taken.
numericalDifferentiationStep | Step size for numerical differentiation (when used internally). |
If less or equal to 0 then the default value is used.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. |
functionDerivative | Derivative of the function whose zeros are searched for. |
If null then derivatives will be calculated by numerical differentiation when necessary.
initialGuess | Initial guess. |
toleranceFunctionValue | Tolerance on absolute function value in solution. |
If less or equal to 0 then the default value is taken.
maxIterations | Maximal number of iteratioins. |
If less or equal to 0 then the default value is taken.
maxStepSize | Maximal step size. |
If less or equal to 0 then default value is taken.
numericalDifferentiationStep | Step size for numerical differentiation (when used internally). |
If less or equal to 0 then the default value is used.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. |
functionDerivative | Derivative of the function whose zeros are searched for. |
If null then derivatives will be calculated by numerical differentiation when necessary.
initialGuess | Initial guess. |
toleranceFunctionValue | Tolerance on absolute function value in solution. |
If less or equal to 0 then the default value is taken.
maxIterations | Maximal number of iteratioins. |
If less or equal to 0 then the default value is taken.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
function | Function whose zeros are searched for. |
functionDerivative | Derivative of the function whose zeros are searched for. |
If null then derivatives will be calculated by numerical differentiation when necessary.
|
inline |
Constructs a new solver for finding zeros of nonlinear functions.
Since function for calculation of function derivatives is not set, derivatives will be calculated numerically if needed.
function | Function whose zeros are searched for. |
|
inline |
Sets definition of the function whose zeros are searched for.
valueDelegate | Delegate used for calculation of function values. |
derivativeDelegate | Delegate used for calculation of function derivatives. |
|
inlineprotectedvirtual |
Resets output data that contains information about the solution and solution procedure.
|
inlineprotectedvirtual |
Resets data that is not valid any more when problem changes.
|
inlineprotectedvirtual |
Resets the following data:
- output data that contains information about the solution and solution procedure
- data that is not valid any more when problem changes.
|
inlinevirtual |
calculates and returns value of the function whose zeros are searched for at the specified value of independent variable.
x | Argument of the function (value of independent variable) for which function value is returned. |
Delegate FunctionValueDelegate is used for calculation of function value.
Function remembers last evaluated values and stores them, which speeds up some operation such as evaluation of numerical derivatives. Last function argument is stored to the internal variable _lastFunctionArgument and function value at that argument is stored to the internal variable _lastFunctionValue. Before any function value is calculated, these variables have the value double.NaN. Fields are also reset to these values when definition of the function changes. Implementers of derived classes are responsible to restore this behavior if properties that interact with function definitions are overriden. If the _recordLastFunctionValue field is set to false then the last calculated value is not remembered. This is used e.g. in the NumericalFunctionDerivative method for calculation of numerical derivatives to switch off recording of the last function value when function is evaluated at perturbed parameters.
|
inlinevirtual |
calculates and returns derivative of the function whose zeros are searched for at the specified value of independent variable.
x | Argument of the function (value of independent variable) for which function derivative is returned. |
Delegate FunctionDerivativeDelegate is used for calculation of function value when it is defined (non-null).
If the derivative delegate (FunctionDerivativeDelegate) is not defined then function derivative is calculated numerically by the NumericalFunctionDerivative method.
|
inlinevirtual |
Calculates and returns numerical derivative of the function whose zero is searched for.
x | Function argumebnt at which numerical derivative is calculated. |
Property NumericalDifferentiationStep is used as step size for numerical differentiation.
This method uses the forward difference scheme for numerical differentiation.
|
pure virtual |
Tries to find problem solution according to settings and solution data.
This method must be overridden in derived classes.
Implemented in IG.Num.ZeroFinderNewton.
|
inlinestatic |
Example where a nonlinear equation equation is solved by a solver class for finding zeros of a function by the Newton's method.
Equation solved is defined by f(x) == 0, where the function f(x) is represented by the ExampleFunction method and its derivative by the ExampleFunctionDerivative method.
Class ZeroFinderNewton is used to solve the equation.
Referenced by IG.Script.AppTestShell.DevelopFunctionTestZeroFinderNewtonApp().
|
inlinestatic |
Example where a nonlinear equation equation is solved by a solver class for finding zeros of a function by the Newton's method.
function | Delegate used for calculation of values of the function whose zeros are searched for. |
functionDerivative | Delegate used for calculation of derivatives of the function whose zeros are searched for. |
Equation solved is defined by f(x) == 0, where the function f(x) is represented by the function delegate and its derivative by the functionDerivative delegate.
Class ZeroFinderNewton is used to solve the equation.
References IG.Num.ZeroFinderBase.FunctionValueInSolution, IG.Num.ZeroFinderBase.InitialGuess, IG.Num.ZeroFinderBase.IsSolutionObtained, IG.Num.ZeroFinderNewton.MaxIterations, IG.Num.ZeroFinderNewton.MaxStepSize, IG.Num.ZeroFinderBase.NumIterations, IG.Num.ZeroFinderBase.OutputLevel, IG.Num.ZeroFinderBase.Solution, IG.Num.ZeroFinderNewton.Solve(), and IG.Num.ZeroFinderBase.ToleranceFunctionValue.
|
inlinestatic |
Example function whose zero is searched for in the example.
f(x) = exp(x) - 10
Equation to be solved: exp(x) == 10
|
inlinestatic |
Derivative of the example function whose zero is searched for in the example.
f(x) = exp(x) - 10
f'(x) = exp(x)
Equation to be solved: exp(x) == 10
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
staticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
private |
|
staticgetset |
Default output level for nonlinear equation solvers.
Output level defines to which extent operation of the solver is logged to the console.
|
staticgetset |
Default value for the maximal number of iterations.
Must be greater or equal to 1.
|
staticgetset |
Default value for the initial guess in solvers for finding zeros of nonlinear functions.
|
staticgetset |
Default tolerance on absolute value of the function in solution.
Must be a positive value.
|
staticgetset |
Default value for maximal step size.
Must be greater than 0.
|
staticgetset |
Default value for step reduction factor.
Must be greater than one.
By this factor, step size is reduced (sometimes iteratively) if improvement in solution quality is not achieved.
|
staticgetset |
Default value for maximal number of step reductions.
Must be greater or equal to 0. 0 means that step reductions are not allowed.
In some algorithms, step size is reduced (sometimes iteratively) if improvement in solution quality is not achieved.
|
staticgetset |
Default value for the step size for numerical differentiation.
Must be greater than 0.
Numerical differentiation is sometimes used if the zero searching algorithm uses derivatives and function derivative is not explicitly specified.
|
getset |
Level of console output for nonlinear equation solvers.
Output level defines to which extent operation of the solver is logged to the console.
Should be greater or equal to 0, 0 means no output is generated on the application's console.
Default value is specified by the ZeroFinderBase.DefaultOutputLevel property.
Referenced by IG.Num.ZeroFinderBase.ExampleNewton().
|
getset |
Maximal number of iterations.
Must be greater or equal to 1.
Default value is defined by the ZeroFinderBase.DefaultMaxIterations property.
|
getset |
Tolerance on absolute value of the function in solution.
Must be a positive value.
Default value is defined by the ZeroFinderBase.DefaultToleranceFunctionValue property.
Referenced by IG.Num.ZeroFinderBase.ExampleNewton().
|
getset |
Initial guess for finding function zero.
Default value is defined by the ZeroFinderBase.DefaultInitialGuess property.
Referenced by IG.Num.ZeroFinderBase.ExampleNewton().
|
getset |
Default value maximal step size.
Must be greater than 0. Default value is specified by ZeroFinderBase.DefaultMaxStepSize.
With this value, step size during iterations is limited. This can be used as means of stabilization of the algorithm.
|
getset |
Step reduction factor.
Must be greater than one. Default value is ZeroFinderBase.DefaultStepReductionFactor.
By this factor, step size is reduced (sometimes iteratively) if improvement in solution quality is not achieved.
|
getset |
Maximal number of step reductions.
Must be greater or equal to 0. 0 means that step reductions are not allowed. Default value is ZeroFinderBase.DefaultMaxStepReductions.
In some algorithms, step size is reduced (sometimes iteratively) if improvement in solution quality is not achieved.
|
getset |
Step size for numerical differentiation.
Must be greater than 0.
Numerical differentiation is sometimes used if the zero searching algorithm uses derivatives and function derivative is not explicitly specified.
|
getset |
|
getprotected set |
Number of iterations performed up to the current point.
After the algorithm completes, this contains the total number of iterations.
Referenced by IG.Num.ZeroFinderBase.ExampleNewton().
|
getprotected set |
Number of function evaluations performed by the solution algorithm up to the current point.
After the algorithm completes, this contains the total number of function evaluations.
In the case that numerical differentiation is used, additional function evaluations that are used in numerical differentiation are counted in.
|
getprotected set |
Number of function derivative evaluations performed by the solution algorithm up to the current point.
After the algorithm completes, this contains the total number of derivative evaluations.
|
getprotected set |
Calculated solution of the problem (i.e. zero of the function whose value is calculated by the FunctionValue method).
Valid if IsSolutionObtained == true.
Referenced by IG.Num.ZeroFinderBase.ExampleNewton().
|
getprotected set |
Value of the function whose zero is searched for in the calculated approximate solution.
Valid if IsSolutionObtained == true.
Referenced by IG.Num.ZeroFinderBase.ExampleNewton().
|
getprotected set |
Flag specifying whether the problem has been successfully solved.
Value becomes true after the solution algorithm is successfully performed and yields a solution that is within the prescribed tolerances. Otherwise, the value is false.
Referenced by IG.Num.ZeroFinderBase.ExampleNewton().