{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "

PPOL564: DS1: Foundations

\n", "

Lecture 20

\n", "Multivariable functions and how to optimize them

\n", "\n", "## Concepts Covered:\n", "\n", "- Multivariate functions\n", "- Partial Derivatives\n", "- The Gradient\n", "- The Jacobian \n", "- Second-order and cross-partial derivatives\n", "- The Hessian\n", "- Unconstrainted Optimization\n", "- Using `sympy` to walk through the multivariate optimization steps" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import numpy.linalg as la\n", "import requests\n", "from sympy import *\n", "init_printing(use_unicode=True)\n", "\n", "# Define sympy symbols\n", "x,y = symbols('x y')" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/html": [ "" ], "text/vnd.plotly.v1+html": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "loaded!\n" ] } ], "source": [ "# Read in Visualization code from Github (requires plotly module)\n", "exec(requests.get('https://raw.githubusercontent.com/edunford/ppol564/master/lectures/visualization_library/plotly_graph_functions.py').content)\n", "mv = multivar()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Multivariate Functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "\n", "$$f(x): A \\to B$$\n", "\n", "
\n", "
\n", "\n", "Where values from set $A$, where $x \\in A$, are mapped to values in set $B$\n", "\n", "However, as we saw in linear algebra, sets need not be confined to one dimension. That is, set $A$ need no be limited to $\\mathbb{R}$ but rather can encompass $\\mathbb{R}^n$.\n", "\n", "
\n", "
\n", "\n", "$$\\textbf{f(x)} : \\mathbb{R}^n \\to \\mathbb{R}^m$$\n", "\n", "
\n", "
\n", "\n", "**scalar multi-variable value** functions take the following forms:\n", "\n", "
\n", "
\n", "\n", "$$f(x,y,z) = 3xy - y^2z + 2$$\n", "\n", "
\n", "
\n", "\n", "$$f(\\textbf{x}) = f(x_1,x_2,x_3) =\\frac{x_1 x_2}{x_3}$$\n", "\n", "
\n", "
\n", "\n", "where $\\textbf{x}$ is a vector of values.\n", "\n", "
\n", "
\n", "\n", "**Vector-value multi-variable functions** that take in some $n$ number of variables and spit out $m$ number of mapped locations: $\\mathbb{R}^n \\to \\mathbb{R}^m$. These vector functions can be thought of as being composed of multiple components $f_i(\\cdot)$.\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{f}(x,y,z) = \\begin{pmatrix} f_1(x,y,z) \\\\ f_2(x,y,z) \\\\ f_3(x,y,z) \\\\ f_4(x,y,z) \\end{pmatrix} = \\begin{pmatrix} xyz \\\\ 2x+\\frac{y}{z} \\\\ z-y^x \\\\ y^2 + x^2 + z^2 \\end{pmatrix}$$\n", "\n", "
\n", "
\n", "\n", "As we've seen if $\\textbf{f(x)}$ is linear (review \"linear combination\"), then we can rewrite it as $\\textbf{Ax}$ for some transformation matrix $\\textbf{A}$.\n", "\n", "However, we are often dealing with non-linear functions. As such, we need to employ either quadratic approximations or think about concepts like \"local-linearity\"." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Visualizing multivariate functions\n", "\n", "In short, like vectors and matrices, beyond a point, it's hard and or impossible to visualize higher dimensional space. That said, I'll introduce two types of plots in the bivariate setting that might help us think through some concepts: 3D surface plots and contour plots (with heat map coloring elements). " ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAEIAAAAXBAMAAABNOYSfAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarMolUmd1mIrvNRO9/G2jnAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABFklEQVQoFWNgAAPGUGMBCAuFRBJmZ2BvQJGDcJCE+S9wfcGiAkmYUwCrChRhVmy2MDAgCXtgcykDA0KYayMWZzAwIAkvZvCCKOGdgKwULszAtcWlECLDpoCkAiHMwPf//wcsKiDCQsoioQkIfTAzhIoYGA0gwgVMRsjhCVMRkMfACTGWcwHTL2Yk10FVcCXUMDBvAJvBwsB9AG4He0dH34uODqDpjAyPGPgUoBL8MAaYD7OF9yODvwNUxf0FjAJQJpCCqWA/wKAHEZW+YM/AilAAV8FtwLAZIpzvWMdwDYsKdgPenxBhcSW2ygQsKhhN1X8hCSMxYe4ARvwBJGEkJizmahjkEpCEsTCbGEyxiCILJalfgHAB1wE260eiHncAAAAASUVORK5CYII=\n", "text/latex": [ "$$x^{2} + y^{2}$$" ], "text/plain": [ " 2 2\n", "x + y " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# For this example, consider the following function\n", "f = x**2 + y**2\n", "f" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### 3D Surface Plots" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "colorscale": "Portland", "contours": { "z": { "highlightcolor": "#42f462", "project": { "z": true }, "show": true, "usecolormap": true } }, "opacity": 1, "type": "surface", "uid": "16ce59b4-0643-11ea-9cc1-003ee1c643c9", "x": [ [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ] ], "y": [ [ -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5 ], [ -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316 ], [ -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632 ], [ -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473 ], [ -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633 ], [ -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579 ], [ -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947 ], [ -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106 ], [ -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265 ], [ -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425 ], [ 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416 ], [ 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257 ], [ 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106 ], [ 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947 ], [ 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788 ], [ 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263 ], [ 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947 ], [ 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632 ], [ 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315 ], [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ], "z": [ [ 50, 45.013850415512465, 40.581717451523545, 36.70360110803324, 33.37950138504155, 30.60941828254848, 28.393351800554015, 26.731301939058174, 25.623268698060944, 25.06925207756233, 25.069252077562325, 25.62326869806094, 26.731301939058174, 28.393351800554015, 30.609418282548475, 33.37950138504155, 36.70360110803324, 40.581717451523545, 45.01385041551246, 50 ], [ 45.013850415512465, 40.02770083102493, 35.59556786703601, 31.717451523545705, 28.393351800554015, 25.623268698060944, 23.40720221606648, 21.74515235457064, 20.63711911357341, 20.083102493074794, 20.08310249307479, 20.637119113573405, 21.74515235457064, 23.40720221606648, 25.62326869806094, 28.393351800554015, 31.717451523545705, 35.59556786703601, 40.02770083102492, 45.013850415512465 ], [ 40.581717451523545, 35.59556786703601, 31.163434903047097, 27.28531855955679, 23.961218836565102, 21.191135734072027, 18.975069252077564, 17.313019390581722, 16.204986149584492, 15.650969529085875, 15.650969529085875, 16.20498614958449, 17.313019390581722, 18.975069252077564, 21.191135734072024, 23.9612188365651, 27.285318559556785, 31.163434903047097, 35.59556786703601, 40.581717451523545 ], [ 36.70360110803324, 31.717451523545705, 27.28531855955679, 23.40720221606648, 20.08310249307479, 17.31301939058172, 15.096952908587257, 13.434903047091412, 12.326869806094182, 11.772853185595567, 11.772853185595567, 12.32686980609418, 13.434903047091412, 15.096952908587257, 17.313019390581715, 20.08310249307479, 23.40720221606648, 27.28531855955679, 31.717451523545698, 36.70360110803324 ], [ 33.37950138504155, 28.393351800554015, 23.961218836565102, 20.08310249307479, 16.759002770083104, 13.988919667590029, 11.772853185595569, 10.110803324099724, 9.002770083102494, 8.448753462603879, 8.448753462603879, 9.002770083102492, 10.110803324099724, 11.772853185595569, 13.988919667590029, 16.7590027700831, 20.08310249307479, 23.961218836565102, 28.393351800554008, 33.37950138504155 ], [ 30.60941828254848, 25.623268698060944, 21.191135734072027, 17.31301939058172, 13.988919667590029, 11.218836565096955, 9.002770083102494, 7.34072022160665, 6.23268698060942, 5.678670360110805, 5.678670360110805, 6.232686980609419, 7.34072022160665, 9.002770083102494, 11.218836565096954, 13.988919667590029, 17.313019390581715, 21.191135734072027, 25.623268698060937, 30.60941828254848 ], [ 28.393351800554015, 23.40720221606648, 18.975069252077564, 15.096952908587257, 11.772853185595569, 9.002770083102494, 6.786703601108033, 5.124653739612189, 4.016620498614959, 3.4626038781163433, 3.462603878116343, 4.016620498614957, 5.124653739612189, 6.786703601108033, 9.002770083102492, 11.772853185595567, 15.096952908587255, 18.975069252077564, 23.407202216066473, 28.393351800554015 ], [ 26.731301939058174, 21.74515235457064, 17.313019390581722, 13.434903047091412, 10.110803324099724, 7.34072022160665, 5.124653739612189, 3.462603878116344, 2.354570637119114, 1.8005540166204992, 1.8005540166204987, 2.354570637119113, 3.462603878116344, 5.124653739612189, 7.340720221606648, 10.110803324099722, 13.43490304709141, 17.313019390581722, 21.74515235457063, 26.731301939058174 ], [ 25.623268698060944, 20.63711911357341, 16.204986149584492, 12.326869806094182, 9.002770083102494, 6.23268698060942, 4.016620498614959, 2.354570637119114, 1.2465373961218844, 0.6925207756232693, 0.6925207756232687, 1.2465373961218829, 2.354570637119114, 4.016620498614959, 6.232686980609418, 9.002770083102492, 12.32686980609418, 16.204986149584492, 20.6371191135734, 25.623268698060944 ], [ 25.06925207756233, 20.083102493074794, 15.650969529085875, 11.772853185595567, 8.448753462603879, 5.678670360110805, 3.4626038781163433, 1.8005540166204992, 0.6925207756232693, 0.13850415512465414, 0.13850415512465367, 0.6925207756232679, 1.8005540166204992, 3.4626038781163433, 5.678670360110803, 8.448753462603877, 11.772853185595565, 15.650969529085875, 20.083102493074787, 25.06925207756233 ], [ 25.069252077562325, 20.08310249307479, 15.650969529085875, 11.772853185595567, 8.448753462603879, 5.678670360110805, 3.462603878116343, 1.8005540166204987, 0.6925207756232687, 0.13850415512465367, 0.1385041551246532, 0.6925207756232674, 1.8005540166204987, 3.462603878116343, 5.678670360110803, 8.448753462603877, 11.772853185595565, 15.650969529085875, 20.083102493074783, 25.069252077562325 ], [ 25.62326869806094, 20.637119113573405, 16.20498614958449, 12.32686980609418, 9.002770083102492, 6.232686980609419, 4.016620498614957, 2.354570637119113, 1.2465373961218829, 0.6925207756232679, 0.6925207756232674, 1.2465373961218815, 2.354570637119113, 4.016620498614957, 6.232686980609417, 9.00277008310249, 12.326869806094178, 16.20498614958449, 20.637119113573398, 25.62326869806094 ], [ 26.731301939058174, 21.74515235457064, 17.313019390581722, 13.434903047091412, 10.110803324099724, 7.34072022160665, 5.124653739612189, 3.462603878116344, 2.354570637119114, 1.8005540166204992, 1.8005540166204987, 2.354570637119113, 3.462603878116344, 5.124653739612189, 7.340720221606648, 10.110803324099722, 13.43490304709141, 17.313019390581722, 21.74515235457063, 26.731301939058174 ], [ 28.393351800554015, 23.40720221606648, 18.975069252077564, 15.096952908587257, 11.772853185595569, 9.002770083102494, 6.786703601108033, 5.124653739612189, 4.016620498614959, 3.4626038781163433, 3.462603878116343, 4.016620498614957, 5.124653739612189, 6.786703601108033, 9.002770083102492, 11.772853185595567, 15.096952908587255, 18.975069252077564, 23.407202216066473, 28.393351800554015 ], [ 30.609418282548475, 25.62326869806094, 21.191135734072024, 17.313019390581715, 13.988919667590029, 11.218836565096954, 9.002770083102492, 7.340720221606648, 6.232686980609418, 5.678670360110803, 5.678670360110803, 6.232686980609417, 7.340720221606648, 9.002770083102492, 11.218836565096952, 13.988919667590025, 17.313019390581715, 21.191135734072024, 25.623268698060933, 30.609418282548475 ], [ 33.37950138504155, 28.393351800554015, 23.9612188365651, 20.08310249307479, 16.7590027700831, 13.988919667590029, 11.772853185595567, 10.110803324099722, 9.002770083102492, 8.448753462603877, 8.448753462603877, 9.00277008310249, 10.110803324099722, 11.772853185595567, 13.988919667590025, 16.7590027700831, 20.08310249307479, 23.9612188365651, 28.393351800554008, 33.37950138504155 ], [ 36.70360110803324, 31.717451523545705, 27.285318559556785, 23.40720221606648, 20.08310249307479, 17.313019390581715, 15.096952908587255, 13.43490304709141, 12.32686980609418, 11.772853185595565, 11.772853185595565, 12.326869806094178, 13.43490304709141, 15.096952908587255, 17.313019390581715, 20.08310249307479, 23.407202216066477, 27.285318559556785, 31.717451523545698, 36.70360110803324 ], [ 40.581717451523545, 35.59556786703601, 31.163434903047097, 27.28531855955679, 23.961218836565102, 21.191135734072027, 18.975069252077564, 17.313019390581722, 16.204986149584492, 15.650969529085875, 15.650969529085875, 16.20498614958449, 17.313019390581722, 18.975069252077564, 21.191135734072024, 23.9612188365651, 27.285318559556785, 31.163434903047097, 35.59556786703601, 40.581717451523545 ], [ 45.01385041551246, 40.02770083102492, 35.59556786703601, 31.717451523545698, 28.393351800554008, 25.623268698060937, 23.407202216066473, 21.74515235457063, 20.6371191135734, 20.083102493074787, 20.083102493074783, 20.637119113573398, 21.74515235457063, 23.407202216066473, 25.623268698060933, 28.393351800554008, 31.717451523545698, 35.59556786703601, 40.027700831024916, 45.01385041551246 ], [ 50, 45.013850415512465, 40.581717451523545, 36.70360110803324, 33.37950138504155, 30.60941828254848, 28.393351800554015, 26.731301939058174, 25.623268698060944, 25.06925207756233, 25.069252077562325, 25.62326869806094, 26.731301939058174, 28.393351800554015, 30.609418282548475, 33.37950138504155, 36.70360110803324, 40.581717451523545, 45.01385041551246, 50 ] ] } ], "layout": { "height": 500, "scene": { "xaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "yaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "zaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" } }, "showlegend": false, "width": 800 } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mv.plot_3d(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Contour Plots" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "opacity": 0.95, "type": "contour", "uid": "16dd4640-0643-11ea-9cc1-003ee1c643c9", "x": [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], "y": [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], "z": [ [ 50, 45.013850415512465, 40.581717451523545, 36.70360110803324, 33.37950138504155, 30.60941828254848, 28.393351800554015, 26.731301939058174, 25.623268698060944, 25.06925207756233, 25.069252077562325, 25.62326869806094, 26.731301939058174, 28.393351800554015, 30.609418282548475, 33.37950138504155, 36.70360110803324, 40.581717451523545, 45.01385041551246, 50 ], [ 45.013850415512465, 40.02770083102493, 35.59556786703601, 31.717451523545705, 28.393351800554015, 25.623268698060944, 23.40720221606648, 21.74515235457064, 20.63711911357341, 20.083102493074794, 20.08310249307479, 20.637119113573405, 21.74515235457064, 23.40720221606648, 25.62326869806094, 28.393351800554015, 31.717451523545705, 35.59556786703601, 40.02770083102492, 45.013850415512465 ], [ 40.581717451523545, 35.59556786703601, 31.163434903047097, 27.28531855955679, 23.961218836565102, 21.191135734072027, 18.975069252077564, 17.313019390581722, 16.204986149584492, 15.650969529085875, 15.650969529085875, 16.20498614958449, 17.313019390581722, 18.975069252077564, 21.191135734072024, 23.9612188365651, 27.285318559556785, 31.163434903047097, 35.59556786703601, 40.581717451523545 ], [ 36.70360110803324, 31.717451523545705, 27.28531855955679, 23.40720221606648, 20.08310249307479, 17.31301939058172, 15.096952908587257, 13.434903047091412, 12.326869806094182, 11.772853185595567, 11.772853185595567, 12.32686980609418, 13.434903047091412, 15.096952908587257, 17.313019390581715, 20.08310249307479, 23.40720221606648, 27.28531855955679, 31.717451523545698, 36.70360110803324 ], [ 33.37950138504155, 28.393351800554015, 23.961218836565102, 20.08310249307479, 16.759002770083104, 13.988919667590029, 11.772853185595569, 10.110803324099724, 9.002770083102494, 8.448753462603879, 8.448753462603879, 9.002770083102492, 10.110803324099724, 11.772853185595569, 13.988919667590029, 16.7590027700831, 20.08310249307479, 23.961218836565102, 28.393351800554008, 33.37950138504155 ], [ 30.60941828254848, 25.623268698060944, 21.191135734072027, 17.31301939058172, 13.988919667590029, 11.218836565096955, 9.002770083102494, 7.34072022160665, 6.23268698060942, 5.678670360110805, 5.678670360110805, 6.232686980609419, 7.34072022160665, 9.002770083102494, 11.218836565096954, 13.988919667590029, 17.313019390581715, 21.191135734072027, 25.623268698060937, 30.60941828254848 ], [ 28.393351800554015, 23.40720221606648, 18.975069252077564, 15.096952908587257, 11.772853185595569, 9.002770083102494, 6.786703601108033, 5.124653739612189, 4.016620498614959, 3.4626038781163433, 3.462603878116343, 4.016620498614957, 5.124653739612189, 6.786703601108033, 9.002770083102492, 11.772853185595567, 15.096952908587255, 18.975069252077564, 23.407202216066473, 28.393351800554015 ], [ 26.731301939058174, 21.74515235457064, 17.313019390581722, 13.434903047091412, 10.110803324099724, 7.34072022160665, 5.124653739612189, 3.462603878116344, 2.354570637119114, 1.8005540166204992, 1.8005540166204987, 2.354570637119113, 3.462603878116344, 5.124653739612189, 7.340720221606648, 10.110803324099722, 13.43490304709141, 17.313019390581722, 21.74515235457063, 26.731301939058174 ], [ 25.623268698060944, 20.63711911357341, 16.204986149584492, 12.326869806094182, 9.002770083102494, 6.23268698060942, 4.016620498614959, 2.354570637119114, 1.2465373961218844, 0.6925207756232693, 0.6925207756232687, 1.2465373961218829, 2.354570637119114, 4.016620498614959, 6.232686980609418, 9.002770083102492, 12.32686980609418, 16.204986149584492, 20.6371191135734, 25.623268698060944 ], [ 25.06925207756233, 20.083102493074794, 15.650969529085875, 11.772853185595567, 8.448753462603879, 5.678670360110805, 3.4626038781163433, 1.8005540166204992, 0.6925207756232693, 0.13850415512465414, 0.13850415512465367, 0.6925207756232679, 1.8005540166204992, 3.4626038781163433, 5.678670360110803, 8.448753462603877, 11.772853185595565, 15.650969529085875, 20.083102493074787, 25.06925207756233 ], [ 25.069252077562325, 20.08310249307479, 15.650969529085875, 11.772853185595567, 8.448753462603879, 5.678670360110805, 3.462603878116343, 1.8005540166204987, 0.6925207756232687, 0.13850415512465367, 0.1385041551246532, 0.6925207756232674, 1.8005540166204987, 3.462603878116343, 5.678670360110803, 8.448753462603877, 11.772853185595565, 15.650969529085875, 20.083102493074783, 25.069252077562325 ], [ 25.62326869806094, 20.637119113573405, 16.20498614958449, 12.32686980609418, 9.002770083102492, 6.232686980609419, 4.016620498614957, 2.354570637119113, 1.2465373961218829, 0.6925207756232679, 0.6925207756232674, 1.2465373961218815, 2.354570637119113, 4.016620498614957, 6.232686980609417, 9.00277008310249, 12.326869806094178, 16.20498614958449, 20.637119113573398, 25.62326869806094 ], [ 26.731301939058174, 21.74515235457064, 17.313019390581722, 13.434903047091412, 10.110803324099724, 7.34072022160665, 5.124653739612189, 3.462603878116344, 2.354570637119114, 1.8005540166204992, 1.8005540166204987, 2.354570637119113, 3.462603878116344, 5.124653739612189, 7.340720221606648, 10.110803324099722, 13.43490304709141, 17.313019390581722, 21.74515235457063, 26.731301939058174 ], [ 28.393351800554015, 23.40720221606648, 18.975069252077564, 15.096952908587257, 11.772853185595569, 9.002770083102494, 6.786703601108033, 5.124653739612189, 4.016620498614959, 3.4626038781163433, 3.462603878116343, 4.016620498614957, 5.124653739612189, 6.786703601108033, 9.002770083102492, 11.772853185595567, 15.096952908587255, 18.975069252077564, 23.407202216066473, 28.393351800554015 ], [ 30.609418282548475, 25.62326869806094, 21.191135734072024, 17.313019390581715, 13.988919667590029, 11.218836565096954, 9.002770083102492, 7.340720221606648, 6.232686980609418, 5.678670360110803, 5.678670360110803, 6.232686980609417, 7.340720221606648, 9.002770083102492, 11.218836565096952, 13.988919667590025, 17.313019390581715, 21.191135734072024, 25.623268698060933, 30.609418282548475 ], [ 33.37950138504155, 28.393351800554015, 23.9612188365651, 20.08310249307479, 16.7590027700831, 13.988919667590029, 11.772853185595567, 10.110803324099722, 9.002770083102492, 8.448753462603877, 8.448753462603877, 9.00277008310249, 10.110803324099722, 11.772853185595567, 13.988919667590025, 16.7590027700831, 20.08310249307479, 23.9612188365651, 28.393351800554008, 33.37950138504155 ], [ 36.70360110803324, 31.717451523545705, 27.285318559556785, 23.40720221606648, 20.08310249307479, 17.313019390581715, 15.096952908587255, 13.43490304709141, 12.32686980609418, 11.772853185595565, 11.772853185595565, 12.326869806094178, 13.43490304709141, 15.096952908587255, 17.313019390581715, 20.08310249307479, 23.407202216066477, 27.285318559556785, 31.717451523545698, 36.70360110803324 ], [ 40.581717451523545, 35.59556786703601, 31.163434903047097, 27.28531855955679, 23.961218836565102, 21.191135734072027, 18.975069252077564, 17.313019390581722, 16.204986149584492, 15.650969529085875, 15.650969529085875, 16.20498614958449, 17.313019390581722, 18.975069252077564, 21.191135734072024, 23.9612188365651, 27.285318559556785, 31.163434903047097, 35.59556786703601, 40.581717451523545 ], [ 45.01385041551246, 40.02770083102492, 35.59556786703601, 31.717451523545698, 28.393351800554008, 25.623268698060937, 23.407202216066473, 21.74515235457063, 20.6371191135734, 20.083102493074787, 20.083102493074783, 20.637119113573398, 21.74515235457063, 23.407202216066473, 25.623268698060933, 28.393351800554008, 31.717451523545698, 35.59556786703601, 40.027700831024916, 45.01385041551246 ], [ 50, 45.013850415512465, 40.581717451523545, 36.70360110803324, 33.37950138504155, 30.60941828254848, 28.393351800554015, 26.731301939058174, 25.623268698060944, 25.06925207756233, 25.069252077562325, 25.62326869806094, 26.731301939058174, 28.393351800554015, 30.609418282548475, 33.37950138504155, 36.70360110803324, 40.581717451523545, 45.01385041551246, 50 ] ] } ], "layout": {} }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mv.plot_contour(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Partial Derivatives\n", "\n", "What is the change in the function in one of the input variables, _holding all else constant_?\n", "\n", "Consider the following function:\n", "\n", "
\n", "
\n", "\n", "$$ f(x,y) = 2x+y^2 $$\n", "\n", "
\n", "
\n", "\n", "How should we think about the output of $f(x,y)$ when we nudge $x$ a little bit? We'll nudge it and just leave the other variable $y$ be.\n", "\n", "
\n", "
\n", "\n", "$$ \\frac{\\partial f(x,y) }{\\partial x} = \\lim_{h\\to0} \\frac{f(x+h,y) - f(x,y)}{h}$$\n", "\n", "
\n", "
\n", "\n", "$$ \\lim_{h\\to0} \\frac{ (2x+h)+y^2 - (2x+y^2)}{h} $$ \n", "\n", "
\n", "
\n", "\n", "$$ \\lim_{h\\to0} \\frac{ (2x+h) - 2x + y^2 - y^2}{h} $$ \n", "\n", "
\n", "
\n", "\n", "$$ \\lim_{h\\to0} \\frac{ 2(x+h - x) }{h} $$ \n", "\n", "
\n", "
\n", "\n", "$$ \\lim_{h\\to0} \\frac{ 2h }{h} $$ \n", "\n", "
\n", "
\n", "\n", "$$ \\frac{\\partial f(x,y) }{\\partial x} = 2 $$ " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that: Everything that is **_not_** $x$ effectively gets **treated as a constant**. Why? Because we aren't nudging it, so nothing changes, so those terms drop out." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Notation** \n", "\n", "
\n", "
\n", "\n", "$$ \\frac{\\partial f }{\\partial x} = \\frac{\\partial }{\\partial x} f = \\partial_x f = f_x $$\n", "\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# The Gradient\n", "\n", "The first order derivative of a function is now a component of many things. Sure, it's $\\frac{\\partial }{\\partial x} f$ but it's also $\\frac{\\partial }{\\partial y} f$ and so on. The function is _multivariate_ and each of those variables corresponds with a dimension. Thus, we want information about how the function changes given a nudge along all those dimensions. \n", "\n", "Luckily, there is a way of capturing and storing this information as a vector. We call this the **gradient vector** and it is denoted with the symbol $\\nabla$. \n", "\n", "$$ \\nabla = \\begin{pmatrix} \\partial_{x_1} \\\\ \\partial_{x_2} \\\\ \\vdots \\\\ \\partial_{x_m} \\end{pmatrix} $$\n", "\n", "The gradient vector is an operator where each element of the vector is the partial derivative with respect to one of the available variables. We write $\\nabla f$ for the gradient of the scalar function $f$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Calculating the gradient" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, let's use the scalar value function from above:\n", "\n", "
\n", "
\n", "\n", "$$f(x,y) = 2x+y^2$$\n", "\n", "
\n", "
\n", "\n", "We know that \n", "\n", "
\n", "
\n", "\n", "$$f_x = 2$$ \n", "\n", "
\n", "
\n", "\n", "And we can use the same method to calculate $f_y$\n", "\n", "
\n", "
\n", "\n", "$$f_y = 2y$$\n", "\n", "
\n", "
\n", "\n", "Now we stack the results\n", "\n", "
\n", "
\n", "\n", "$$\\nabla f = \\begin{pmatrix} 2 \\\\ 2y \\\\ \\end{pmatrix}$$\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What is the gradient?\n", "\n", "Note that the gradient is outputs a vector, which we can visualize." ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "mode": "lines", "type": "scatter", "uid": "16fff032-0643-11ea-9cc1-003ee1c643c9", "x": [ -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5, -6, null, -4, -4.8, null, -3, -3.6, null, -2, -2.4, null, -1, -1.2, null, 0, 0, null, 1, 1.2, null, 2, 2.4, null, 3, 3.6, null, 4, 4.8, null, -5.820698256761928, -6, -5.615486170766527, null, -4.677079814009082, -4.8, -4.471867728013681, null, -3.5334613712562373, -3.6, -3.328249285260836, null, -2.3898429285033918, -2.4, -2.1846308425079903, null, -1.246224485750546, -1.2, -1.0410123997551448, null, -0.10260604299770064, 0, 0.10260604299770061, null, 1.0410123997551448, 1.2, 1.246224485750546, null, 2.1846308425079903, 2.4, 2.3898429285033918, null, 3.328249285260836, 3.6, 3.5334613712562373, null, 4.471867728013681, 4.8, 4.677079814009082, null, -5.8001770481623875, -6, -5.636007379366067, null, -4.6565586054095425, -4.8, -4.492388936613222, null, -3.512940162656697, -3.6, -3.348770493860376, null, -2.3693217199038514, -2.4, -2.2051520511075307, null, -1.225703277151006, -1.2, -1.061533608354685, null, -0.0820848343981605, 0, 0.08208483439816047, null, 1.061533608354685, 1.2, 1.225703277151006, null, 2.2051520511075307, 2.4, 2.3693217199038514, null, 3.348770493860376, 3.6, 3.512940162656697, null, 4.492388936613222, 4.8, 4.6565586054095425, null, -5.779655839562848, -6, -5.656528587965607, null, -4.636037396810003, -4.8, -4.512910145212762, null, -3.492418954057157, -3.6, -3.369291702459916, null, -2.348800511304311, -2.4, -2.2256732597070705, null, -1.2051820685514658, -1.2, -1.082054816954225, null, -0.061563625798620396, 0, 0.061563625798620375, null, 1.082054816954225, 1.2, 1.2051820685514658, null, 2.2256732597070705, 2.4, 2.348800511304311, null, 3.369291702459916, 3.6, 3.492418954057157, null, 4.512910145212762, 4.8, 4.636037396810003, null, -5.759134630963308, -6, -5.677049796565147, null, -4.615516188210462, -4.8, -4.5334313538123014, null, -3.4718977454576168, -3.6, -3.3898129110594564, null, -2.3282793027047712, -2.4, -2.246194468306611, null, -1.1846608599519257, -1.2, -1.1025760255537653, null, -0.04104241719908025, 0, 0.041042417199080236, null, 1.1025760255537653, 1.2, 1.1846608599519257, null, 2.246194468306611, 2.4, 2.3282793027047712, null, 3.3898129110594564, 3.6, 3.4718977454576168, null, 4.5334313538123014, 4.8, 4.615516188210462, null, -5.738613422363768, -6, -5.697571005164687, null, -4.594994979610922, -4.8, -4.553952562411841, null, -3.451376536858077, -3.6, -3.4103341196589962, null, -2.307758094105231, -2.4, -2.2667156769061507, null, -1.1641396513523856, -1.2, -1.1230972341533054, null, -0.020521208599540125, 0, 0.020521208599540118, null, 1.1230972341533054, 1.2, 1.1641396513523856, null, 2.2667156769061507, 2.4, 2.307758094105231, null, 3.4103341196589962, 3.6, 3.451376536858077, null, 4.553952562411841, 4.8, 4.594994979610922, null, -5.718092213764227, -6, -5.718092213764227, null, -4.574473771011382, -4.8, -4.574473771011382, null, -3.4308553282585366, -3.6, -3.4308553282585366, null, -2.287236885505691, -2.4, -2.287236885505691, null, -1.1436184427528455, -1.2, -1.1436184427528455, null, 0, 0, 0, null, 1.1436184427528455, 1.2, 1.1436184427528455, null, 2.287236885505691, 2.4, 2.287236885505691, null, 3.4308553282585366, 3.6, 3.4308553282585366, null, 4.574473771011382, 4.8, 4.574473771011382, null, -5.697571005164687, -6, -5.738613422363768, null, -4.553952562411841, -4.8, -4.594994979610922, null, -3.4103341196589962, -3.6, -3.451376536858077, null, -2.2667156769061507, -2.4, -2.307758094105231, null, -1.1230972341533054, -1.2, -1.1641396513523856, null, 0.020521208599540118, 0, -0.020521208599540125, null, 1.1641396513523856, 1.2, 1.1230972341533054, null, 2.307758094105231, 2.4, 2.2667156769061507, null, 3.451376536858077, 3.6, 3.4103341196589962, null, 4.594994979610922, 4.8, 4.553952562411841, null, -5.677049796565147, -6, -5.759134630963308, null, -4.5334313538123014, -4.8, -4.615516188210462, null, -3.3898129110594564, -3.6, -3.4718977454576168, null, -2.246194468306611, -2.4, -2.3282793027047712, null, -1.1025760255537653, -1.2, -1.1846608599519257, null, 0.041042417199080236, 0, -0.04104241719908025, null, 1.1846608599519257, 1.2, 1.1025760255537653, null, 2.3282793027047712, 2.4, 2.246194468306611, null, 3.4718977454576168, 3.6, 3.3898129110594564, null, 4.615516188210462, 4.8, 4.5334313538123014, null, -5.656528587965607, -6, -5.779655839562848, null, -4.512910145212762, -4.8, -4.636037396810003, null, -3.369291702459916, -3.6, -3.492418954057157, null, -2.2256732597070705, -2.4, -2.348800511304311, null, -1.082054816954225, -1.2, -1.2051820685514658, null, 0.061563625798620375, 0, -0.061563625798620396, null, 1.2051820685514658, 1.2, 1.082054816954225, null, 2.348800511304311, 2.4, 2.2256732597070705, null, 3.492418954057157, 3.6, 3.369291702459916, null, 4.636037396810003, 4.8, 4.512910145212762, null, -5.636007379366067, -6, -5.8001770481623875, null, -4.492388936613222, -4.8, -4.6565586054095425, null, -3.348770493860376, -3.6, -3.512940162656697, null, -2.2051520511075307, -2.4, -2.3693217199038514, null, -1.061533608354685, -1.2, -1.225703277151006, null, 0.08208483439816047, 0, -0.0820848343981605, null, 1.225703277151006, 1.2, 1.061533608354685, null, 2.3693217199038514, 2.4, 2.2051520511075307, null, 3.512940162656697, 3.6, 3.348770493860376, null, 4.6565586054095425, 4.8, 4.492388936613222, null ], "y": [ -5, -6, null, -5, -6, null, -5, -6, null, -5, -6, null, -5, -6, null, -5, -6, null, -5, -6, null, -5, -6, null, -5, -6, null, -5, -6, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -4, -4.8, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -3, -3.6, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -2, -2.4, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, -1, -1.2, null, 0, 0, null, 0, 0, null, 0, 0, null, 0, 0, null, 0, 0, null, 0, 0, null, 0, 0, null, 0, 0, null, 0, 0, null, 0, 0, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 1, 1.2, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 2, 2.4, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 3, 3.6, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, 4, 4.8, null, -5.615486170766527, -6, -5.820698256761928, null, -5.636007379366067, -6, -5.8001770481623875, null, -5.656528587965607, -6, -5.779655839562848, null, -5.677049796565147, -6, -5.759134630963308, null, -5.697571005164687, -6, -5.738613422363768, null, -5.718092213764227, -6, -5.718092213764227, null, -5.738613422363768, -6, -5.697571005164687, null, -5.759134630963308, -6, -5.677049796565147, null, -5.779655839562848, -6, -5.656528587965607, null, -5.8001770481623875, -6, -5.636007379366067, null, -4.471867728013681, -4.8, -4.677079814009082, null, -4.492388936613222, -4.8, -4.6565586054095425, null, -4.512910145212762, -4.8, -4.636037396810003, null, -4.5334313538123014, -4.8, -4.615516188210462, null, -4.553952562411841, -4.8, -4.594994979610922, null, -4.574473771011382, -4.8, -4.574473771011382, null, -4.594994979610922, -4.8, -4.553952562411842, null, -4.615516188210462, -4.8, -4.5334313538123014, null, -4.636037396810003, -4.8, -4.512910145212762, null, -4.6565586054095425, -4.8, -4.492388936613222, null, -3.328249285260836, -3.6, -3.5334613712562373, null, -3.348770493860376, -3.6, -3.512940162656697, null, -3.369291702459916, -3.6, -3.492418954057157, null, -3.3898129110594564, -3.6, -3.4718977454576168, null, -3.4103341196589962, -3.6, -3.451376536858077, null, -3.4308553282585366, -3.6, -3.4308553282585366, null, -3.451376536858077, -3.6, -3.4103341196589962, null, -3.4718977454576168, -3.6, -3.3898129110594564, null, -3.492418954057157, -3.6, -3.369291702459916, null, -3.512940162656697, -3.6, -3.348770493860376, null, -2.1846308425079903, -2.4, -2.3898429285033918, null, -2.2051520511075307, -2.4, -2.3693217199038514, null, -2.2256732597070705, -2.4, -2.348800511304311, null, -2.246194468306611, -2.4, -2.3282793027047712, null, -2.2667156769061507, -2.4, -2.307758094105231, null, -2.287236885505691, -2.4, -2.287236885505691, null, -2.307758094105231, -2.4, -2.2667156769061507, null, -2.3282793027047712, -2.4, -2.246194468306611, null, -2.348800511304311, -2.4, -2.2256732597070705, null, -2.3693217199038514, -2.4, -2.2051520511075307, null, -1.0410123997551448, -1.2, -1.2462244857505462, null, -1.061533608354685, -1.2, -1.225703277151006, null, -1.082054816954225, -1.2, -1.2051820685514658, null, -1.1025760255537653, -1.2, -1.1846608599519257, null, -1.1230972341533054, -1.2, -1.1641396513523856, null, -1.1436184427528455, -1.2, -1.1436184427528455, null, -1.1641396513523856, -1.2, -1.1230972341533054, null, -1.1846608599519257, -1.2, -1.1025760255537653, null, -1.2051820685514658, -1.2, -1.082054816954225, null, -1.225703277151006, -1.2, -1.061533608354685, null, 0.1026060429977006, 0, -0.10260604299770067, null, 0.08208483439816046, 0, -0.08208483439816051, null, 0.06156362579862037, 0, -0.0615636257986204, null, 0.04104241719908023, 0, -0.04104241719908026, null, 0.020521208599540115, 0, -0.02052120859954013, null, 0, 0, 0, null, -0.020521208599540118, 0, 0.020521208599540118, null, -0.041042417199080236, 0, 0.041042417199080236, null, -0.061563625798620375, 0, 0.061563625798620375, null, -0.08208483439816047, 0, 0.08208483439816047, null, 1.2462244857505462, 1.2, 1.0410123997551448, null, 1.225703277151006, 1.2, 1.061533608354685, null, 1.2051820685514658, 1.2, 1.082054816954225, null, 1.1846608599519257, 1.2, 1.1025760255537653, null, 1.1641396513523856, 1.2, 1.1230972341533054, null, 1.1436184427528455, 1.2, 1.1436184427528455, null, 1.1230972341533054, 1.2, 1.1641396513523856, null, 1.1025760255537653, 1.2, 1.1846608599519257, null, 1.082054816954225, 1.2, 1.2051820685514658, null, 1.061533608354685, 1.2, 1.225703277151006, null, 2.3898429285033918, 2.4, 2.1846308425079903, null, 2.3693217199038514, 2.4, 2.2051520511075307, null, 2.348800511304311, 2.4, 2.2256732597070705, null, 2.3282793027047712, 2.4, 2.246194468306611, null, 2.307758094105231, 2.4, 2.2667156769061507, null, 2.287236885505691, 2.4, 2.287236885505691, null, 2.2667156769061507, 2.4, 2.307758094105231, null, 2.246194468306611, 2.4, 2.3282793027047712, null, 2.2256732597070705, 2.4, 2.348800511304311, null, 2.2051520511075307, 2.4, 2.3693217199038514, null, 3.5334613712562373, 3.6, 3.328249285260836, null, 3.512940162656697, 3.6, 3.348770493860376, null, 3.492418954057157, 3.6, 3.369291702459916, null, 3.4718977454576168, 3.6, 3.3898129110594564, null, 3.451376536858077, 3.6, 3.4103341196589962, null, 3.4308553282585366, 3.6, 3.4308553282585366, null, 3.4103341196589962, 3.6, 3.451376536858077, null, 3.3898129110594564, 3.6, 3.4718977454576168, null, 3.369291702459916, 3.6, 3.492418954057157, null, 3.348770493860376, 3.6, 3.512940162656697, null, 4.677079814009082, 4.8, 4.471867728013681, null, 4.6565586054095425, 4.8, 4.492388936613222, null, 4.636037396810003, 4.8, 4.512910145212762, null, 4.615516188210462, 4.8, 4.5334313538123014, null, 4.594994979610922, 4.8, 4.553952562411841, null, 4.574473771011382, 4.8, 4.574473771011382, null, 4.553952562411842, 4.8, 4.594994979610922, null, 4.5334313538123014, 4.8, 4.615516188210462, null, 4.512910145212762, 4.8, 4.636037396810003, null, 4.492388936613222, 4.8, 4.6565586054095425, null ] } ], "layout": { "hovermode": "closest" } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mv.plot_gradient(f)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$\\nabla f $ points in the direction of steepest ascent: the direction in which the function of $f$ **increases most rapidly**, and its **magnitude is the rate of this increase**. It tells us how to climb the hill." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "**Another example**\n", "\n", "Say we have function \n", "\n", "
\n", "
\n", "\n", "$$g(x,y) = x + .0001y $$\n", "\n", "
\n", "
\n", "\n", "The gradient would be \n", "\n", "
\n", "
\n", "\n", "$$ \\nabla g = \\begin{pmatrix} 1 \\\\ .0001 \\\\ \\end{pmatrix} $$\n", "\n", "
\n", "
\n", "\n", "the gradient of $g$ points most prominently in the direction of the x-axis. This means that it is moving most rapidly in that direction." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Directional Derivative\n", "\n", "Say we want to know how fast the function increases in some other direction $\\vec{v}$. To figure this out, we can just take the dot product of the gradient of the function with a vector in the direction of interest. \n", "\n", "
\n", "
\n", "\n", "$$ \\nabla f \\cdot \\vec{v} = \\begin{pmatrix} 2 \\\\ 2y \\\\ \\end{pmatrix} \\cdot \\vec{v}$$\n", "\n", "
\n", "
\n", "\n", "This tells us the rate at which $f$ changes as one moves in the direction of $\\vec{v}$. Given how we can conceptualize movement in a multivariate setting is more nuanced, the directional derivative offers a way for us to make particular movements in particular directions. \n", "\n", "For example, say \n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{x} = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix} $$\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{v} = \\begin{pmatrix} 3 \\\\ 2 \\end{pmatrix} $$\n", "\n", "
\n", "
\n", "\n", "$$\\nabla f (x) \\cdot \\textbf{v} = \\begin{pmatrix} 2 \\\\ 2(1) \\end{pmatrix} \\cdot \\begin{pmatrix} 3 \\\\ 2 \\end{pmatrix} = 2(3) + 2(2) = 10$$ \n", "\n", "
\n", "
\n", "\n", "The rate of change starting at $\\textbf{x}$ and changing to $\\textbf{v}$ is 10." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The Jacobian Matrix\n", "\n", "For vector-valued functions, isolating the first-order partial derivatives is more involved but nothing new from what we've seen before.\n", "\n", "Consider the following vector-valued function from before:\n", "\n", "
\n", "
\n", "\n", "\n", "$$ \\textbf{f}(x,y) = \\begin{pmatrix} xy \\\\ x^2 + y^2 \\\\ y-2x \\end{pmatrix}$$\n", "\n", "\n", "
\n", "
\n", "\n", "We capture information about the first order derivatives of $\\textbf{f}$ using a special matrix called a **Jacobian Matrix**. Note that $\\textbf{f}$ takes in two variable inputs and outputs a 3-dimensional vector. The dimensions of this matrix will correspond with this 2 in, 3 out arrangement. \n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{f}(x,y) = \\begin{pmatrix} f^1(x,y) \\\\ f^2(x,y) \\\\ f^3(x,y) \\end{pmatrix}$$\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{J} = \\begin{pmatrix} f_x^1(x,y) & f_y^1(x,y)\\\\ \n", "f_x^2(x,y) & f_y^2(x,y) \\\\\n", "f_x^3(x,y) & f_y^3(x,y) \\end{pmatrix} = \n", "\\begin{pmatrix} y & x\\\\ \n", "2x & 2y \\\\\n", "-2 & 1 \\end{pmatrix} $$\n", "\n", "
\n", "
\n", "\n", "All in all, the Jacobian is just a generalization of the gradient for a vector-valued function. You'll see the Jacobian used for linear approximations of functions (see reading). " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Second-order and cross-partial derivatives" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As we saw last time, taking the higher order derivatives of a function can tell us important information about the shape of a curve. \n", "\n", "Taking **second-order partial derivations** follows the same logic we encountered in the univariate context (with slightly different notation). \n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "$$ \\frac{\\partial^2}{ \\partial x^2 } = f_{xx}$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "\n", "Consider the function \n", "\n", "$$ f(x,y) = 2y^2x^3$$\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "\n", "$$ f_x = 6y^2x^2$$ \n", "\n", "
\n", "
\n", "\n", "$$ f_{xx} = 12y^2x$$ \n", "\n", "
\n", "
\n", "\n", "Likewise,\n", "\n", "$$ f_y = 4x^3y$$ \n", "\n", "
\n", "
\n", "\n", "$$ f_{yy} = 4x^3 $$ \n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can also take the **cross-partial derivative** (or the **mixed-partial derivative**): that is, we can first take the derivative with respect to one variable and then take that partial derivate with respect to another variable.\n", "\n", "
\n", "
\n", "\n", "$$ f_x = 6y^2x^2$$\n", "\n", "$$ f_{xy} = \\frac{\\partial^2 f}{\\partial_y \\partial_x} = 12yx^2$$\n", "\n", "
\n", "
\n", "\n", "Likewise, \n", "\n", "
\n", "
\n", "\n", "$$ f_y = 4x^3y$$ \n", "\n", "
\n", "
\n", "\n", "$$ f_{yx} = \\frac{\\partial^2 f}{\\partial_x \\partial_y} = 12x^2y $$\n", "\n", "
\n", "
\n", "\n", "Note something interesting here \n", "\n", "
\n", "
\n", "\n", "$$ f_{yx} = f_{xy}$$ \n", "\n", "
\n", "
\n", "\n", "$$ 12yx^2 = 12x^2y $$\n", "\n", "
\n", "
\n", "\n", "The order in which we differentiate doesn't matter!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## The Hessian \n", "\n", "A multidimensional analog to the second derivative, the Hessian provides us a way to record information about the second-order partial derivatives and the cross-partial derivatives. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Again, consider:\n", "\n", "
\n", "
\n", "\n", "$$ f(x,y) = 2y^2x^3$$\n", "\n", "
\n", "
\n", "\n", "We can concisely store this information as a matrix.\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{H} =\\begin{pmatrix} f_{xx} & f_{yx} \\\\f_{xy} & f_{yy}\\end{pmatrix}$$\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{H} =\\begin{pmatrix} 12y^2x & 12yx^2 \\\\12yx^2 & 4x^3\\end{pmatrix}$$\n", "\n", "
\n", "
\n", "\n", "where the diagonal of $\\textbf{H}$ describes the second-order partials and the off-diagonal describes the cross-partials. Note that the Hessian is both a square and symmetric matrix. As we'll see below, this means we can decompose it. Moreover, its eigenvalues will be instrumental when evaluating minima/maxima." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Optimizing in Multiple Dimensions\n", "\n", "> Disclaimer: note that we are discussing _unconstrained optimization_, so we'll avoid thinking about the boundaries of some functional domain for now. Later on, we'll introduce this topic as constraints on our optimization problems. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Consider the function:\n", "\n", "
\n", "
\n", "\n", "$$ f(x,y) = x^2 + y^2 + xy $$\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Isolating critical values\n", "\n", "As was the case in the univariate setting, we want to find our extrema candidates by isolating the stationary points in the function. Thus, let's hunt for the locations where the first-order derivatives are 0. We can do this by setting the gradient to 0.\n", "\n", "
\n", "
\n", "\n", "$$\\nabla f = \\textbf{0} $$\n", "\n", "
\n", "
\n", "\n", "where $\\textbf{0}$ equals the zero vector." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "\n", "$$ \\nabla f = \\begin{pmatrix} 2x + y \\\\ 2y + x \\end{pmatrix} $$\n", "\n", "
\n", "
\n", "\n", "$$ \\begin{pmatrix} 2x + y \\\\ 2y + x \\end{pmatrix} = \\textbf{0} $$\n", "\n", "
\n", "
\n", "\n", "$$ 2x + y = 0 \\\\ 2y + x = 0 $$\n", "\n", "
\n", "
\n", "\n", "$$ y = -2x \\\\ 2(-2x) + x = 0 $$\n", "\n", "
\n", "
\n", "\n", "$$ y = -2x \\\\ x = 0 $$\n", "\n", "
\n", "
\n", "\n", "$$ y = 0 \\\\ x = 0 $$\n", "\n", "
\n", "
\n", "\n", "So we only have one candidate entry\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{x*} = \\begin{pmatrix} x_0^* \\\\ y_0^* \\end{pmatrix} = \\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix}$$ \n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Classifying Extrema\n", "\n", "Recall that stationary points are where the \"action happens\" but we only care about certain kinds of actions. In particular, we want to know where the function is maximized/minimized. Thus, we must classify if a function is a local maxima or minima.\n", "\n", "Recall that we leveraged the second-order derivatives to figure out if a function was convex (minimum), concave (maximum), or an inflection (saddle) around a stationary point. We'll we do exactly the same thing here, except we have to use our more nuanced conceptualization of the second derivative: the **Hessian**!\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{H} =\\begin{pmatrix} f_{xx} & f_{yx} \\\\f_{xy} & f_{yy}\\end{pmatrix}$$\n", "\n", "
\n", "
\n", "\n", "In fact, the determinant of the **Hessian** tells us what we want to know. \n", "\n", "
\n", "
\n", "\n", "$$ |\\textbf{H}| =f_{xx}f_{yy} - f_{xy}^2 $$\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Interpreting $|\\textbf{H}|$ \n", "\n", "\n", "If $|\\textbf{H}| > 0 $, then we know a maxima/minima exists at the stationary point.\n", "\n", "If $|\\textbf{H}| < 0 $, then we know the stationary point is a saddle point.\n", "\n", "If $|\\textbf{H}| = 0 $, then it's undefined (insufficient information)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### What is the determinant of the Hessian actually telling us?\n", "\n", "- $f_{xx} \\to $ is the function concave/convex in the $x$ direction?\n", "\n", "\n", "- $f_{yy} \\to $ is the function concave/convex in the $y$ direction?\n", "\n", "\n", "- $f_{xx}f_{yy} \\to $ is there agreement with regard to the concavity/convexity along the two dimensions?\n", " - if they agree, then this product will be positive. \n", " - if they disagree, i.e. one axis says one thing, the other says another thing, then this product will be negative. \n", " \n", " \n", "- $f_{xy}^2 \\to $ how much does the interaction of the dimensions muddle the story?\n", " - if the interaction is really pronounced, then this influence can outweight the agreement along the first term." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### A visual" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "colorscale": "Portland", "contours": { "z": { "highlightcolor": "#42f462", "project": { "z": true }, "show": true, "usecolormap": true } }, "opacity": 1, "type": "surface", "uid": "170c24ec-0643-11ea-9cc1-003ee1c643c9", "x": [ [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ] ], "y": [ [ -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5 ], [ -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316 ], [ -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632 ], [ -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473 ], [ -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633 ], [ -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579 ], [ -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947 ], [ -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106 ], [ -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265 ], [ -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425 ], [ 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416 ], [ 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257 ], [ 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106 ], [ 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947 ], [ 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788 ], [ 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263 ], [ 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947 ], [ 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632 ], [ 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315 ], [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ], "z": [ [ 50, 45.013850415512465, 40.581717451523545, 36.70360110803324, 33.37950138504155, 30.60941828254848, 28.393351800554015, 26.731301939058174, 25.623268698060944, 25.06925207756233, 25.069252077562325, 25.62326869806094, 26.731301939058174, 28.393351800554015, 30.609418282548475, 33.37950138504155, 36.70360110803324, 40.581717451523545, 45.01385041551246, 50 ], [ 45.013850415512465, 40.02770083102493, 35.59556786703601, 31.717451523545705, 28.393351800554015, 25.623268698060944, 23.40720221606648, 21.74515235457064, 20.63711911357341, 20.083102493074794, 20.08310249307479, 20.637119113573405, 21.74515235457064, 23.40720221606648, 25.62326869806094, 28.393351800554015, 31.717451523545705, 35.59556786703601, 40.02770083102492, 45.013850415512465 ], [ 40.581717451523545, 35.59556786703601, 31.163434903047097, 27.28531855955679, 23.961218836565102, 21.191135734072027, 18.975069252077564, 17.313019390581722, 16.204986149584492, 15.650969529085875, 15.650969529085875, 16.20498614958449, 17.313019390581722, 18.975069252077564, 21.191135734072024, 23.9612188365651, 27.285318559556785, 31.163434903047097, 35.59556786703601, 40.581717451523545 ], [ 36.70360110803324, 31.717451523545705, 27.28531855955679, 23.40720221606648, 20.08310249307479, 17.31301939058172, 15.096952908587257, 13.434903047091412, 12.326869806094182, 11.772853185595567, 11.772853185595567, 12.32686980609418, 13.434903047091412, 15.096952908587257, 17.313019390581715, 20.08310249307479, 23.40720221606648, 27.28531855955679, 31.717451523545698, 36.70360110803324 ], [ 33.37950138504155, 28.393351800554015, 23.961218836565102, 20.08310249307479, 16.759002770083104, 13.988919667590029, 11.772853185595569, 10.110803324099724, 9.002770083102494, 8.448753462603879, 8.448753462603879, 9.002770083102492, 10.110803324099724, 11.772853185595569, 13.988919667590029, 16.7590027700831, 20.08310249307479, 23.961218836565102, 28.393351800554008, 33.37950138504155 ], [ 30.60941828254848, 25.623268698060944, 21.191135734072027, 17.31301939058172, 13.988919667590029, 11.218836565096955, 9.002770083102494, 7.34072022160665, 6.23268698060942, 5.678670360110805, 5.678670360110805, 6.232686980609419, 7.34072022160665, 9.002770083102494, 11.218836565096954, 13.988919667590029, 17.313019390581715, 21.191135734072027, 25.623268698060937, 30.60941828254848 ], [ 28.393351800554015, 23.40720221606648, 18.975069252077564, 15.096952908587257, 11.772853185595569, 9.002770083102494, 6.786703601108033, 5.124653739612189, 4.016620498614959, 3.4626038781163433, 3.462603878116343, 4.016620498614957, 5.124653739612189, 6.786703601108033, 9.002770083102492, 11.772853185595567, 15.096952908587255, 18.975069252077564, 23.407202216066473, 28.393351800554015 ], [ 26.731301939058174, 21.74515235457064, 17.313019390581722, 13.434903047091412, 10.110803324099724, 7.34072022160665, 5.124653739612189, 3.462603878116344, 2.354570637119114, 1.8005540166204992, 1.8005540166204987, 2.354570637119113, 3.462603878116344, 5.124653739612189, 7.340720221606648, 10.110803324099722, 13.43490304709141, 17.313019390581722, 21.74515235457063, 26.731301939058174 ], [ 25.623268698060944, 20.63711911357341, 16.204986149584492, 12.326869806094182, 9.002770083102494, 6.23268698060942, 4.016620498614959, 2.354570637119114, 1.2465373961218844, 0.6925207756232693, 0.6925207756232687, 1.2465373961218829, 2.354570637119114, 4.016620498614959, 6.232686980609418, 9.002770083102492, 12.32686980609418, 16.204986149584492, 20.6371191135734, 25.623268698060944 ], [ 25.06925207756233, 20.083102493074794, 15.650969529085875, 11.772853185595567, 8.448753462603879, 5.678670360110805, 3.4626038781163433, 1.8005540166204992, 0.6925207756232693, 0.13850415512465414, 0.13850415512465367, 0.6925207756232679, 1.8005540166204992, 3.4626038781163433, 5.678670360110803, 8.448753462603877, 11.772853185595565, 15.650969529085875, 20.083102493074787, 25.06925207756233 ], [ 25.069252077562325, 20.08310249307479, 15.650969529085875, 11.772853185595567, 8.448753462603879, 5.678670360110805, 3.462603878116343, 1.8005540166204987, 0.6925207756232687, 0.13850415512465367, 0.1385041551246532, 0.6925207756232674, 1.8005540166204987, 3.462603878116343, 5.678670360110803, 8.448753462603877, 11.772853185595565, 15.650969529085875, 20.083102493074783, 25.069252077562325 ], [ 25.62326869806094, 20.637119113573405, 16.20498614958449, 12.32686980609418, 9.002770083102492, 6.232686980609419, 4.016620498614957, 2.354570637119113, 1.2465373961218829, 0.6925207756232679, 0.6925207756232674, 1.2465373961218815, 2.354570637119113, 4.016620498614957, 6.232686980609417, 9.00277008310249, 12.326869806094178, 16.20498614958449, 20.637119113573398, 25.62326869806094 ], [ 26.731301939058174, 21.74515235457064, 17.313019390581722, 13.434903047091412, 10.110803324099724, 7.34072022160665, 5.124653739612189, 3.462603878116344, 2.354570637119114, 1.8005540166204992, 1.8005540166204987, 2.354570637119113, 3.462603878116344, 5.124653739612189, 7.340720221606648, 10.110803324099722, 13.43490304709141, 17.313019390581722, 21.74515235457063, 26.731301939058174 ], [ 28.393351800554015, 23.40720221606648, 18.975069252077564, 15.096952908587257, 11.772853185595569, 9.002770083102494, 6.786703601108033, 5.124653739612189, 4.016620498614959, 3.4626038781163433, 3.462603878116343, 4.016620498614957, 5.124653739612189, 6.786703601108033, 9.002770083102492, 11.772853185595567, 15.096952908587255, 18.975069252077564, 23.407202216066473, 28.393351800554015 ], [ 30.609418282548475, 25.62326869806094, 21.191135734072024, 17.313019390581715, 13.988919667590029, 11.218836565096954, 9.002770083102492, 7.340720221606648, 6.232686980609418, 5.678670360110803, 5.678670360110803, 6.232686980609417, 7.340720221606648, 9.002770083102492, 11.218836565096952, 13.988919667590025, 17.313019390581715, 21.191135734072024, 25.623268698060933, 30.609418282548475 ], [ 33.37950138504155, 28.393351800554015, 23.9612188365651, 20.08310249307479, 16.7590027700831, 13.988919667590029, 11.772853185595567, 10.110803324099722, 9.002770083102492, 8.448753462603877, 8.448753462603877, 9.00277008310249, 10.110803324099722, 11.772853185595567, 13.988919667590025, 16.7590027700831, 20.08310249307479, 23.9612188365651, 28.393351800554008, 33.37950138504155 ], [ 36.70360110803324, 31.717451523545705, 27.285318559556785, 23.40720221606648, 20.08310249307479, 17.313019390581715, 15.096952908587255, 13.43490304709141, 12.32686980609418, 11.772853185595565, 11.772853185595565, 12.326869806094178, 13.43490304709141, 15.096952908587255, 17.313019390581715, 20.08310249307479, 23.407202216066477, 27.285318559556785, 31.717451523545698, 36.70360110803324 ], [ 40.581717451523545, 35.59556786703601, 31.163434903047097, 27.28531855955679, 23.961218836565102, 21.191135734072027, 18.975069252077564, 17.313019390581722, 16.204986149584492, 15.650969529085875, 15.650969529085875, 16.20498614958449, 17.313019390581722, 18.975069252077564, 21.191135734072024, 23.9612188365651, 27.285318559556785, 31.163434903047097, 35.59556786703601, 40.581717451523545 ], [ 45.01385041551246, 40.02770083102492, 35.59556786703601, 31.717451523545698, 28.393351800554008, 25.623268698060937, 23.407202216066473, 21.74515235457063, 20.6371191135734, 20.083102493074787, 20.083102493074783, 20.637119113573398, 21.74515235457063, 23.407202216066473, 25.623268698060933, 28.393351800554008, 31.717451523545698, 35.59556786703601, 40.027700831024916, 45.01385041551246 ], [ 50, 45.013850415512465, 40.581717451523545, 36.70360110803324, 33.37950138504155, 30.60941828254848, 28.393351800554015, 26.731301939058174, 25.623268698060944, 25.06925207756233, 25.069252077562325, 25.62326869806094, 26.731301939058174, 28.393351800554015, 30.609418282548475, 33.37950138504155, 36.70360110803324, 40.581717451523545, 45.01385041551246, 50 ] ] } ], "layout": { "height": 500, "scene": { "xaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "yaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "zaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" } }, "showlegend": false, "width": 800 } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "c = 0 # There is no interaction in the y*x dimension\n", "f = x**2 + y**2 + c*(x*y)\n", "mv.plot_3d(f)\n", "# Why is this??" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "colorscale": "Portland", "contours": { "z": { "highlightcolor": "#42f462", "project": { "z": true }, "show": true, "usecolormap": true } }, "opacity": 1, "type": "surface", "uid": "1716fcc8-0643-11ea-9cc1-003ee1c643c9", "x": [ [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ] ], "y": [ [ -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5 ], [ -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316 ], [ -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632 ], [ -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473 ], [ -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633 ], [ -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579 ], [ -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947 ], [ -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106 ], [ -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265 ], [ -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425 ], [ 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416 ], [ 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257 ], [ 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106 ], [ 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947 ], [ 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788 ], [ 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263 ], [ 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947 ], [ 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632 ], [ 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315 ], [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ], "z": [ [ 175, 156.85595567867034, 139.26592797783934, 122.22991689750693, 105.74792243767314, 89.81994459833795, 74.44598337950137, 59.62603878116344, 45.360110803324105, 31.648199445983387, 18.490304709141288, 5.886426592797797, -6.163434903047094, -17.659279778393348, -28.60110803324099, -38.988919667590025, -48.82271468144043, -58.102493074792235, -66.82825484764541, -75 ], [ 156.8559556786704, 140.09695290858724, 123.89196675900277, 108.2409972299169, 93.14404432132964, 78.60110803324099, 64.61218836565097, 51.17728531855956, 38.29639889196677, 25.969529085872583, 14.196675900277018, 2.977839335180068, -7.686980609418285, -17.797783933518005, -27.35457063711911, -36.3573407202216, -44.806094182825476, -52.70083102493075, -60.041551246537395, -66.82825484764544 ], [ 139.26592797783934, 123.89196675900277, 109.07202216066483, 94.80609418282549, 81.09418282548478, 67.93628808864267, 55.332409972299175, 43.2825484764543, 31.786703601108044, 20.844875346260398, 10.45706371191137, 0.6232686980609543, -8.656509695290858, -17.382271468144044, -25.55401662049861, -33.171745152354575, -40.235457063711905, -46.74515235457065, -52.700831024930736, -58.10249307479225 ], [ 122.22991689750693, 108.2409972299169, 94.80609418282548, 81.92520775623268, 69.5983379501385, 57.825484764542935, 46.60664819944598, 35.94182825484765, 25.831024930747926, 16.27423822714682, 7.271468144044329, -1.177285318559548, -9.072022160664819, -16.412742382271468, -23.199445983379498, -29.43213296398892, -35.11080332409971, -40.235457063711905, -44.80609418282548, -48.822714681440445 ], [ 105.74792243767313, 93.14404432132964, 81.09418282548476, 69.5983379501385, 58.65650969529086, 48.26869806094183, 38.43490304709141, 29.15512465373962, 20.42936288088643, 12.257617728531862, 4.639889196675908, -2.4238227146814317, -8.933518005540167, -14.889196675900275, -20.290858725761773, -25.138504155124657, -29.432132963988913, -33.171745152354575, -36.35734072022161, -38.988919667590025 ], [ 89.81994459833795, 78.601108033241, 67.93628808864267, 57.825484764542935, 48.26869806094183, 39.26592797783934, 30.817174515235457, 22.9224376731302, 15.581717451523552, 8.795013850415518, 2.5623268698061006, -3.116343490304703, -8.2409972299169, -12.81163434903047, -16.82825484764543, -20.290858725761776, -23.199445983379494, -25.554016620498615, -27.354570637119114, -28.601108033241 ], [ 74.44598337950139, 64.61218836565097, 55.332409972299175, 46.60664819944598, 38.43490304709141, 30.817174515235457, 23.75346260387811, 17.24376731301939, 11.288088642659282, 5.886426592797787, 1.0387811634349071, -3.2548476454293573, -6.994459833795014, -10.180055401662045, -12.811634349030468, -14.889196675900275, -16.412742382271468, -17.382271468144044, -17.797783933518005, -17.659279778393355 ], [ 59.62603878116344, 51.177285318559555, 43.282548476454295, 35.94182825484764, 29.155124653739616, 22.9224376731302, 17.24376731301939, 12.119113573407203, 7.548476454293631, 3.5318559556786733, 0.0692520775623302, -2.8393351800553983, -5.193905817174516, -6.994459833795013, -8.240997229916898, -8.933518005540167, -9.072022160664819, -8.656509695290856, -7.686980609418287, -6.163434903047095 ], [ 45.360110803324105, 38.29639889196676, 31.78670360110804, 25.831024930747926, 20.429362880886433, 15.58171745152355, 11.28808864265928, 7.548476454293631, 4.362880886426596, 1.731301939058174, -0.3462603878116325, -1.8698060941828243, -2.839335180055403, -3.254847645429364, -3.1163434903047116, -2.4238227146814437, -1.17728531855956, 0.6232686980609404, 2.9778393351800454, 5.886426592797777 ], [ 31.64819944598339, 25.969529085872587, 20.844875346260398, 16.27423822714682, 12.257617728531862, 8.795013850415518, 5.886426592797787, 3.5318559556786733, 1.7313019390581743, 0.48476454293628946, -0.20775623268698049, -0.3462603878116357, 0.06925207756232485, 1.0387811634348998, 2.5623268698060895, 4.6398891966758935, 7.271468144044313, 10.457063711911353, 14.196675900276993, 18.490304709141267 ], [ 18.490304709141284, 14.19667590027702, 10.45706371191137, 7.271468144044329, 4.639889196675908, 2.562326869806101, 1.0387811634349078, 0.06925207756233015, -0.34626038781163254, -0.20775623268698046, 0.4847645429362862, 1.7313019390581676, 3.531855955678667, 5.886426592797779, 8.795013850415506, 12.257617728531846, 16.2742382271468, 20.84487534626038, 25.969529085872555, 31.648199445983366 ], [ 5.886426592797798, 2.977839335180069, 0.6232686980609567, -1.1772853185595473, -2.4238227146814326, -3.1163434903047023, -3.254847645429358, -2.8393351800553983, -1.8698060941828245, -0.3462603878116357, 1.7313019390581676, 4.362880886426586, 7.548476454293624, 11.288088642659272, 15.581717451523534, 20.429362880886416, 25.8310249307479, 31.786703601108023, 38.29639889196673, 45.36011080332408 ], [ -6.163434903047095, -7.686980609418283, -8.656509695290856, -9.07202216066482, -8.933518005540169, -8.240997229916898, -6.994459833795013, -5.193905817174516, -2.8393351800554036, 0.06925207756232488, 3.531855955678667, 7.548476454293624, 12.119113573407203, 17.24376731301939, 22.922437673130194, 29.155124653739612, 35.941828254847636, 43.282548476454295, 51.17728531855954, 59.62603878116344 ], [ -17.659279778393355, -17.797783933518005, -17.382271468144044, -16.412742382271468, -14.889196675900278, -12.811634349030468, -10.180055401662045, -6.994459833795014, -3.2548476454293653, 1.0387811634348996, 5.886426592797779, 11.288088642659272, 17.24376731301939, 23.75346260387811, 30.81717451523545, 38.43490304709141, 46.60664819944597, 55.332409972299175, 64.61218836565095, 74.44598337950139 ], [ -28.60110803324099, -27.35457063711911, -25.55401662049861, -23.199445983379498, -20.290858725761773, -16.82825484764543, -12.81163434903047, -8.240997229916896, -3.116343490304712, 2.5623268698060895, 8.795013850415504, 15.581717451523534, 22.922437673130194, 30.81717451523545, 39.26592797783933, 48.26869806094182, 57.82548476454292, 67.93628808864266, 78.60110803324098, 89.81994459833794 ], [ -38.988919667590025, -36.3573407202216, -33.17174515235456, -29.432132963988913, -25.138504155124657, -20.29085872576177, -14.889196675900273, -8.933518005540165, -2.423822714681444, 4.6398891966758935, 12.257617728531846, 20.429362880886412, 29.155124653739612, 38.4349030470914, 48.268698060941816, 58.65650969529085, 69.59833795013849, 81.09418282548476, 93.1440443213296, 105.74792243767313 ], [ -48.82271468144043, -44.806094182825476, -40.235457063711905, -35.11080332409971, -29.43213296398892, -23.199445983379498, -16.412742382271468, -9.07202216066482, -1.1772853185595622, 7.271468144044313, 16.274238227146803, 25.831024930747905, 35.94182825484764, 46.60664819944598, 57.82548476454293, 69.59833795013849, 81.92520775623267, 94.80609418282548, 108.24099722991687, 122.22991689750691 ], [ -58.10249307479225, -52.70083102493075, -46.74515235457065, -40.23545706371192, -33.171745152354575, -25.55401662049862, -17.382271468144044, -8.656509695290858, 0.6232686980609383, 10.457063711911353, 20.84487534626038, 31.786703601108023, 43.2825484764543, 55.332409972299175, 67.93628808864266, 81.09418282548476, 94.80609418282548, 109.07202216066483, 123.89196675900276, 139.26592797783934 ], [ -66.82825484764541, -60.04155124653739, -52.70083102493074, -44.80609418282548, -36.35734072022161, -27.354570637119117, -17.797783933518005, -7.686980609418285, 2.9778393351800467, 14.196675900276993, 25.969529085872555, 38.29639889196673, 51.17728531855955, 64.61218836565095, 78.60110803324098, 93.14404432132963, 108.24099722991687, 123.89196675900274, 140.0969529085872, 156.8559556786703 ], [ -75, -66.82825484764543, -58.102493074792235, -48.822714681440445, -38.98891966759004, -28.601108033241005, -17.659279778393348, -6.163434903047094, 5.886426592797779, 18.490304709141263, 31.648199445983366, 45.36011080332408, 59.62603878116344, 74.44598337950137, 89.81994459833794, 105.74792243767313, 122.22991689750691, 139.26592797783934, 156.85595567867034, 175 ] ] } ], "layout": { "height": 500, "scene": { "xaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "yaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "zaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" } }, "showlegend": false, "width": 800 } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "c = 5 # increase c; no there is a significant intraction\n", "f = x**2 + y**2 + c*(x*y)\n", "mv.plot_3d(f)\n", "# Why is this??" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's actually apply this...\n", "\n", "
\n", "
\n", "\n", "$$ \\nabla f = \\begin{pmatrix} 2x + y \\\\ 2y + x \\end{pmatrix} $$\n", "\n", "
\n", "
\n", "\n", "$$ \\textbf{H} =\\begin{pmatrix} 2 & 1 \\\\1 & 2\\end{pmatrix}$$\n", "\n", "
\n", "
\n", "\n", "$$ |\\textbf{H}| = (2)(2) - (1)(1) = 3 $$\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Making the call\n", "\n", "Okay, so it's an extrema, but which type? We'll to make this call, we just need to evaluate the signs of the second-order partial derivatives. \n", "\n", "Given $|\\textbf{H}| > 0$, then \n", "\n", "- if $f_{xx} = +$ and $f_{yy} = +$, $\\textbf{x}^*$ is a **local minima**.\n", "\n", "- if $f_{xx} = -$ and $f_{yy} = -$, $\\textbf{x}^*$ is a **local maxima**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "So in the case of $f$, our stationary point is _local minima_. To actually get this minimum value, we plug the points back into $f$,\n", "\n", "
\n", "
\n", "\n", "$$ f(x_0^*,y_0^*) = f(0,0) = 0^2 + 0^2 + 0(0) = 0 $$\n", "\n", "
\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What about when there are more than two variable inputs?\n", "\n", "The above is straightforward enough when dealing with two variables, but as we know, calculating the determinant for a matrix becomes increasingly more involved as the dimensions of the matrix grows: that is, as we begin to consider more and more variables. \n", "\n", "Luckily, there is a familiar solution: leverage the **eigenvalues**! \n", "\n", "Specifically, given that $|\\textbf{H}| \\ne 0$, we want to determine if the Hessian matrix is:\n", "\n", "- **positive definite**: if all eigenvalues for $\\textbf{H}$ evaluated at $\\textbf{x}^*$ are positive, then the matrix is positive definite and we can conclude that $\\textbf{x}^*$ is a local minimum. \n", "- **negative definite**: if all eigenvalues for $\\textbf{H}$ evaluated at $\\textbf{x}^*$ are positive, then the matrix is negative definite and we can conclude that $\\textbf{x}^*$ is a local maxima. \n", "- **indeterminate**: if the eigenvalues are a mix of positive and negative values. \n", "\n", "Again if $|\\textbf{H}| = 0$ then the second derivative test is inconclusive.\n", "\n", "\n", "**Given our intuition of eigenvalues and vectors, why might this make sense?**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## A friendly guide to unconstrained optimization: step-by-step" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In summary, the steps:\n", "\n", "1. find $\\nabla f$\n", "2. find stationary points: set $\\nabla f = \\textbf{0}$\n", "3. calculate the Hessian $\\textbf{H}$\n", "4. calculate the determinant of $\\textbf{H}$ for each stationary point.\n", " - if $|\\textbf{H}_{x*}| > 0$, a min/max exists\n", " - if $|\\textbf{H}_{x*}| < 0$, saddle point\n", " - if $|\\textbf{H}_{x*}| = 0$, undetermined\n", "5. calculate the eigenvalues of $\\textbf{H}$ for all remaining stationary points. \n", " - if all $\\lambda > 0$, local minima.\n", " - if all $\\lambda < 0$, local maxima.\n", " - if all $\\lambda > 0$ and $\\lambda < 0$, indeterminant .\n", " - if all $\\lambda = 0$, undefined.\n", "6. plug the remaining values back into $f$, find the highest or lowest. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Using `sympy` in a multivariate optimization problem" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As we've seen before, sympy requires that we initialize a unique data type for its class of symbols." ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [], "source": [ "x,y = symbols('x y') # This is repeat from above..." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Practice 1" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's find all critical points and determine whether they are minima, maxima, or neighter for the function \n", "\n", "$$ g(x,y) = x^2 + 6xy + y^2 - 18x - 22y +5 $$" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAARMAAAAXBAMAAADaYbYpAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEHarMolUmd1mIrvNRO9/G2jnAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADgklEQVRIDa1WS2gTURQ9k0ln8jHp2AoFFY11kZ3Wai3iohEsiBtLIQoqGNy406qLKqRaFemsNHRh0Y0RwYoblVZw4ScLwbrLSigIjS5EFCSVLrRY4/vcl3mZtpHWvMV9995z7nkn84YkgFhGeqcjswbF1QvasIcbZELKrF6wuRiZa6iV1QuGnQZb+R/BpsZeELASwSCw3ruUA/7XNp1Oeag/C14BjP4jRX9fq/2C49lJQASNRGn89xQTpBV5qjLaHxbNYV/LK1uzs4AN7PZa/swvGOnAiaIIfiarQzeve0/iPg5KyjQx3yL6ZIkhagWYldvARp0Ry+lVVZCapoN4SQSdRaeZWi8yuf+sLE/KzWJn1VncyjGfFSuhDXiC1IzPwpwXQWOBTtOtxCuVsqQQuKakTyzKuZWZp7ioAzVWPEGisOs250TQZ2qttGxdl854MIHNb/qHAIEZyQRaPYLIuBWzkszAaN/Re1iCykrLORgdPr4oQ/zThsq6nrIymkwxbCDQqX/TErj5HeIZiTVZJdwVWl7gVnDid569u1sTF2RfWek7jTA9Ym+AZ4cSIuh6dFrUiSwA4Xxg3sxxplzKShn2R4k9sAvYq2DauRXr6OsF3MH2/B7ZJCuRTBbmEx9flCM8jkDXo9NY/zkQRLTAKWJdcN3vrnuN5c3DCC9IzIkn8Im1jCmXrxRncitjsP44KbzgNWzXvfHFdTsYjZHZhFz6jD3AeQNQevBOY8DlPAvNCRaqi3yGCgj/ImzGCfp/oLiVj8DjDPBDjaoLis3iUEo1tX2M5zxoenQa+ziXUxzJGw7baBEY5U+FsCwCJQXTzqwYZfbm5hCbx1rZVFbYfW7z0Xlp9eGRDJoenfYF6AE2FHvQpE0SGGPvSomwCUTZg69Z/Kl8BaL3Xppl9ElIWWHkiRqyLHqBLRBB06PTmMI34My+S3ivTRKIZ9iUIew8ZnIag6fcygcHo9ZcWymWkaCyYnfE2NX6V2Rk8PywCND06LRxBNh1t7VbFzPanLLSNLhLYa394p3SSOarn50Idg8WjXOJU7cIUFaMruS8xqV0TaVSKYgATY9Oiwx2O4tHlJUa5HhNtUyhrLD/B4VlKKpd1VvyNMWaVkl1twvG52pRJ1E/h1l2tXVo0PUWn1ZvEqGESS9mXVoVvIquar5UslI9TcNqH9Kqf6cnk8W6pOX0/gJo5PCmKfUbzwAAAABJRU5ErkJggg==\n", "text/latex": [ "$$x^{2} + 6 x y - 18 x + y^{2} - 22 y + 5$$" ], "text/plain": [ " 2 2 \n", "x + 6â‹…xâ‹…y - 18â‹…x + y - 22â‹…y + 5" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "g = x**2 + 6*x*y + y**2 - 18*x - 22*y + 5\n", "g" ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAQsAAAAVBAMAAACj0NY+AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdt0yiUQimc27qxDvZlRT12JPAAAACXBIWXMAAA7EAAAOxAGVKw4bAAADfElEQVRIDcVWTUgUYRh+VvdHZ9xtjECwQBsJQwSX8FQHtzLqVHuPculQ1CG2IFakn6VDEAVKUVSnLYIQCUeKLAvSronuqW65QdAl0JLEkNre7/2+mZ353K2j3+Gd933e93nmmW9mZxabO7DRK2QncWCjTdD5w2lh49Tg7apewv37q+K7HOD5lgvrezUINfSjuetJcGAb0QKOpNdrIroDj6rA5pNhspGFUdKbNQi19M8g/BMc2IbhoGnaL3lMFg1Z3PfDXt7mIF6EmfcAleiESJEb6/TV+BgwCw5so2kNxopf8rMsFumiqy6yER6pYkMnJCymr9NXovMOxjMc5G60w1j2n0/ZuOnH/DnZiPxyYvJafQ2doGwYur6i0B0fT3JgG4TWLWGi9Vl/SQ4oG6u9LWlMnINZkLAXyQbGv1/2ajdhgtk81ntYIsoGFXVLZouFKXfQO/aIrEf9UoA+C9nQw1i77Esb5moRc0h9Q3xJwl4UNsLla16tEkmIodU6L5GKjT4rnJjGgs6o/04IBXc3OhHPhFYMtc3KRhm4+KI0CGNEowsbX06X0xpsCoLzAW2Zp7JTsdGJs7E8RjUC6rKEUFA2YlnUozHPU+dte9a2uyj/ASwcxQyaLCpe2mJ18AjZiGex+J4LXxCEdBL3GIrZdvc72y6IgvQdUpmh1LwqdOi1KVZOBWXjoyg3ibPxUs/GTlItRtbQJzluFyAbTQ6ifyqIzJgAiJ3m5e2G0B9w6gO/A4LoWmSQNhIpnKS5jOkwG8rGLXFxtJfbJFqJZOMtVWrrKzgTEFnBa4m5Nlh/EKHpyihnXxDNQARpoxfY+io9jrAaUzYG6FajsYAHGpt3IwPchbLt9gXBvGMsISUR14bQJxWSCqz6FEIOB7YR7cwNtS/uuYjjakrZaEyZc4gVIr8DZCpoNyI3ELfM1WBHEBLLk9ORksSVDdbHEAaKwfETudwjcGAbDeVyOT/ZnLik2O5NwcGhJMzHLYE3LCmNzndZ2J2jT5utbQcRzHPW10/qdMoG62Nq75WMwtVhuFxeBQd5U4JdeDYkHs7rfa9OaDa8hkzcm6LgQ1q7Ula3oT5tPDaIN6XKvJa5D5MGu6X6tHEZy9MdrrWq2/BPb8djfxnMJ4Llv6o6y0jV7P/fxmf6rtRc2jNXc44aieYqf5NcAtnYJ9+MLrIRx1B3+i9SCPTp8h3WEAAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left [ 2 x + 6 y - 18, \\quad 6 x + 2 y - 22\\right ]$$" ], "text/plain": [ "[2â‹…x + 6â‹…y - 18, 6â‹…x + 2â‹…y - 22]" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 1: Calculate the gradient \n", "g_x = g.diff(x)\n", "g_y = g.diff(y)\n", "grad = [g_x,g_y]\n", "grad" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAH4AAAAVBAMAAAByPkciAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEER2zVSJ3ZkiZjKru+/kt61jAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAB50lEQVQ4EZ2TsUsbcRTHv7+EO3OXpB64BKR6COLWCjo4FJvFUTwpOGqG4qx26WagGY5Cyy3SDkozO6UUuigYEePSEv8AQUHcpDZVh7jE9373S3I/z7aQB/nde5/3vrnH+70DIEbQm20EUjc535sc6Z8OKY1GTG4tf3BjUAOWP1sBslWC5oqW4SAH+zYGNbAJ84+SPqJ/6YkbrTwW7AO//q5/5uI/+isH9SBs/ZH301DuYq/UwBFQr0T0Ay8Glz2q6CuGZWPl8Nk9B95BVDl8q9i66j+VJ1BMHqR4jsMcAN9+0HR1KyzC/k2oPZn0NZA8I/ClDNhBspmhJwT92IyH87e8EjLHnHL4CDu1qGp3jYI0snmGXaMBaSZwjifjEeSzvzUDUZKV/dHcDnDqRWrZTTSwV+kyu8j+a1ctEZ4HQv4PU9Fy4noa0zQnlS3ACmA0KeL7e+rWYbZTwCVw5bRHoTDt6km3Il1A0oF5RoT1S18/YpSz4fy3+f7VVTBlS1UTcifC+X/yfVoBuTp85CaM9x5Xhfef8On76Vtl0DFRm+Ju1f3PtVq0oR19pyrqPPyszXw0y/6/9QWtvIQh2WEUSr1coihVvhjX4BvUtJgDubriIsYlsHX8asrVAUVDZUafD/nswb6T8B7TjWX6+OQF4QAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left \\{ x : 3, \\quad y : 2\\right \\}$$" ], "text/plain": [ "{x: 3, y: 2}" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 2: Set gradient to 0 and locate the stationary points\n", "crit_points = solve(grad,[x,y])\n", "crit_points" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[2., 6.],\n", " [6., 2.]])" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 3: Calculate the Hessian\n", "g_xx = g_x.diff(x)\n", "g_xy = g_x.diff(y)\n", "g_yy = g_y.diff(y)\n", "g_yx = g_y.diff(x)\n", "H = np.matrix([[g_xx,g_xy],[g_yx,g_yy]],dtype='float')\n", "H" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAADMAAAAOBAMAAABwazlqAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMiKJmbtEZlR276s0Yu9/AAAACXBIWXMAAA7EAAAOxAGVKw4bAAAA80lEQVQYGU2QsUtCURTGf1d9gdrwaHHMsa2hnHtDY5DQHk7i4CAttz+hqQRnUWgLxDu16tZWS2uJuCu8oSiD5zkXX88P7uE73497OPfCVkHztktgjyLfN1/qKYAKpTXX7P1olHOmlqE3Z2Lm8KHRI7Qy1O8SMwtZ6aR7mIQZo/zLAlaRRN8wcDuoN9TmTI5R5DtN4GIZSS38SQm+4HIqJlV5LS7fkeJRg4MT1alyWQKrxsitwVSd1zk8OEp6ya8x+V/DJKGiZ4K6oDsYy4itPnVgocG+RiO4SQE86buurF1wWCXvzHuGila+9zhJYl3StF8jNt6JQGjJVtEGAAAAAElFTkSuQmCC\n", "text/latex": [ "$$-32.0$$" ], "text/plain": [ "-32.0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Step 4: Calculate the determinant of H\n", "la.det(H)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The determinant is negative! This means we're dealing with a saddle point. Let's inspect visually to see if this is, in fact, the case." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "scrolled": false }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "colorscale": "Portland", "contours": { "z": { "highlightcolor": "#42f462", "project": { "z": true }, "show": true, "usecolormap": true } }, "opacity": 1, "type": "surface", "uid": "18560d40-0643-11ea-9cc1-003ee1c643c9", "x": [ [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ] ], "y": [ [ -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5 ], [ -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316 ], [ -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632 ], [ -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473 ], [ -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633 ], [ -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579 ], [ -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947 ], [ -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106 ], [ -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265 ], [ -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425 ], [ 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416 ], [ 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257 ], [ 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106 ], [ 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947 ], [ 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788 ], [ 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263 ], [ 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947 ], [ 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632 ], [ 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315 ], [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ], "z": [ [ 405, 374.75069252077566, 345.0554016620499, 315.9141274238227, 287.3268698060942, 259.2936288088643, 231.81440443213296, 204.88919667590028, 178.5180055401662, 152.70083102493078, 127.43767313019393, 102.72853185595571, 78.57340720221606, 54.97229916897507, 31.92520775623268, 9.432132963988948, -12.506925207756211, -33.8919667590028, -54.72299168975067, -75 ], [ 372.6454293628809, 344.0581717451524, 316.02493074792244, 288.54570637119116, 261.6204986149585, 235.2493074792244, 209.43213296398892, 184.1689750692521, 159.45983379501388, 135.30470914127426, 111.70360110803327, 88.65650969529088, 66.16343490304708, 44.22437673130193, 22.8393351800554, 2.008310249307499, -18.26869806094183, -37.991689750692515, -57.16066481994456, -75.77562326869806 ], [ 340.84487534626044, 313.91966759002776, 287.5484764542937, 261.7313019390582, 236.46814404432138, 211.75900277008313, 187.60387811634348, 164.00277008310252, 140.95567867036016, 118.46260387811637, 96.52354570637122, 75.13850415512469, 54.307479224376735, 34.030470914127434, 14.307479224376749, -4.861495844875321, -23.47645429362879, -41.537396121883646, -59.04432132963986, -75.9972299168975 ], [ 309.5983379501385, 284.3351800554017, 259.6260387811634, 235.47091412742384, 211.86980609418282, 188.82271468144046, 166.32963988919664, 144.39058171745154, 123.00554016620498, 102.17451523545708, 81.89750692520776, 62.17451523545708, 43.00554016620498, 24.390581717451525, 6.3296398891966845, -11.177285318559555, -28.130193905817166, -44.5290858725762, -60.373961218836556, -75.66481994459836 ], [ 278.9058171745153, 255.30470914127426, 232.2576177285319, 209.76454293628814, 187.82548476454292, 166.44044321329642, 145.60941828254846, 125.33240997229917, 105.60941828254849, 86.44044321329642, 67.82548476454296, 49.764542936288116, 32.257617728531855, 15.304709141274245, -1.094182825484765, -16.939058171745145, -32.2299168975069, -46.96675900277009, -61.1495844875346, -74.77839335180057 ], [ 248.7673130193906, 226.82825484764547, 205.4432132963989, 184.61218836565098, 164.33518005540168, 144.61218836565098, 125.4432132963989, 106.82825484764544, 88.7673130193906, 71.26038781163436, 54.30747922437675, 37.908587257617754, 22.063711911357338, 6.772853185595565, -7.963988919667585, -22.14681440443212, -35.775623268698055, -48.850415512465375, -61.371191135734065, -73.33795013850414 ], [ 219.18282548476458, 198.90581717451522, 179.18282548476458, 160.01385041551248, 141.398891966759, 123.33795013850417, 105.83102493074792, 88.8781163434903, 72.47922437673131, 56.63434903047093, 41.34349030470916, 26.606648199446, 12.423822714681435, -1.2049861495844851, -14.279778393351798, -26.80055401662048, -38.76731301939057, -50.180055401662045, -61.03878116343489, -71.34349030470915 ], [ 190.1523545706371, 171.53739612188366, 153.47645429362882, 135.96952908587258, 119.01662049861497, 102.61772853185596, 86.77285318559557, 71.4819944598338, 56.74515235457065, 42.56232686980611, 28.93351800554018, 15.858725761772874, 3.337950138504155, -8.628808864265924, -20.04155124653739, -30.90027700831024, -41.204986149584485, -50.955678670360115, -60.152354570637115, -68.79501385041551 ], [ 161.6759002770083, 144.7229916897507, 128.32409972299172, 112.47922437673131, 97.18836565096953, 82.45152354570638, 68.26869806094183, 54.63988919667591, 41.565096952908604, 29.0443213296399, 17.07756232686982, 5.6648199445983565, -5.193905817174514, -15.498614958448748, -25.249307479224377, -34.44598337950138, -43.08864265927976, -51.17728531855956, -58.71191135734072, -65.69252077562328 ], [ 133.75346260387812, 118.46260387811637, 103.7257617728532, 89.54293628808865, 75.91412742382273, 62.83933518005542, 50.31855955678671, 38.351800554016634, 26.93905817174517, 16.080332409972314, 5.775623268698078, -3.975069252077544, -13.171745152354564, -21.81440443213296, -29.903047091412738, -37.4376731301939, -44.41828254847645, -50.84487534626039, -56.717451523545705, -62.036011080332415 ], [ 106.38504155124656, 92.75623268698062, 79.68144044321332, 67.16066481994463, 55.19390581717454, 43.78116343490307, 32.92243767313021, 22.617728531855974, 12.86703601108035, 3.670360110803342, -4.97229916897505, -13.06094182825483, -20.595567867036003, -27.57617728531855, -34.00277008310248, -39.87534626038781, -45.1939058171745, -49.958448753462605, -54.16897506925208, -57.82548476454294 ], [ 79.57063711911361, 67.60387811634352, 56.19113573407205, 45.3324099722992, 35.02770083102496, 25.277008310249332, 16.080332409972318, 7.437673130193925, -0.6509695290858524, -8.185595567867017, -15.166204986149566, -21.592797783933502, -27.46537396121883, -32.78393351800553, -37.54847645429362, -41.7590027700831, -45.41551246537395, -48.5180055401662, -51.066481994459835, -53.060941828254855 ], [ 53.310249307479225, 43.00554016620498, 33.254847645429365, 24.058171745152347, 15.415512465373961, 7.326869806094184, -0.2077562326869824, -7.18836565096953, -13.614958448753463, -19.48753462603878, -24.806094182825483, -29.57063711911357, -33.78116343490305, -37.43767313019391, -40.54016620498615, -43.08864265927978, -45.08310249307478, -46.52354570637118, -47.40997229916897, -47.742382271468145 ], [ 27.603878116343488, 18.961218836565088, 10.872576177285325, 3.337950138504155, -3.6426592797783925, -10.069252077562329, -15.94182825484765, -21.26038781163435, -26.024930747922436, -30.235457063711912, -33.89196675900277, -36.99445983379501, -39.54293628808864, -41.53739612188366, -42.97783933518006, -43.86426592797785, -44.19667590027701, -43.97506925207756, -43.199445983379505, -41.86980609418282 ], [ 2.4515235457063724, -4.529085872576175, -10.955678670360108, -16.828254847645425, -22.146814404432128, -26.91135734072022, -31.121883656509695, -34.778393351800545, -37.880886426592795, -40.42936288088642, -42.423822714681435, -43.86426592797783, -44.750692520775615, -45.08310249307479, -44.86149584487535, -44.085872576177294, -42.7562326869806, -40.87257617728532, -38.43490304709142, -35.44321329639889 ], [ -22.14681440443212, -27.46537396121883, -32.22991689750691, -36.44044321329638, -40.09695290858724, -43.19944598337949, -45.747922437673125, -47.74238227146813, -49.182825484764535, -50.06925207756232, -50.401662049861486, -50.180055401662045, -49.40443213296398, -48.074792243767305, -46.19113573407202, -43.75346260387812, -40.76177285318559, -37.21606648199446, -33.11634349030473, -28.46260387811634 ], [ -46.191135734072006, -49.84764542936287, -52.950138504155106, -55.49861495844874, -57.49307479224375, -58.93351800554016, -59.81994459833794, -60.152354570637115, -59.93074792243766, -59.155124653739605, -57.825484764542935, -55.94182825484765, -53.504155124653735, -50.51246537396122, -46.96675900277008, -42.86703601108034, -38.21329639889197, -33.005540166204995, -27.243767313019404, -20.927977839335185 ], [ -69.68144044321332, -71.67590027700834, -73.11634349030473, -74.0027700831025, -74.33518005540168, -74.11357340720224, -73.33795013850417, -72.00831024930748, -70.1246537396122, -67.6869806094183, -64.69529085872577, -61.14958448753464, -57.04986149584488, -52.39612188365652, -47.18836565096953, -41.42659279778394, -35.110803324099734, -28.2409972299169, -20.81717451523548, -12.8393351800554 ], [ -92.61772853185593, -92.95013850415512, -92.72853185595565, -91.95290858725758, -90.62326869806091, -88.73961218836564, -86.30193905817174, -83.31024930747921, -79.76454293628808, -75.66481994459834, -71.01108033240996, -65.803324099723, -60.041551246537395, -53.72576177285318, -46.855955678670355, -39.432132963988934, -31.454293628808877, -22.92243767313019, -13.836565096952938, -4.196675900277029 ], [ -115, -113.67036011080333, -111.78670360110804, -109.34903047091413, -106.3573407202216, -102.81163434903048, -98.71191135734072, -94.05817174515235, -88.85041551246537, -83.08864265927978, -76.77285318559558, -69.90304709141276, -62.47922437673131, -54.501385041551245, -45.96952908587257, -36.8836565096953, -27.24376731301939, -17.04986149584485, -6.301939058171769, 5 ] ] } ], "layout": { "height": 500, "scene": { "xaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "yaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "zaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" } }, "showlegend": false, "width": 800 } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mv.plot_3d(g)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Sure enough there doesn't appear to be any emerging extrema" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Practice 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's find all critical points and determine whether they are minima, maxima, or neighter for the function \n", "\n", "$$ t(x,y) = - x^{2} - 3 y^{2} + y $$" ] }, { "cell_type": "code", "execution_count": 16, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIEAAAAXBAMAAADesTE9AAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAEM3dMnariVSZZiK7RO/kCJG0AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABnElEQVQ4EX2Tv0sCYRzGn6PTtLzLGowm/RfioqHJIYi2WxSaUmiKhiiK2lwampSkoCGyLWjQrQYhaGjzD6hFl6ClH4KBEGGevq/v9/uqd8Pd83ye5x6O4w5gx/xhlnlq/DLVK6CojKb8MlX9w2NSOa78MtW88Vnwy9QCsE+Npv2yQdVcHMi+uD+uSTKUyYBdq1FmYRRQzgmkZ7wp3HTGrLAg0EY80Scqe2UVbqqr6/whrA/MiAWVnfCbmPvqdJj3TL7URyobvWCksmtH/So/WyswNlzECBULGg4j7Y76Hs30FiZDDZSHFzR8h83KNmkpmc89hBPYUQDiGQSec7xjCUk8qY6EPWI3o7aLN5kWHefTcZa7lmEv/pEdejWTiLRRj5otQuWb1LD1i1nSEjLe9BbOEGiQTC4wbNSC39glLSHtDOwmnhHJkEwuMBxqLTSsHGkJOVXyvocL1EskkwsMG+fu6S0pDeTLZffPih1c049dLmh4cM9IsUepXAAYphVNhxPGO0Xiz9IxrWh6wg2OeMkYg7WbezaUuhqP/wGNHWkLgSCpVAAAAABJRU5ErkJggg==\n", "text/latex": [ "$$- x^{2} - 3 y^{2} + y$$" ], "text/plain": [ " 2 2 \n", "- x - 3â‹…y + y" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t = -x**2+y+-3*y**2\n", "t" ] }, { "cell_type": "code", "execution_count": 17, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAJUAAAAVBAMAAAC9PLGkAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAdt0yiUQQzSKZu6vvZlSXY1v9AAAACXBIWXMAAA7EAAAOxAGVKw4bAAABwElEQVQ4Ea2UPU/CUBSG3/JRKIVSHEyMC6mJCQkDg3EVDMbR/gIpcVJMaHRyMCFOuhgWQwgaTXTTAeLmYnVwNKxO8g8kGpHFYAul9OMWHDjDzfl4z5NzT9OLmQVMxSghhbWpkFSITzSzTirXk8DZbIok8S7aWME6NkSScpQ7Etn4KDK8QqVjY7ESwopRJzoHCF2ZCv6mHlB2VrgDtmtSOl1ObTEbx+uRg6WOz36ZpQ4/oFhT7ixV52kjP7+VbVlbjCi6nzkDPcejMEiNZa3wKFMNJm50W53iIcItH6fg/R+sBCIlqssOV2olAcU2mJdTRsaDG4veEzRLAUwZXoRkOwJDRTSOyLcU5vGkShhBSD4LQl1TO3YPvGn5KK+dRPPIiPwiJ3n1TzRmX1wax0CuREtEEhDS5kIFlDIQjGEtAbM74iN8AJnmV/el4Bah/sUAd1YwUa3FP5bPsQn6hzzZDXZbqCHXnDRXoNfrydsx7qIFCOTBfNV7oJC5LFlZ7N1nw/ZODAT9k5NMgcNd1zPGHbXY+uaYetSVuRkj0696zfi3tdiVlXcjqf8Zz6ZJVVeWvlxSDxc7I6W1uVan9d4nxT/8gGe5FzOAlAAAAABJRU5ErkJggg==\n", "text/latex": [ "$$\\left [ - 2 x, \\quad - 6 y + 1\\right ]$$" ], "text/plain": [ "[-2â‹…x, -6â‹…y + 1]" ] }, "execution_count": 17, "metadata": {}, "output_type": "execute_result" } ], "source": [ "grad = [t.diff(term) for term in [x,y]]\n", "grad" ] }, { "cell_type": "code", "execution_count": 18, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAIsAAAAyBAMAAACe8jVxAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAIrt2EIlmRJmrMu/dzVR9PQywAAAACXBIWXMAAA7EAAAOxAGVKw4bAAACvUlEQVRIDe1XTWsTQRh+mkyym2qT0D/QxYuICoFeKh6yUAWlkSyIIB5M/APWHyC4Ui9SgwGtB/Gwl548pOpBkCqCgpcquQsS8CL0YKpVRBp15p3ZzWy3Sdisx85h5nk/nmdn352Z3QV4m7ZEP157XPJ56W+2D+OPxnpRkWr1+GzOmHxLtHNPJNv4NZbK2cY28dhTSU91x5JBWsqg5hG/YCWTackiV5vJZGZc4lflEFvLvynF35fRKrhfG60YYZg7unOPPEPWTeb8zTBpiDVE5hMq/jEyRECGBstkXyNjjeSrBLUnW06EkGoir46BSCziUCdE+Vo04sL4E/EOcEx1KbAuejZ7f/WyAAdd3vHbNX4KS2/zS2BN7qAMLZCnTJPOUhMnSndErNrm3YyDye9aJkFnE1lxYcrQg3eL3Fr2hOsKysUHAjDRCZkfAmhtotNAzuIOytACMJ8DFZc8Ho5rkaoDY/dsGJ7hQClIKvwVTZqbJVRuqYhOK7jIR0psbKPlBTI6uM7V5U3B2MKpIJSykI08cLONk0GGDswX3KISs8O5Lpwgll0DJ9mBTYAvpiNhj7LkG+Y9t/K/z6wZHeGWz+EDFjzWE3a/mU25CHY/KbU0xPJjS6UvV4khV8Xp2YfAht3X4IitzG0Jx+51o16Xe2wGSc/bcgz6TDuAHGQuXCKzIL1qh+oZEmfCrgYWOppn4h0ekam25kCZeY3E4Rus6I4pF4ekjKsPeorE9bDr8xwvYr99tRVW0xg4mz5lL/TRdyaT6a2q2SWSYb06XtGEksnwbblsC51EMtgBFqnmyWT4HlqsJ5/Nsf8zmxu8NmIyQW2aZMXtUg4LP6nxZHDxtkeXVp+QBSvuRML56oRIRY7LcNooq+xRRuRVMooXjrOXyq51woF4lv/rgfR4/x7yasZG0b/stOWj+KP8LfsHeoW2mvlrlMcAAAAASUVORK5CYII=\n", "text/latex": [ "$$\\left \\{ x : 0, \\quad y : \\frac{1}{6}\\right \\}$$" ], "text/plain": [ "{x: 0, y: 1/6}" ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "cp = solve(grad,[x,y])\n", "cp # One critical point" ] }, { "cell_type": "code", "execution_count": 19, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "matrix([[-2., 0.],\n", " [ 0., -6.]])" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "H = [t.diff(term).diff(term2) for term in [x,y] for term2 in [x,y]]\n", "H = np.matrix(H,dtype='float').reshape(2,2)\n", "H" ] }, { "cell_type": "code", "execution_count": 20, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAACMAAAAOBAMAAABXxbiCAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAMt0Qq5nNdrvvIolEZlSFnHVmAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAvElEQVQYGTXOsQ7BUBTG8X9dIalI+gYGm0UHu6QGI0s7G20MvIGB0WjSiAfoRuIhiM2ku6EJwUBS52rvTW7Oub98OeeCVQfbHzroc5iG0AoesKXy1VKKVUNKWagDK01n2Oe0dumF0s8gcbOUBz097AnHOCN5NeUqTSdD1lvI/kBtbKjQNxQZ8kVQkjqaVFWH/uOTOE/dsEOhOVzdjKyIsrRcIJCif7/xfY/2gEKsllBc3LuM0vSFLFW7icMP5DU3m8o/1S4AAAAASUVORK5CYII=\n", "text/latex": [ "$$12.0$$" ], "text/plain": [ "12.0" ] }, "execution_count": 20, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# Positive! Let's continue...\n", "la.det(H)" ] }, { "cell_type": "code", "execution_count": 21, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-2., -6.])" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "evals = la.eigvals(H)\n", "evals " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The eigenvalues are all negative, so we can conclude that $x^* = (0,\\frac{1}{6})$ is a global maxima." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Plug that value back into $t$" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAALQAAAAOBAMAAAB0sisSAAAAMFBMVEX///8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAv3aB7AAAAD3RSTlMAiXaZIs1UEN1mu6tEMu+iw/3TAAAACXBIWXMAAA7EAAAOxAGVKw4bAAABq0lEQVQ4EY2UvUsDQRDFX0zIsfFy8eMfUFsLDyIWYhFbG1OItmdleRdsrDxBEOzSWpnCUkhaETFgYyXBVgQ7CwVJIBe0ibOT4EwK4a74vdl5s7PH3t4CmblV2Ie1trgBbM5fa+Rm19sQKFuSHCmHW2AXRxXbmtXHdOD4uFTAIUyiILZKco04HMGcINOgzqymDqc6lSBWwErg9BXEVkmuEYcjFFrID6g1Ky3iVN1PlBTw1EZfQWyV5BpxOELJh5tQa1b3J8rWaRBOIv9NOYGyJcmRcqhFTK3tzJHe99Yods8ngEe7kkBslWRbHBttz6DYo5kjzQx3gOLynQaebztQEFsluUYcjmzL7rh1F/tbwzYNwmACebtjAmVLkiPlUIt4Bq59a1bjI3yngWc/rABfEY0FaRyqoc/HC7J6EXJJsYOCAl6BZiAQ+3+Ha1BowPDhsxrTy93EA2otcIYRmgd/CNI4XAPzhmyVOrJ6FeDKa9FeCPBh90KQxuEa4AzHHfrdWN09mAX6JcO6ABf2SAvSOFwD1JboqJ2O9aVM19NDma4ngVum60mQyrGzfwEUJlwJi35nRQAAAABJRU5ErkJggg==\n", "text/latex": [ "$$0.0833333333333333$$" ], "text/plain": [ "0.0833333333333333" ] }, "execution_count": 22, "metadata": {}, "output_type": "execute_result" } ], "source": [ "t.evalf(subs={x:0,y:(1/6)})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Does that seem right?" ] }, { "cell_type": "code", "execution_count": 23, "metadata": {}, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "data": [ { "colorscale": "Portland", "contours": { "z": { "highlightcolor": "#42f462", "project": { "z": true }, "show": true, "usecolormap": true } }, "opacity": 1, "type": "surface", "uid": "196ed34c-0643-11ea-9cc1-003ee1c643c9", "x": [ [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ], [ -5, -4.473684210526316, -3.947368421052632, -3.4210526315789473, -2.8947368421052633, -2.368421052631579, -1.8421052631578947, -1.3157894736842106, -0.7894736842105265, -0.2631578947368425, 0.2631578947368416, 0.7894736842105257, 1.3157894736842106, 1.8421052631578947, 2.3684210526315788, 2.894736842105263, 3.421052631578947, 3.947368421052632, 4.473684210526315, 5 ] ], "y": [ [ -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5 ], [ -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316, -4.473684210526316 ], [ -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632, -3.947368421052632 ], [ -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473, -3.4210526315789473 ], [ -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633, -2.8947368421052633 ], [ -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579, -2.368421052631579 ], [ -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947, -1.8421052631578947 ], [ -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106, -1.3157894736842106 ], [ -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265, -0.7894736842105265 ], [ -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425, -0.2631578947368425 ], [ 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416, 0.2631578947368416 ], [ 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257, 0.7894736842105257 ], [ 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106, 1.3157894736842106 ], [ 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947, 1.8421052631578947 ], [ 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788, 2.3684210526315788 ], [ 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263, 2.894736842105263 ], [ 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947, 3.421052631578947 ], [ 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632, 3.947368421052632 ], [ 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315, 4.473684210526315 ], [ 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ], "z": [ [ -105, -100.01385041551247, -95.58171745152355, -91.70360110803324, -88.37950138504155, -85.60941828254848, -83.39335180055402, -81.73130193905817, -80.62326869806094, -80.06925207756233, -80.06925207756233, -80.62326869806094, -81.73130193905817, -83.39335180055402, -85.60941828254848, -88.37950138504155, -91.70360110803324, -95.58171745152355, -100.01385041551245, -105 ], [ -89.51523545706371, -84.52908587257618, -80.09695290858726, -76.21883656509695, -72.89473684210526, -70.12465373961219, -67.90858725761773, -66.24653739612188, -65.13850415512465, -64.58448753462604, -64.58448753462604, -65.13850415512465, -66.24653739612188, -67.90858725761773, -70.12465373961219, -72.89473684210526, -76.21883656509695, -80.09695290858726, -84.52908587257618, -89.51523545706371 ], [ -75.69252077562328, -70.70637119113574, -66.27423822714682, -62.39612188365652, -59.07202216066483, -56.301939058171754, -54.085872576177294, -52.42382271468145, -51.31578947368422, -50.761772853185605, -50.761772853185605, -51.31578947368422, -52.42382271468145, -54.085872576177294, -56.301939058171754, -59.07202216066483, -62.39612188365652, -66.27423822714682, -70.70637119113573, -75.69252077562328 ], [ -63.531855955678665, -58.54570637119113, -54.11357340720221, -50.235457063711905, -46.911357340720215, -44.14127423822714, -41.92520775623268, -40.263157894736835, -39.155124653739605, -38.60110803324099, -38.60110803324099, -39.155124653739605, -40.263157894736835, -41.92520775623268, -44.14127423822714, -46.911357340720215, -50.235457063711905, -54.11357340720221, -58.54570637119112, -63.531855955678665 ], [ -53.03324099722992, -48.04709141274238, -43.61495844875347, -39.73684210526316, -36.41274238227147, -33.6426592797784, -31.426592797783936, -29.764542936288095, -28.656509695290865, -28.10249307479225, -28.102493074792246, -28.65650969529086, -29.764542936288095, -31.426592797783936, -33.64265927977839, -36.41274238227147, -39.73684210526316, -43.61495844875347, -48.047091412742375, -53.03324099722992 ], [ -44.196675900277015, -39.21052631578948, -34.77839335180057, -30.90027700831025, -27.57617728531856, -24.80609418282549, -22.590027700831026, -20.927977839335185, -19.819944598337955, -19.26592797783934, -19.265927977839336, -19.81994459833795, -20.927977839335185, -22.590027700831026, -24.806094182825486, -27.57617728531856, -30.90027700831025, -34.77839335180057, -39.21052631578947, -44.196675900277015 ], [ -37.02216066481994, -32.03601108033241, -27.60387811634349, -23.725761772853183, -20.401662049861496, -17.63157894736842, -15.415512465373961, -13.753462603878116, -12.645429362880886, -12.091412742382271, -12.091412742382271, -12.645429362880883, -13.753462603878116, -15.415512465373961, -17.631578947368418, -20.401662049861493, -23.72576177285318, -27.60387811634349, -32.0360110803324, -37.02216066481994 ], [ -31.50969529085873, -26.523545706371195, -22.091412742382275, -18.21329639889197, -14.889196675900278, -12.119113573407205, -9.903047091412743, -8.2409972299169, -7.132963988919669, -6.578947368421054, -6.578947368421054, -7.132963988919668, -8.2409972299169, -9.903047091412743, -12.119113573407203, -14.889196675900278, -18.213296398891963, -22.091412742382275, -26.523545706371188, -31.50969529085873 ], [ -27.659279778393355, -22.67313019390582, -18.240997229916903, -14.362880886426595, -11.038781163434905, -8.26869806094183, -6.052631578947369, -4.390581717451525, -3.2825484764542954, -2.72853185595568, -2.72853185595568, -3.282548476454294, -4.390581717451525, -6.052631578947369, -8.26869806094183, -11.038781163434905, -14.362880886426591, -18.240997229916903, -22.673130193905813, -27.659279778393355 ], [ -25.470914127423825, -20.48476454293629, -16.05263157894737, -12.174515235457063, -8.850415512465375, -6.080332409972302, -3.86426592797784, -2.202216066481996, -1.0941828254847659, -0.5401662049861508, -0.5401662049861503, -1.0941828254847645, -2.202216066481996, -3.86426592797784, -6.0803324099723, -8.850415512465373, -12.174515235457061, -16.05263157894737, -20.484764542936283, -25.470914127423825 ], [ -24.944598337950136, -19.9584487534626, -15.526315789473689, -11.64819944598338, -8.32409972299169, -5.554016620498616, -3.3379501385041546, -1.6759002770083102, -0.5678670360110805, -0.013850415512465242, -0.013850415512464798, -0.5678670360110789, -1.6759002770083102, -3.3379501385041546, -5.554016620498614, -8.32409972299169, -11.648199445983376, -15.526315789473689, -19.958448753462594, -24.944598337950136 ], [ -26.0803324099723, -21.094182825484765, -16.662049861495845, -12.783933518005536, -9.459833795013848, -6.689750692520774, -4.473684210526313, -2.8116343490304687, -1.7036011080332387, -1.1495844875346237, -1.1495844875346233, -1.7036011080332374, -2.8116343490304687, -4.473684210526313, -6.689750692520772, -9.459833795013846, -12.783933518005535, -16.662049861495845, -21.094182825484758, -26.0803324099723 ], [ -28.878116343490305, -23.89196675900277, -19.459833795013857, -15.581717451523547, -12.257617728531857, -9.487534626038784, -7.271468144044322, -5.609418282548478, -4.501385041551248, -3.9473684210526327, -3.9473684210526327, -4.501385041551247, -5.609418282548478, -7.271468144044322, -9.487534626038782, -12.257617728531857, -15.581717451523543, -19.459833795013857, -23.891966759002763, -28.878116343490305 ], [ -33.33795013850415, -28.35180055401662, -23.919667590027704, -20.041551246537395, -16.71745152354571, -13.947368421052634, -11.73130193905817, -10.069252077562325, -8.961218836565095, -8.40720221606648, -8.40720221606648, -8.961218836565095, -10.069252077562325, -11.73130193905817, -13.94736842105263, -16.717451523545705, -20.04155124653739, -23.919667590027704, -28.351800554016613, -33.33795013850415 ], [ -39.45983379501385, -34.473684210526315, -30.0415512465374, -26.16343490304709, -22.839335180055404, -20.06925207756233, -17.853185595567865, -16.191135734072024, -15.083102493074794, -14.529085872576179, -14.529085872576175, -15.08310249307479, -16.191135734072024, -17.853185595567865, -20.069252077562325, -22.8393351800554, -26.163434903047087, -30.0415512465374, -34.473684210526315, -39.45983379501385 ], [ -47.24376731301939, -42.257617728531855, -37.825484764542935, -33.94736842105263, -30.623268698060937, -27.853185595567865, -25.6371191135734, -23.97506925207756, -22.86703601108033, -22.313019390581715, -22.31301939058171, -22.867036011080327, -23.97506925207756, -25.6371191135734, -27.85318559556786, -30.623268698060937, -33.94736842105263, -37.825484764542935, -42.25761772853185, -47.24376731301939 ], [ -56.68975069252077, -51.70360110803323, -47.27146814404432, -43.39335180055401, -40.06925207756232, -37.29916897506924, -35.08310249307478, -33.42105263157894, -32.31301939058171, -31.759002770083093, -31.759002770083093, -32.31301939058171, -33.42105263157894, -35.08310249307478, -37.29916897506924, -40.06925207756232, -43.39335180055401, -47.27146814404432, -51.703601108033226, -56.68975069252077 ], [ -67.79778393351802, -62.811634349030484, -58.379501385041564, -54.50138504155126, -51.17728531855957, -48.407202216066494, -46.191135734072034, -44.52908587257619, -43.42105263157896, -42.867036011080344, -42.867036011080344, -43.42105263157896, -44.52908587257619, -46.191135734072034, -48.407202216066494, -51.17728531855957, -54.50138504155126, -58.379501385041564, -62.81163434903047, -67.79778393351802 ], [ -80.56786703601107, -75.58171745152352, -71.14958448753461, -67.2714681440443, -63.947368421052616, -61.17728531855954, -58.961218836565074, -57.29916897506923, -56.191135734072, -55.637119113573384, -55.637119113573384, -56.191135734072, -57.29916897506923, -58.961218836565074, -61.17728531855954, -63.947368421052616, -67.27146814404429, -71.14958448753461, -75.58171745152352, -80.56786703601107 ], [ -95, -90.01385041551247, -85.58171745152355, -81.70360110803324, -78.37950138504155, -75.60941828254848, -73.39335180055402, -71.73130193905817, -70.62326869806094, -70.06925207756233, -70.06925207756233, -70.62326869806094, -71.73130193905817, -73.39335180055402, -75.60941828254848, -78.37950138504155, -81.70360110803324, -85.58171745152355, -90.01385041551245, -95 ] ] } ], "layout": { "height": 500, "scene": { "xaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "yaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" }, "zaxis": { "gridcolor": "#dee0e2", "showbackground": false, "zerolinecolor": "#dee0e2" } }, "showlegend": false, "width": 800 } }, "text/html": [ "
" ], "text/vnd.plotly.v1+html": [ "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "mv.plot_3d(t)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.0" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": false, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }