Previous Up Next

17.2.2  Rational minimax approximation

The minimax command finds the rational function which approximates a continuous function f:[a,b]→ℝ most closely in the sense of ℓ norm. It operates exclusively in floating-point arithmetic.

Example

Find a function of form r(x)=a2x2+a1x+a0/b2x2+b1x+b0 which is an optimal ℓ-approximation of f(x)=ln(x+1)/2+sinx on the segment [0,7]. Define f by entering:

f:=ln(x+1)/(2+sin(x)):;

Now compute the approximation by entering:

fit:=minimax(f,x=0..7,[2,2])
     



0.0759657940359,
−0.00264534091503 x2+0.0393947055011 x+0.0759192001346
0.0386492470797 x2−0.368513748981 x+1



          

To display the approximation, enter:

tol,r:=op(fit):; plot(ln(x+1)/(2+sin(x)),x=0..7); plot(r,x=0..7,color=blue)

(Here, r(x) is drawn in blue.) You can conclude that max0≤ x≤ 7|f(x)−r(x)|=tol. Indeed:

maximize(abs(f-r),x=0..7)
     
0.0759657940359           

The maximal absolute error is attained at x=3.45532968966.

As another example, consider the function f(x)=xesinx/10+7cosx for x∈[0,10]. To show the graph, enter:

f:=x*exp(sin(x))/(10+7*cos(x)); D:=0..10:; plot(f,x=D)

In the examples that follow, approximation functions are not output to save space.

To obtain the ℓ error of the 15th order polynomial approximation, enter:

minimax(f,x=D,15)[0]
     
0.0800812074329           

By requesting a rational approximant, you can achieve significantly better accuracy with polynomials of lower degrees:

p:=minimax(f,x=D,[8,8])[0]
     
0.000495628620328           

Sometimes you get poles in the approximant, for example:

minimax(f,x=D,[10,3])[0]

Warning: the result is undefined at point(s) 3.03555290496

     
0.206238829817           

By using the rand option, you obtain a pole-free result:

p:=minimax(f,x=D,[10,3],rand=30)[0]

Evaluation time: 6.11

     
0.0364254964552           

Previous Up Next