Iteration algorithm

The equation f(x) = g(x)

can be formulated as f(x) - g(x) = 0

Hence the general task to determine conditions of equality of 2 functions for a value x is reduced to finding the roots of one equation, where its value is zero. If g(x) is a number q, the task is to find a value x for which f(x) has the value q.

Logically the task presents the inversion of the simple task to calculate the value of f(x) for a given x. Yet an analytic solution is possible only for very simple functions, as a linear or a second order parabola. With trigonometric functions or logarithms, in classical technique, we use tables of corresponding numbers, without normally asking how they originated.

Numerically the roots of any function can be calculated by iteration up to every wanted, finite degree of accuracy. Instead of looking for an inverting calculus, we simply calculate "forward". We take an initial arbitrary value of x and calculate y = f(x). In general y will not be zero, and hence x will not be a root. Now we vary x systematically (iterate x) until y becomes smaller than a desired accuracy delta.

For easy understanding and demonstration this simulation uses a very simple iteration algorithm in form of a calculating loop. In each step of the loop the following commands are performed (you will find the code at the Evolution page of the EJS model);

d x = 0.1/n; defines the step width in dependence on a step variable n

x = x + dx; goes one step further

the corresponding y- value is calculated with the given formula for f(x) (Fixed Relations page)

if (y>0) ( it is assumed that initially y<0, with changing sign (y>0) a root has been crossed) {

x = x - 2*dx; jump back to last point

n=10*n; reduce step by factor 10

}

if (Math.abs(y)<2*delta) when y is sufficiently small {

_pause(); -stop calculation

}

While this algorithm is very simple and easy to understand, it needs many steps. One can speed it up considerably using variable step widths, that adjust themselves to the steepness of the curve or even to its curvature. In the zoom window one recognizes that the function can quickly be approximated well by a linear. The root of a linear determined by 2 consecutive points of the iteration or even of a parabola determined by 3 of them, will be very close to the root of the curve itself after just one more step of iteration. The linear approximation is used in the so called Newton algorithm.

With the availability of fast PCs the time needed for iteration algorithms is so minute that one can use them universally. Standard programs like Excel or Mathematica offer ready solutions.

Our simple algorithm is easily extended to calculate all roots in a given interval in one run. An additional if- else- logic condition is sufficient to adjust the flyback command to the 2 cases of the initial y value being positive or negative.

if (y0<0) {

dx = 0.1/n;

x = x + dx;

if (y > 0) {

x = x - 2*dx;

n = 10*n;

}}

else {

dx = 0.1/n;

x = x + dx;

if (y < 0) {

x = x - 2*dx;

n =10*n;

}}

As the formula field is editable, one can determine roots for any arbitrary function.