{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "824dfd25",
            "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": "ddba8c06",
            "cell_type": "markdown",
            "source": "Compute the first 4 real roots and the derivatives at the roots of\n$Y_1$:\n",
            "metadata": {}
        },
        {
            "id": "e0b3b879",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.special import y1_zeros\nzeros, grads = y1_zeros(4)\nwith np.printoptions(precision=5):\n    print(f\"Roots: {zeros}\")\n    print(f\"Gradients: {grads}\")",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "Roots: [ 2.19714+0.j  5.42968+0.j  8.59601+0.j 11.74915+0.j]\nGradients: [ 0.52079+0.j -0.34032+0.j  0.27146+0.j -0.23246+0.j]"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "c9de085a",
            "cell_type": "markdown",
            "source": "Extract the real parts:\n",
            "metadata": {}
        },
        {
            "id": "d5a0ffeb",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "realzeros = zeros.real\nrealzeros",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 2.19714133,  5.42968104,  8.59600587, 11.74915483])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "61f35402",
            "cell_type": "markdown",
            "source": "Plot $Y_1$ and the first four computed roots.\n",
            "metadata": {}
        },
        {
            "id": "cfb76aa6",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import matplotlib.pyplot as plt\nfrom scipy.special import y1\nxmin = 0\nxmax = 13\nx = np.linspace(xmin, xmax, 500)\nzeros, grads = y1_zeros(4)\nfig, ax = plt.subplots()\nax.hlines(0, xmin, xmax, color='k')\nax.plot(x, y1(x), label=r'$Y_1$')\nax.scatter(zeros.real, np.zeros((4, )), s=30, c='r',\n           label=r'$Y_1$_zeros', zorder=5)\nax.set_ylim(-0.5, 0.5)\nax.set_xlim(xmin, xmax)\nplt.legend()\nplt.show()",
            "outputs": []
        },
        {
            "id": "6d3012e3",
            "cell_type": "markdown",
            "source": "Compute the first 4 complex roots and the derivatives at the roots of\n$Y_1$ by setting ``complex=True``:\n",
            "metadata": {}
        },
        {
            "id": "70875641",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "y1_zeros(4, True)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(array([ -0.50274327+0.78624371j,  -3.83353519+0.56235654j,\n         -7.01590368+0.55339305j, -10.17357383+0.55127339j]),\n array([-0.45952768+1.31710194j,  0.04830191-0.69251288j,\n        -0.02012695+0.51864253j,  0.011614  -0.43203296j]))"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}