{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "781470c3",
            "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": "fd3af520",
            "cell_type": "markdown",
            "source": "Solve the Toeplitz system ``T @ x = b``, where\n```\n\n[ 1 -1 -2 -3]       [1]\nT = [ 3  1 -1 -2]   b = [2]\n[ 6  3  1 -1]       [2]\n[10  6  3  1]       [5]\n\n```\nTo specify the Toeplitz matrix, only the first column and the first\nrow are needed.\n",
            "metadata": {}
        },
        {
            "id": "eec38f48",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nc = np.array([1, 3, 6, 10])    # First column of T\nr = np.array([1, -1, -2, -3])  # First row of T\nb = np.array([1, 2, 2, 5])",
            "outputs": []
        },
        {
            "id": "26e1749c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy.linalg import solve_toeplitz, toeplitz\nx = solve_toeplitz((c, r), b)\nx",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.66666667, -1.        , -2.66666667,  2.33333333])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "b5fbd8cb",
            "cell_type": "markdown",
            "source": "Check the result by creating the full Toeplitz matrix and\nmultiplying it by ``x``.  We should get `b`.\n",
            "metadata": {}
        },
        {
            "id": "2fc02a52",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "T = toeplitz(c, r)\nT.dot(x)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([ 1.,  2.,  2.,  5.])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}