Function Repository Resource:

# PolynomialApproximation

Approximate a function with a polynomial

Contributed by: Sander Huisman
 ResourceFunction["PolynomialApproximation"][f,{x,xmin,xmax},n, "type"] finds an nth order polynomial of a given type that approximates the function f for x∈[xmin,xmax].

## Details

Supported values of "type" include:
 "Taylor" Taylor expansion around (xmin+xmax)/2 "Equispaced" Polynomial going through n+1 points equispaced between xmin and xmax "Chebyshev" Polynomial going through n+1 Chebyshev nodes "Remez" Iteratively optimize the nodes starting with Chebyshev nodes {“Remez”, m} Remez with m iterations

## Examples

### Basic Examples (5)

Find the second-order Taylor polynomial approximating the sine function:

 In[1]:=
 Out[1]=

Compare with the original function:

 In[2]:=
 Out[2]=

Use equispaced points to get a better approximation:

 In[3]:=
 Out[5]=

Use Chebyshev points to get an even better approximation:

 In[6]:=
 Out[8]=

The polynomial produced by the Remez method yields a nearly-optimal approximation:

 In[9]:=
 Out[11]=

### Scope (1)

Perform 6 iterations for the Remez method, and then compare the error:

 In[12]:=
 Out[14]=

### Applications (2)

Find a function that can approximate the cosine function for angles up to :

 In[15]:=
 Out[16]=

Calculate several orders and compare the maximum absolute error:

 In[17]:=
 Out[18]=

### Possible Issues (4)

The Remez method does not always converge:

 In[19]:=
 Out[21]=

Higher order Remez might not converge to a good solution:

 In[22]:=
 Out[24]=

Higher order Remez might be prone to numerical errors:

 In[25]:=
 Out[25]=

Functions that are not continuous can not be approximated very well:

 In[26]:=
 Out[28]=

### Neat Examples (3)

Find a function that approximates a normal distribution:

 In[29]:=
 Out[31]=

Find the maximum error:

 In[32]:=
 Out[32]=

Compare that to the Chebyshev case:

 In[33]:=
 Out[34]=
 In[35]:=
 Out[35]=

SHuisman

## Requirements

Wolfram Language 13.2 (December 2022) or above

## Version History

• 1.0.0 – 11 August 2023