{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "a19e3ec1",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "2bd87f07",
            "cell_type": "markdown",
            "source": "For some data, this method may miss a root. This happens when one of\nthe spline knots (which FITPACK places automatically) happens to\ncoincide with the true root. A workaround is to convert to `PPoly`,\nwhich uses a different root-finding algorithm.\n\nFor example,\n",
            "metadata": {}
        },
        {
            "id": "68db90ef",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = [1.96, 1.97, 1.98, 1.99, 2.00, 2.01, 2.02, 2.03, 2.04, 2.05]\ny = [-6.365470e-03, -4.790580e-03, -3.204320e-03, -1.607270e-03,\n     4.440892e-16,  1.616930e-03,  3.243000e-03,  4.877670e-03,\n     6.520430e-03,  8.170770e-03]\nfrom scipy.interpolate import UnivariateSpline\nspl = UnivariateSpline(x, y, s=0)\nspl.roots()",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([], dtype=float64)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "20a61f42",
            "cell_type": "markdown",
            "source": "Converting to a PPoly object does find the roots at `x=2`:\n",
            "metadata": {}
        },
        {
            "id": "a19221f8",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.interpolate import splrep, PPoly\ntck = splrep(x, y, s=0)\nppoly = PPoly.from_spline(tck)\nppoly.roots(extrapolate=False)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([2.])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}