Skip to content

Commit 3dae79e

Browse files
ENH: scipy.interpolate: add derivative/antiderivative and inverse interpolation examples (#742)
* ENH: scipy.interpolate: add derivative/antiderivative and inverse interpolation examples * Update intro/scipy/index.rst Co-authored-by: Matt Haberland <[email protected]> * Update intro/scipy/index.rst --------- Co-authored-by: Jarrod Millman <[email protected]>
1 parent f71480d commit 3dae79e

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

intro/scipy/index.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,33 @@ exactly through each point.
342342
:scale: 60
343343
:align: right
344344

345+
The ``derivative`` and ``antiderivative`` methods of the result object can be used
346+
for differentiation and integration. For the latter, the constant of integration is
347+
assumed to be zero, but we can "wrap" the antiderivative to include a nonzero
348+
constant of integration.
349+
350+
>>> d_interp_spline = interp_spline.derivative()
351+
>>> d_interp_results = d_interp_spline(interpolation_time)
352+
>>> i_interp_spline = lambda t: interp_spline.antiderivative()(t) - 1
353+
>>> i_interp_results = i_interp_spline(interpolation_time)
354+
355+
.. image:: auto_examples/images/sphx_glr_plot_interpolation_003.png
356+
:target: auto_examples/plot_interpolation.html
357+
:scale: 60
358+
:align: right
359+
360+
For functions that are monotonic on an interval (e.g. :math:`\sin` from :math:`\pi/2`
361+
to :math:`3\pi/2`), we can reverse the arguments of ``make_interp_spline`` to
362+
interpolate the inverse function. Because the first argument is expected to be
363+
monotonically *increasing*, we also reverse the order of elements in the arrays
364+
with :func:`numpy.flip`.
365+
366+
>>> i = (measured_time > np.pi/2) & (measured_time < 3*np.pi/2)
367+
>>> inverse_spline = sp.interpolate.make_interp_spline(np.flip(function[i]),
368+
... np.flip(measured_time[i]))
369+
>>> inverse_spline(0)
370+
array(3.14159265)
371+
345372
See the summary exercise on :ref:`summary_exercise_stat_interp` for a more
346373
advanced spline interpolation example, and read the
347374
`SciPy interpolation tutorial <https://scipy.github.io/devdocs/tutorial/interpolate.html>`__

0 commit comments

Comments
 (0)