## Thursday, December 06, 2007

### Root-Finders in TK Solver

Here is a summary of the root-finders available in TK Solver, including their strengths and weaknesses. My goal is to help you choose the right tool for the task at hand. If you're just solving a problem once and need a quick solution, the built-in Iterative Solver is the best tool but if you're creating an application for repeated use, some other tools from the TK Library will be valuable.

Iterative Solver
The Iterative Solver uses a modified Newton-Raphson approach. It requires an initial guess. It cannot be bounded or controlled once engaged. It runs the entire model repeatedly until the solution is found or the processes diverges. It cannot be used on a subset of a model, such as within a procedure function loop. The initial guesses are programmable within TK. It can be run repeatedly at each element of a list solve.

Optimizer
The Optimizer uses a variety of methods. It is a close cousin to the Excel Solver add-in. It requires a Premium license. It uses the initial value as its guess. This initial value is not programmable within TK. It accepts bounds which may be functions of other variables. It runs the entire model repeatedly until the solution is found or the processes diverges. It cannot be used on a subset of a model, such as within a procedure function loop. It cannot be run repeatedly at each element of a list solve.

TK Library Functions
TK Library functions can be merged into models to solve subsets of equations such as within procedure loops. These complement the Iterative Solver and Optimizer.

Here is a listing of the root-finders in the TK Library.

The first batch process polynomial coefficients and return the roots.
cubicg - solves cubic equations in general form
cubicnr - solves cubic equations in normal or reduced form
quartic - solves quartic equations for real and complex roots
Bairstow - solves polynomial equations for real and complex roots

The next group require that an error term be generated and returned by a function. For example, to solve the equation
Y = X*LN(X) + 20*X
for Y = 5, iteration would be required to find the value of X. Both the Iterative Solver and Optimizer could be used but what if Y will vary within a procedure function loop and solutions are required for each Y? Create a rule function with the following equation
Y = X*LN(X) + 20*X + ERROR
Make X the "argument" variable and ERROR the "result" variable. The value of Y will be passed in as a list element as it changes during the procedure loop. For example, the first element of a list called Ytemp could be used to store and retrieve the temporary value.
Y = 'Ytemp
Now TK Library functions such as NewtonN can be used to determine the value of X that makes ERROR close to 0.

bisect - finds the point at which the sign of the error changes; Note that this may not be a root of the equation but could also be a point where the equation becomes undefined.
mbisect - finds a series of solutions within a range of values
refal - regula falsi (false position) method; Similar to bisect in that it searches for a sign change in the error and may return a root or a point where the equation becomes undefined
NewtonS - Newton's method, assuming that an equation for the derivative is known and available
NewtonN - Newton's method, with numeric differentiation
Newton2 - Newton's method with numeric differentation; functions of 2 unknowns
Newton3 - Newton's method with numeric differentation; functions of 3 unknowns
Newton4 - Newton's method with numeric differentation; functions of 4 unknowns
Newton5 - Newton's method with numeric differentation; functions of 5 unknowns
Newtonm - Newton's method with numeric differentation; functions of m unknowns; uses lists instead of variables to allow for an arbitrary number of unknowns.

Labels: ,