{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "7df2601a",
            "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": "842f8a1e",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.linalg import det, inv, fiedler\na = [1, 4, 12, 45, 77]\nn = len(a)\nA = fiedler(a)\nA",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0,  3, 11, 44, 76],\n       [ 3,  0,  8, 41, 73],\n       [11,  8,  0, 33, 65],\n       [44, 41, 33,  0, 32],\n       [76, 73, 65, 32,  0]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "546dcc08",
            "cell_type": "markdown",
            "source": "The explicit formulas for determinant and inverse seem to hold only for\nmonotonically increasing/decreasing arrays. Note the tridiagonal structure\nand the corners.\n",
            "metadata": {}
        },
        {
            "id": "694f958a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "Ai = inv(A)\nAi[np.abs(Ai) < 1e-12] = 0.  # cleanup the numerical noise for display\nAi",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[-0.16008772,  0.16666667,  0.        ,  0.        ,  0.00657895],\n       [ 0.16666667, -0.22916667,  0.0625    ,  0.        ,  0.        ],\n       [ 0.        ,  0.0625    , -0.07765152,  0.01515152,  0.        ],\n       [ 0.        ,  0.        ,  0.01515152, -0.03077652,  0.015625  ],\n       [ 0.00657895,  0.        ,  0.        ,  0.015625  , -0.00904605]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "61762d32",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "det(A)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "15409151.999999998"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "63d4de8d",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "(-1)**(n-1) * 2**(n-2) * np.diff(a).prod() * (a[-1] - a[0])",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "15409152"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}