{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "28dbbafe",
            "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": "b3128252",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nimport matplotlib.pyplot as plt\nfrom scipy.special import sici, exp1",
            "outputs": []
        },
        {
            "id": "2c72806a",
            "cell_type": "markdown",
            "source": "`sici` accepts real or complex input:\n",
            "metadata": {}
        },
        {
            "id": "df48547a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "sici(2.5)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(1.7785201734438267, 0.2858711963653835)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "49905107",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "sici(2.5 + 3j)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "((4.505735874563953+0.06863305018999577j),\n(0.0793644206906966-2.935510262937543j))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "121e0209",
            "cell_type": "markdown",
            "source": "For z in the right half plane, the sine and cosine integrals are\nrelated to the exponential integral E1 (implemented in SciPy as\n`scipy.special.exp1`) by\n\n* Si(z) = (E1(i*z) - E1(-i*z))/2i + pi/2\n* Ci(z) = -(E1(i*z) + E1(-i*z))/2\n\nSee [1] (equations 5.2.21 and 5.2.23).\n\nWe can verify these relations:\n",
            "metadata": {}
        },
        {
            "id": "c50586dd",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "z = 2 - 3j\nsici(z)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "((4.54751388956229-1.3991965806460565j),\n(1.408292501520851+2.9836177420296055j))"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "a2f6c3fd",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "(exp1(1j*z) - exp1(-1j*z))/2j + np.pi/2  # Same as sine integral",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(4.54751388956229-1.3991965806460565j)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b080a547",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "-(exp1(1j*z) + exp1(-1j*z))/2            # Same as cosine integral",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "(1.408292501520851+2.9836177420296055j)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "aac8c3d1",
            "cell_type": "markdown",
            "source": "Plot the functions evaluated on the real axis; the dotted horizontal\nlines are at pi/2 and -pi/2:\n",
            "metadata": {}
        },
        {
            "id": "fb4a55c1",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "x = np.linspace(-16, 16, 150)\nsi, ci = sici(x)",
            "outputs": []
        },
        {
            "id": "a88c1f02",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "fig, ax = plt.subplots()\nax.plot(x, si, label='Si(x)')\nax.plot(x, ci, '--', label='Ci(x)')\nax.legend(shadow=True, framealpha=1, loc='upper left')\nax.set_xlabel('x')\nax.set_title('Sine and Cosine Integrals')\nax.axhline(np.pi/2, linestyle=':', alpha=0.5, color='k')\nax.axhline(-np.pi/2, linestyle=':', alpha=0.5, color='k')\nax.grid(True)\nplt.show()",
            "outputs": []
        }
    ]
}