A Review of the Approximations package

Ken Levasseur
Mathematical Sciences
UMass Lowell
Kenneth_Levasseur@uml.edu

Introduction

The Approximations  package provides a variety of functions for approximating functions by rational functions.

Needs["NumericalMath`Approximations`"]

Given a function f defined on an interval [a,b], the basic problem this addresses is that of finding a rational function  r(x) = p(x)/q(x), where p(x) and q(x) are polynomials with some specified maximal degrees, such that f and r are as close as possible in some sense.

In this review, we will approximate this function.  If you are reading a Mathematica Notebook, you can change the function to one you might prefer.

f[x_] := E^(- x)

Minimization of Relative Error

Here is how to approximate our function in the relative minimax sense.  First we approximate with polynomials of degree 2 or less.

r20 = MiniMaxApproximation[f[x], {x, {0, 1}, 2, 0}]

{{0., 0.30088, 0.792787, 1.}, {0.298557 x^2 - 0.923636 x + 0.994852, 0.00514761}}

The output has several parts.  The first part is the list of locations of relative maxima in the error.

r20[[1]]

{0., 0.30088, 0.792787, 1.}

The second part of the output has two parts.  The first is the approximating function itself.

r20[[2, 1]]

0.298557 x^2 - 0.923636 x + 0.994852

The second part of the second part is the maximum error

r20[[2, 2]]

0.00514761

Here is a plot of the error function

Plot[f[x] - r20[[2, 1]], {x, 0, 1}]

[Graphics:HTMLFiles/Approximations_13.gif]

-Graphics -

Here is an approximation by a rational function with degrees 1 and 2 for the numerator and denominator.

r12 = MiniMaxApproximation[f[x], {x, {0, 1}, 1, 2}]

{{0., 0.137649, 0.483257, 0.845839, 1.}, {(0.999892 - 0.284324 x)/(0.233414 x^2 + 0.711911 x + 1), 0.000108386}}

Notice that the error is considerably smaller in this case.

Plot[f[x] - r12[[2, 1]], {x, 0, 1}]

[Graphics:HTMLFiles/Approximations_18.gif]

-Graphics -

Minimization of Absolute Error

Minimization of absolute error is done with GeneralMiniMaxApproximation:

rg20 = GeneralMiniMaxApproximation[{t, f[t], 1}, {t, {0, 1}, 2, 0}, x]

General :: spell1 : Possible spelling error: new symbol name \" rg20 \" is similar to existing symbol \" r20 \".  More…

{{0., 0.234629, 0.734243, 1.}, {0.311236 x^2 - 0.936914 x + 0.996779, 0.00322116}}

Notice how the maximum error is attained at all four extremes of the error function.

Plot[f[x] - rg20[[2, 1]], {x, 0, 1}]

[Graphics:HTMLFiles/Approximations_24.gif]

-Graphics -

Other weight functions can be used in the third part of the first argument

rgw20 = GeneralMiniMaxApproximation[{t, f[t], E^(-3t)}, {t, {0, 1}, 2, 0}, x]

General :: spell1 : Possible spelling error: new symbol name \" rgw20 \" is similar to existing symbol \" rg20 \".  More…

{{0., 0.466976, 0.869907, 1.}, {0.273496 x^2 - 0.891949 x + 0.986981, 0.0130188}}

Plot[f[x] - rgw20[[2, 1]], {x, 0, 1}]

[Graphics:HTMLFiles/Approximations_30.gif]

-Graphics -

Not everything goes well

I haven't had a chance to experiment with the Brake option that is mentioned in the message below.

sinapprox = GeneralMiniMaxApproximation[{t, Sin[t], 1}, {t, {0, Pi}, 2, 0}, x]

{{0., 0.616531, 2.52506, 3.14159}, -0.427496 x^2 + 1.34302 x - 0.0548042, {0.0548042, -0.0325042, -0.0325042, 0.0548042}}

Plot[Sin[x] - sinapprox[[2]], {x, 0, Pi}]

[Graphics:HTMLFiles/Approximations_36.gif]

-Graphics -


Created by Mathematica  (March 1, 2006) Valid XHTML 1.1!