1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

Roots of equations by interpolation.
A sample call is: INTERPOLATE(SIN(X)X/2,X,.1,%PI);
This finds the zero of SIN(X)X/2 as X varies. The last two args give the
range to look in. The function must have a different sign at each endpoint.
If this condition is not met, the action of the of the function is governed
by INTPOLERROR (default value TRUE). If INTPOLERROR is TRUE then an error
occurs, otherwise the value of INTPOLERROR is returned (thus for plotting
INTPOLERROR might be set to 0.0). Otherwise (given that MACSYMA can
evaluate the first argument in the specified range, and that it is
continuous) interpolate is guaranteed to come up with the zero (or one of
them if there is more than one zero).
The accuracy of INTERPOLATE is governed by INTPOLABS and INTPOLREL which must
be nonnegative floating point numbers. INTERPOLATE will stop when the
first arg evaluates to something less than or equal to INTPOLABS or is
successive approximants to the root differ by no more than INTPOLREL *
<one of the approximants>. The defaults values of INTPOLABS and INTPOLREL
are 0.0 so INTERPOLATE gets as good an answer as is possible with the single
precision arithmetic we have. The first arg may be an equation. The order
of the last two args is irrelevant. Thus
INTERPOLATE(SIN(X)=X/2,X,%PI,.1);
would also work.
The method used is a binary search in the range specified by the last two
args. When it thinks the function is close enough to being linear, it
starts using linear interpolation.
========
ADDENDUM
========
An alternative syntax has been added to interpolate, this replaces the first
two arguments by a function name.
e.g.
F(X):=(MODEDECLARE(X,FLOAT),SIN(X)X/2.0);
INTERPOLATE(SIN(X)X/2,X,0.1,%PI) TIME= 60 MSEC
INTERPOLATE(F(X),X,0.1,%PI); TIME= 68 MSEC
INTERPOLATE(F,0.1,%PI); TIME= 60 MSEC
TRANSLATE(F);
INTERPOLATE(F(X),X,0.1,%PI); TIME= 26 MSEC
INTERPOLATE(F,0.1,%PI); TIME= 5 MSEC
For further improvement one can COMPILE(), which creates a LISP
and FASL file of functions which are then loaded into macsyma. See
the documentation on COMPILE.
Comments, questions etc. to CFFK@MC
