{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "ff2d5c37",
            "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": "e72b2213",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "import numpy as np\nfrom scipy.optimize import fmin_bfgs\ndef quadratic_cost(x, Q):\n    return x @ Q @ x\n\nx0 = np.array([-3, -4])\ncost_weight =  np.diag([1., 10.])\n# Note that a trailing comma is necessary for a tuple with single element\nfmin_bfgs(quadratic_cost, x0, args=(cost_weight,))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "Optimization terminated successfully.\n        Current function value: 0.000000\n        Iterations: 7                   # may vary\n        Function evaluations: 24        # may vary\n        Gradient evaluations: 8         # may vary\narray([ 2.85169950e-06, -4.61820139e-07])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "38c5dd1c",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "def quadratic_cost_grad(x, Q):\n    return 2 * Q @ x\n\nfmin_bfgs(quadratic_cost, x0, quadratic_cost_grad, args=(cost_weight,))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "Optimization terminated successfully.\n        Current function value: 0.000000\n        Iterations: 7\n        Function evaluations: 8\n        Gradient evaluations: 8\narray([ 2.85916637e-06, -4.54371951e-07])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}