Optimization

Finding maxima and minima of single-variable real-valued functions.

Example: Finding the maximum and minimum of f(x)=4+6x-(x^2) on the interval [0,7],  including the 2nd derivative test for concavity.

f[x_]:=4+6x-(x^2)
Plot[f[x],{x,0,7}]
Plot[f'[x],{x,0,7}]

Minimize[{f[x],0≤x≤7},x]
Maximize[{f[x],0≤x≤7},x]
FindRoot[f'[x]==0,{x,3.5}]

It looks like there’s a maximum at x=3.  Test the first and second derivative:

f'[3]
f''[3]

The first derivative is zero at 3, so there’s either a maximum, a minimum, or an inflection point there.

The second derivative is negative, indicating the function is concave down, so it must be a maximum.  This is consistent with the graph of the function.

Exercise 1

1.) For the function g(x)=(x^2)+sin(1.3 (x^2)) find all the maxima, minima and inflection points on the interval [0.5,2.5].

2.) Consider the more general function g(x)=(x^2)+sin(a (x^2)) on the interval [0.5,2.5].  For what values of a is there only one minimum and one maximum (at the endpoints of the interval)? (Maybe “Manipulate”ing a plot will help you find this....]

Finding maxima and minima of multi-variable real-valued functions.

Examples of useful functions, using as an example function f(x)=((sin((x^2)+2(y^2)))/(((x^2)+2(y^2))))

f[x_,y_]:=((Sin[(x^2)+2(y^2)])/(((x^2)+2(y^2))))
(Subscript[f, x])=D[f[x,y],x]
(Subscript[f, y]) =D[f[x,y],y]
(Subscript[f, xx])=D[
D[f[x,y],x]
,x]

Evaluating some derivatives at (1,1): (adding a decimal point to one number will give you a numerical answer...)

(Subscript[f, x])/.{x->1,y->1.}
(Subscript[f, xx])/.{x->1,y->1.}

Finding the solution to two equations simultaneously:

Solve[
{x+3y==8,2x-y==2},
{x,y}
]

Visualizations

Plot3D[f[x,y],{x,-1,5},{y,-1,5}]
Plot3D[f[x,y],{x,-1,5},{y,-1,5}, PlotRange->{-0.5,1.5}]
ContourPlot[f[x,y],{x,-1,5},{y,-1,5}]

Exercise 2

Find all the maxima, minima, or saddlepoints of f(x,y)=(x^3)+(y^3)-12x y on the square interval -1≤x≤5,-1≤y≤5. Include the 2nd derivative test. Display Plot3D and ContourPlot ‘s of this function.