Unconstrained Optimization - Example #2

Define Function To Be Optimized/Analyzed:

f[x_,y_]:=2*x+4*x^2-y^2+2*x*y^2-x^4-y^4;

First plot surface z = f(x,y) to see its shape.  Use both a 3d perspective and a contour plot:

Plot3D[f[x,y],{x,-2.2,2.2},{y,-2.2,2.2},AxesLabel->{"x","y","f[x,y]"}, PlotLabel -> "The Function 2x+4x^2-y^2+2xy^2-x^4-y^4", ColorFunction->Function[{x,y,z},Hue[z]]]

ContourPlot[f[x,y],{x,-2.2,2.2},{y,-2.2,2.2},AxesLabel->{"x","y","f[x,y]"}, PlotLabel -> "Contour Plot of the Function 2x+4x^2-y^2+2xy^2-x^4-y^4", ColorFunction->Hue, Contours->100, Axes->True]

Compute Gradient Of f(x,y):

Gradf[x_,y_]:={D[f[x,y],x],D[f[x,y],y]}

Gradf[x,y]

Find Critical Points By Solving Grad(f) = (0,0):

Case A : y = 0; Need to solve 2(x^3)-4x+1=0.  Graph the function to understand where the zeros are located.

p[x_]:=2*x^3-4*x-1;


Plot[p[x],{x,-2,2}, AxesLabel->{"x","p(x)"}]

Use the “Solve” command to find the roots of the polynomial.

RootSolns = Solve[p[x]==0,x]

The answer will come out in terms of radicals.  Use the "N" command to numerically evaluate the exact expressions for the roots.  Note how the imaginary parts are essentially zero.  This is numerical error -- just round it to zero.

N[RootSolns]

Case A Conclusion: Three Critical Points are (1.526, 0), (-.259, 0), and (-1.267, 0) :

Case B : If y ≠ 0, then 4(x^3)-10x-1=0 instead:  Solve this equation instead.

q[x_]:=4*x^3-10*x-1

Plot[q[x],{x,-2,2}, AxesLabel->{"x","q(x)"}]

Solve q(x) = 0 as before with p(x):

Solve[q[x]==0,x]
N[%]

The only valid solution is x = 1.629 since 2(y^2)=2x-1 requires that x > 0.  The corresponding y value is given by Sqrt[(2*x-1)/2] = 1.063 (approximately).  This yields two more critical points : (1.629, 1.063) and (1.629, 1.063).