## File: intpol.usg

package info (click to toggle)
maxima 5.6-17
 `123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051` `````` 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 non-negative 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 * . 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 ``````