-
Notifications
You must be signed in to change notification settings - Fork 6
Solver
Rugen Heidbuchel edited this page Apr 30, 2015
·
3 revisions
The Solver class currently supports single variable function root finding. Several methods have been implemented, but the general solve method still has to be written.
Two constants define the basic behaviour of the Solver class:
-
SOLVER_ACCURACY
: defines the allowed error on the root, standard is 10^-7 -
SOLVER_MAX_TIME
: defines the allowed time for the solving, standard set on 10 seconds Both constants can be altered, so that the values don't have to be passed to every function call.
Uses a simple 'binary search' to reduce the interval iteratively. An interval needs to be given that holds the zero-point. The signs of the function-values of the outer points of the interval (a and b) have to be opposite.
parameters:
-
a: Double
: The beginpoint of the interval to start the search in. -
_ b: Double
: The endpoint of the interval to start the search in. -
accuracy err: Double? = nil
: The accuracy, this is standard set to SOLVER_ACCURACY. -
maxTime t_m: Double? = nil
: The allowed time for the solving, this is standard set to SOLVER_MAX_TIME. -
_ f: (Double) -> Double
: The function to find the root of.
Uses Newton's method.
parameters:
-
x0: Double
: The starting value for Newton's method. -
df: ((Double) -> Double)? = nil
: The derivative of the function. When this is nil, the derivative will be estimated. -
error err: Double? = nil
: The accuracy, this is standard set to SOLVER_ACCURACY. -
k_max: Int = 100
: The maximum number of iterations allowed to take. -
maxTime t_m: Double? = nil
: The allowed time for the solving, this is standard set to SOLVER_MAX_TIME. -
f: (Double) -> Double
: The function
- Implement general solve method.