# What is the equivalent of Python's 'interp1d' in Mathematica?

I am new to Mathematica, and I am trying to extrapolate some data points. In Python, I can easily do that using interp1d. See below:

from scipy.interpolate import interp1d
import numpy as np
import matplotlib.pyplot as plt

#Random_data
xdata = [0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1]
ydata = [0.11, 0.234, 0.324, 0.3986, 0.512, 0.677, 0.765, 0.85433, 1.0533]

xdata_new = np.linspace(0, 0.3, 100)
f_interp = interp1d(xdata, ydata, kind = 'quadratic', fill_value = 'extrapolate')

plt.plot(xdata, ydata, label = "original/old data")
plt.plot(xdata_new, f_interp(xdata_new), '--', label = "extrapolated data")
plt.xlabel("x")
plt.ylabel("y")
plt.legend()


The result:

My attempt in Mathematica:

xdata = {0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1, 1.1}
ydata = {0.11, 0.234, 0.324, 0.3986, 0.512, 0.677, 0.765, 0.85433,
1.0533}

ListLinePlot[Transpose[{Interpolation[xdata, 0], Interpolation[ydata, 0]}],AxesOrigin -> {0, 0}]


The result in Mathematica:

Input value {0} lies outside the range of data in the interpolating function.
Extrapolation will be used


I was using Interpolation in hopes that it will extend the data points outside the range as demonstrated in Python.

What would be the equivalent of interp1d(xdata, ydata, kind = 'quadratic', fill_value = 'extrapolate') in Mathematica?

• You're using Interpolation blindly, please read its document (which is very detailed and suitable for self-learning) carefully by pressing F1. Getting used to reading document of Mathematica is the first thing to learn for beginners. Aug 23, 2022 at 2:31

int = Interpolation[Transpose[{xdata, ydata}]]

Show[
Plot[
int[x], {x, 0.3, 1.1},
PlotLegends -> {"original"}
],
Plot[
int[x], {x, 0, 0.3}, PlotStyle -> Directive[Orange, Dashed],
PlotLegends -> {"extrapolated"}
],
Frame -> True, Axes -> False, PlotRange -> All
]


This will still output the extrapolation warning. I find that to be a positive feature: I would always like to be aware of the use of extrapolation whenever that happens.

• If you need to get rid of the warning, you can wrap the code in Off[InterpolatingFunction::dmval]; .... On[InterpolatingFunction::dmval]; Aug 22, 2022 at 18:12
• Interpolation[Transpose[{xdata, ydata}] "ExtrapolationHandler" -> {Automatic, "WarningMessage" -> False}] will transfer the redness from the output to the input, but it turns off the warning message if desired. Aug 22, 2022 at 18:22