import numpy as np
import plotly.graph_objects as go
from IPython.display import HTML, display
x1 = np.linspace(-5, 5, 200)
x2 = np.linspace(-5, 5, 200)
x1, x2 = np.meshgrid(x1, x2)
z = 3*x1**2 + 4* x1*x2 + 3 * x2**2
fig = go.Figure(data=[go.Surface(z=z, x=x1, y=x2)])
fig.update_layout(title=dict(text='Two-variable quadratic function'), autosize=False,
width=500, height=500,
margin=dict(l=65, r=50, b=65, t=90))
display(HTML(fig.to_html(full_html=False, include_plotlyjs="cdn", include_mathjax=False)))Linear Algebra: Quadratic Forms
In single-variable calculus, we often study functions of the form:
\[ f(x) = ax^2 + bx + c \]
In multivariable calculus, we can extend this idea to functions of the form:
\[ f(x_1, x_2) = a x_1^2 + b x_1 x_2 + c x_2^2 \]
This can be written in matrix form as \(f(\mathbf{x}) = \mathbf{x}^T A \mathbf{x}\), where
\[ \mathbf{x} = \begin{bmatrix} x_1 \\ x_2 \end{bmatrix}, \qquad A = \begin{bmatrix} a & b/2 \\ b/2 & c \end{bmatrix}. \]
As with \(ax^2 + bx + c\), where \(a\) determines whether the function is concave up or down, we can use the matrix \(A\) to determine whether the multidimensional bowl is concave up or down.
First, let’s see a concave up (positive definite) example:
\[ A = \begin{bmatrix} 3 & 2 \\ 2 & 3 \end{bmatrix} \]
Second, let’s see a indefinite example:
\[ A = \begin{bmatrix} 1 & 2 \\ 2 & 3 \end{bmatrix} \]
import numpy as np
import plotly.graph_objects as go
from IPython.display import HTML, display
x1 = np.linspace(-5, 5, 200)
x2 = np.linspace(-5, 5, 200)
x1, x2 = np.meshgrid(x1, x2)
z = 1*x1**2 + 4* x1*x2 + 3 * x2**2
fig = go.Figure(data=[go.Surface(z=z, x=x1, y=x2)])
fig.update_layout(title=dict(text='Two-variable quadratic function'), autosize=False,
width=500, height=500,
margin=dict(l=65, r=50, b=65, t=90))
display(HTML(fig.to_html(full_html=False, include_plotlyjs="cdn", include_mathjax=False)))This has a saddle point, in one direction it curves up, and in the other direction it curves down.
We can see this using Sylvester’s criterion, which examines the leading principal minors of \(A\). If they are all positive, the function is concave up. If their signs alternate, starting with negative, the function is concave down. If neither condition holds, the function is not definite.
For the indefinite example, the first leading principal minor is \(1 > 0\), and the second is the determinant of \(A\):
\[ \det(A) = 1 \cdot 3 - 2 \cdot 2 = 3 - 4 = -1 < 0. \]
The signs do not satisfy either definiteness condition, so \(A\) is indefinite.
Now, let’s see a concave down (negative definite) example:
\[ A = \begin{bmatrix} -1 & 2 \\ 2 & -3 \end{bmatrix} \]
The first leading principal minor is \(-1 < 0\), and the second is
\[ \det(A) = (-1)(-3) - 2 \cdot 2 = 3 - 4 = -1 < 0. \]
The signs alternate, so the function is concave down.
import numpy as np
import plotly.graph_objects as go
from IPython.display import HTML, display
x1 = np.linspace(-5, 5, 200)
x2 = np.linspace(-5, 5, 200)
x1, x2 = np.meshgrid(x1, x2)
z = -1*x1**2 + 4* x1*x2 - 3 * x2**2
fig = go.Figure(data=[go.Surface(z=z, x=x1, y=x2)])
fig.update_layout(title=dict(text='Two-variable quadratic function'), autosize=False,
width=500, height=500,
margin=dict(l=65, r=50, b=65, t=90))
display(HTML(fig.to_html(full_html=False, include_plotlyjs="cdn", include_mathjax=False)))