222 - Topic 09 - Multivariate Extrema

282 days ago by Professor222

Extrema for Multivariate Functions

John Travis

Mississippi College

This sage worksheet takes a given multivariate function and compute various derivatives, critical points and the other stuff necessary to locate critical points and aid in describing any possible extreme values.  Students using this for preparing homework should copy the results of each cell into a word processor and prepare a report with all conclusions.  In other words, let Sage do the calculus and the student do the interpretation/application.  If pasting formulas into a Word document, the formulas might look funny.  That's ok.

Don't forget to get a nice perspective on your surface with all the points plotted (at the bottom) before pasting it into your document.

%auto # To start things off, enter the function f that you want to use. var('x,y') # f = x^2 - 3*x*y - y^2 # f = x^2*y+y^3-12*y # f = 2*x^3-3*x^2*y+3*x^2-y^3+3*y-4 # f = y^3-3*y*x^2-3*y^2-3*x^2+1 # f = x*sin(y) # this one has infinitely many critical points so the solver has fits f = (1/2-x^2+y^2)*e^(1-x^2-y^2) show(f) 
       

                                
                            

                                

(Be certain to evaluate each cell--in order--from the top.  The results from each active cell should print below the cell.)

fx = diff(f,x) fy = diff(f,y) grad = [fx,fy] print 'The gradient vector' show(grad) 
       
The gradient vector
The gradient vector
fxx = diff(fx,x) fyy = diff(fy,y) fxy = diff(fx,y) print 'The collection of second partial derivatives' show([fxx,fyy,fxy]) 
       
The collection of second partial derivatives
The collection of second partial derivatives
solns = solve(grad,x,y,solution_dict=True) print(html('The collection of solutions to grad(f)=0')) show((sol[x],sol[y]) for sol in solns) 
       
The collection of solutions to grad(f)=0

The collection of solutions to grad(f)=0

# To display the results nicely to determine extreme nature... for sol in solns: html('At critical point $%s$,'%str(latex((sol[x],sol[y])))) d = (fxx(x=sol[x],y=sol[y])*fyy(x=sol[x],y=sol[y])-fxy(x=sol[x],y=sol[y])^2) html(' d = $%s$ '%str(latex(d))+'with $f_{xx} = %s.'%str(latex(fxx(x=sol[x],y=sol[y])))) 
       
At critical point ,

d = with

At critical point ,

d = with

At critical point ,

d = with

At critical point ,

d = with

At critical point ,

d = with
At critical point ,

d = with

At critical point ,

d = with

At critical point ,

d = with

At critical point ,

d = with

At critical point ,

d = with
# Determine the ranges of the extrema components to get bounds for a nice graph minx = min(sol[x] for sol in solns) maxx = max(sol[x] for sol in solns) miny = min(sol[y] for sol in solns) maxy = max(sol[y] for sol in solns) print 'range of x values: ',(minx,maxx) print 'range of y values: ',(miny,maxy) 
       
range of x values:   (-1/2*sqrt(3)*sqrt(2), 1/2*sqrt(3)*sqrt(2))
range of y values:   (-1/2*sqrt(2), 1/2*sqrt(2))
range of x values:   (-1/2*sqrt(3)*sqrt(2), 1/2*sqrt(3)*sqrt(2))
range of y values:   (-1/2*sqrt(2), 1/2*sqrt(2))
# Use this cell if the above cell returns a range of values that is not definite # minx = # maxx = # miny = -pi # maxy = pi # Solns = needs to be a finite string of values...how to get rid of the possible z?? terms? 
       
print 'A nice plot of the given surface with critical points.' Surf = plot3d(f,(x,minx-1,maxx+1),(y,miny-1,maxy+1),color='yellow') delx = (maxx-minx)/6 dely = (maxy-miny)/6 Points = [] G = Graphics() for sol in solns: z = f(x=sol[x],y=sol[y]) Points.append((sol[x],sol[y],z)) G += point3d((sol[x],sol[y],z),size=20) G += text3d('(%s,'%str(sol[x])+'%s,'%str(sol[y])+'%s)'%str(z),(sol[x]+delx,sol[y]+dely,z+1),horizontal_alignment='left', vertical_alignment='bottom') # Dots = point3d(Points,size=10) (Surf+G).show() 
       
A nice plot of the given surface with critical points.
A nice plot of the given surface with critical points.
# The whole thing in one cell var('x,y') @interact def _(f = input_box(2*x^3-3*x^2*y+3*x^2-y^3+3*y-4,label='$f(x,y) = $')): fx = diff(f,x) fy = diff(f,y) grad = [fx,fy] fxx = diff(fx,x) fyy = diff(fy,y) fxy = diff(fx,y) solns = solve(grad,x,y,solution_dict=True) for sol in solns: html('At critical point $%s$,'%str(latex((sol[x],sol[y])))) d = (fxx(x=sol[x],y=sol[y])*fyy(x=sol[x],y=sol[y])-fxy(x=sol[x],y=sol[y])^2) html(' d = $%s$ '%str(latex(d))+'with $f_{xx} = %s.'%str(latex(fxx(x=sol[x],y=sol[y])))) solns = solve(grad,x,y,solution_dict=True) minx = min(sol[x] for sol in solns) maxx = max(sol[x] for sol in solns) miny = min(sol[y] for sol in solns) maxy = max(sol[y] for sol in solns) print html('A nice plot of $f(x,y) = %s$ with critical points.'%str(latex(f))) Surf = plot3d(f,(x,minx-1,maxx+1),(y,miny-1,maxy+1),color='yellow') delx = (maxx-minx)/6 dely = (maxy-miny)/6 Points = [] G = Graphics() for sol in solns: z = f(x=sol[x],y=sol[y]) Points.append((sol[x],sol[y],z)) G += point3d((sol[x],sol[y],z),size=20) G += text3d('(%s,'%str(sol[x])+'%s,'%str(sol[y])+'%s)'%str(z),(sol[x]+delx,sol[y]+dely,z+1),horizontal_alignment='left', vertical_alignment='bottom') # Dots = point3d(Points,size=10) (Surf+G).show() 
       

Click to the left again to hide and once more to show the dynamic interactive window

var('x,y,z') implicit_plot3d((x^2 + y^2 + z^2), (x, -2, 2), (y, -2, 2), (z, -2, 2), plot_points=60, contour=[1,3,5], region=lambda x,y,z: x<=0.2 or y>=0.2 or z<=0.2).show()