{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "3fcabc47",
            "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": "a2ff644d",
            "cell_type": "markdown",
            "source": "Solve the banded system ``A x = b``, where\n```\n\n[ 4  2 -1  0  0  0]       [1]\n[ 2  5  2 -1  0  0]       [2]\nA = [-1  2  6  2 -1  0]   b = [2]\n[ 0 -1  2  7  2 -1]       [3]\n[ 0  0 -1  2  8  2]       [3]\n[ 0  0  0 -1  2  9]       [3]\n\n```",
            "metadata": {}
        },
        {
            "id": "0107be3c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.linalg import solveh_banded",
            "outputs": []
        },
        {
            "id": "d9b8eae3",
            "cell_type": "markdown",
            "source": "``ab`` contains the main diagonal and the nonzero diagonals below the\nmain diagonal. That is, we use the lower form:\n",
            "metadata": {}
        },
        {
            "id": "0fa3d6df",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ab = np.array([[ 4,  5,  6,  7, 8, 9],\n               [ 2,  2,  2,  2, 2, 0],\n               [-1, -1, -1, -1, 0, 0]])\nb = np.array([1, 2, 2, 3, 3, 3])\nx = solveh_banded(ab, b, lower=True)\nx",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 0.03431373,  0.45938375,  0.05602241,  0.47759104,  0.17577031,\n        0.34733894])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "128b8f8a",
            "cell_type": "markdown",
            "source": "Solve the Hermitian banded system ``H x = b``, where\n```\n\n[ 8   2-1j   0     0  ]        [ 1  ]\nH = [2+1j  5     1j    0  ]    b = [1+1j]\n[ 0   -1j    9   -2-1j]        [1-2j]\n[ 0    0   -2+1j   6  ]        [ 0  ]\n\n```\nIn this example, we put the upper diagonals in the array ``hb``:\n",
            "metadata": {}
        },
        {
            "id": "31832649",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "hb = np.array([[0, 2-1j, 1j, -2-1j],\n               [8,  5,    9,   6  ]])\nb = np.array([1, 1+1j, 1-2j, 0])\nx = solveh_banded(hb, b)\nx",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 0.07318536-0.02939412j,  0.11877624+0.17696461j,\n        0.10077984-0.23035393j, -0.00479904-0.09358128j])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}