Function Repository Resource:

# InterpolatingFunctionToPiecewise

Convert an InterpolatingFunction to a Piecewise representation

Contributed by: Jan Mangaldan
 ResourceFunction["InterpolatingFunctionToPiecewise"][fun,x] converts the InterpolatingFunction of one variable fun into an equivalent Piecewise polynomial function in x.

## Details and Options

ResourceFunction["InterpolatingFunctionToPiecewise"] takes the following options:
 "Extrapolation" False whether to extrapolate beyond the initial domain InterpolationOrder Automatic order of polynomial pieces to use
With "Extrapolation"True, ResourceFunction["InterpolatingFunctionToPiecewise"] yields a piecewise function with a larger domain than the original function.
"Extrapolation"{bleft,bright} can be used to independently specify the extrapolation behavior on either side of the domain.

## Examples

### Basic Examples (3)

Use Interpolation to generate an interpolating function from data:

 In[1]:=
 Out[1]=

Convert the result to a Piecewise function:

 In[2]:=
 Out[2]=

Plot the relative difference between the InterpolatingFunction and the Piecewise function:

 In[3]:=
 Out[3]=

### Scope (2)

Convert an interpolating function from non-equispaced data:

 In[4]:=
 Out[4]=

Convert an interpolating function generated by NDSolveValue:

 In[5]:=
 Out[5]=

### Options (5)

#### Extrapolation (3)

By default, InterpolatingFunctionToPiecewise generates a result that is valid on the same domain as the original InterpolatingFunction:

 In[6]:=
 Out[6]=

With "Extrapolation"True, InterpolatingFunctionToPiecewise generates a result with an extended domain:

 In[7]:=
 Out[7]=

You can give a list of Boolean values to independently specify the extrapolation behavior at the left and right sides of the domain:

 In[8]:=
 Out[8]=

#### InterpolationOrder (2)

Use InterpolationOrder to generate a lower-order approximation to an InterpolatingFunction:

 In[9]:=
 Out[9]=

Generate a piecewise-constant approximation with :

 In[10]:=
 Out[10]=

### Possible Issues (1)

InterpolatingFunctionToPiecewise currently supports only InterpolatingFunction objects of one variable and is left unevaluated otherwise:

 In[11]:=
 Out[11]=

## Version History

• 1.0.2 – 13 August 2024
• 1.0.1 – 29 August 2022
• 1.0.0 – 05 February 2021