Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Convert an InterpolatingFunction to a Piecewise representation
ResourceFunction["InterpolatingFunctionToPiecewise"][fun,x] converts the InterpolatingFunction of one variable fun into an equivalent Piecewise polynomial function in x. |
"Extrapolation" | False | whether to extrapolate beyond the initial domain |
InterpolationOrder | Automatic | order of polynomial pieces to use |
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]= | ![]() |
Convert an interpolating function from non-equispaced data:
In[4]:= | ![]() |
Out[4]= | ![]() |
Convert an interpolating function generated by NDSolveValue:
In[5]:= | ![]() |
Out[5]= | ![]() |
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]= | ![]() |
Use InterpolationOrder to generate a lower-order approximation to an InterpolatingFunction:
In[9]:= | ![]() |
Out[9]= | ![]() |
Generate a piecewise-constant approximation with InterpolationOrder→0:
In[10]:= | ![]() |
Out[10]= | ![]() |
InterpolatingFunctionToPiecewise currently supports only InterpolatingFunction objects of one variable and is left unevaluated otherwise:
In[11]:= | ![]() |
Out[11]= | ![]() |
This work is licensed under a Creative Commons Attribution 4.0 International License