{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "01d248cb",
            "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": "579900b3",
            "cell_type": "markdown",
            "source": "The modified spherical Bessel functions of the first kind $i_n$\naccept both real and complex second argument.\nThey can return a complex type:\n",
            "metadata": {}
        },
        {
            "id": "a85b5de2",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.special import spherical_in\nspherical_in(0, 3+5j)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(-1.1689867793369182-1.2697305267234222j)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "f748cb06",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "type(spherical_in(0, 3+5j))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "<class 'numpy.complex128'>"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "1f5d48ad",
            "cell_type": "markdown",
            "source": "We can verify the relation for the derivative from the Notes\nfor $n=3$ in the interval $[1, 2]$:\n",
            "metadata": {}
        },
        {
            "id": "ec2e770c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nx = np.arange(1.0, 2.0, 0.01)\nnp.allclose(spherical_in(3, x, True),\n            spherical_in(2, x) - 4/x * spherical_in(3, x))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "True"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "09a1e132",
            "cell_type": "markdown",
            "source": "The first few $i_n$ with real argument:\n",
            "metadata": {}
        },
        {
            "id": "c54756bf",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nx = np.arange(0.0, 6.0, 0.01)\nfig, ax = plt.subplots()\nax.set_ylim(-0.5, 5.0)\nax.set_title(r'Modified spherical Bessel functions $i_n$')\nfor n in np.arange(0, 4):\n    ax.plot(x, spherical_in(n, x), label=rf'$i_{n}$')\nplt.legend(loc='best')\nplt.show()",
            "outputs": []
        }
    ]
}