Matlab  Homework

 

 

In this assignment, you will use Matlab to visualize the solution of the problem of finding minima and maxima of a function of two variables. Below is an example of using Matlab plotting routines.

 

 

Surface and Contour Plots



 

Use the “mesh” function to produce a surface plot of z=x exp(y^2 ).

Here is an example (the >> symbols denote the Matlab prompt):

 

>> [X,Y]=meshgrid(-2:.1:2);

>>Z=X.*exp(-Y.^2);

>>mesh(X,Y,Z)

 

The first line creates axes with –2 < x < 2 and –2 < y < 2, and tic marks separated by 0.1. 

The second line defines the function, and the third line plots the surface.

You can also try the “surf” in place of “mesh” to see how the surface plotting routine works in Matlab.

 

 

To produce a contour plot of the same function, using 20 equally spaced contours, do:

 

>>contour(X,Y,Z,20); axis square; colorbar

 

The last two commands generate the plot with unit aspect ratio and a color bar for the scale.

 

 

 

 

Assignment:

 

a) Find and classify all critical points of the function

 

f(x, y) =(3 x + 1) (2 y + 1) exp(-x^2 - y^2)

 

in D = [-3,3] x [-3,3].

 

Find also the minimum and the maximum value of f(x, y) in D.

 

b) Generate a surface and a contour plot of f(x,y) over D and verify that your answer in part a) agrees with these plots.

 

 

August 28, 2007