Contour Plot and Saddle Points in Matlab for f(x,y)

In summary, the given function has multiple relative extrema within the given square region. The contour plot shows one interior saddle point and one interior maximum point, with the rest of the critical points located on the boundary. The exact coordinates for all the critical points can be estimated from the contour plot.
  • #1
jwxie
282
0

Homework Statement



Suppose f(x,y) = sin(3y-x^2+1)+cos(2y^2-2x)
a) produce a labeled contour plot for -2 <= x <= 2, -1<= y<= 1

b) Based on the contour plot you found in a) estimate the coordinates of two saddle
points of the function in the region S defined in a). Mark the points using the Data
Cursor.

Homework Equations


The Attempt at a Solution



I will attach my code and output image

Code:
x=linspace (-2,2,25); y=linspace (-1,1,25);
[x y]=meshgrid (x,y)
z = sin(3.*y - x.^2 + 1) + cos(2.*y.^2 - 2.*x);
[C h]=contour (x,y,z); % the "handle" matrix [C h] holds the graph for labelling
clabel (C,h); % the clabel function labels the level curves

2dalvyu.jpg


I don't really know how to tell from the graph. I tried to solve it using second derivative test in matlab, but the solution is very weird, which I can't really use it at this point.

Is it true that the the gap (pointy-gap) between the two lightest green lines are the two saddle points?

Any help is appreciated. Thank you
 
Physics news on Phys.org
  • #2
Yes, it's the green "pointy-gap" parts. And good job on the MATLAB programming. If you go through on a line through the two green pointy gaps it looks like minimum. If you go through at approximately a 90 degree angle to that it looks like a maximum. Isn't that a saddle point?
 
  • #3
@ Dick thank you,

I really have one more simple problem.

Code:
x= linspace(0, 2, 15);y= linspace(0,2,15);
[x y]= meshgrid(x,y);
z=sin(3.*x+y)+ 2.*cos(x-y);
[C h] = contour(x,y,z);clabel(C,h);

hold on
surfc (x,y,z);
view ([1 1 1])
title('Yeukhon Wong, Ex. 5.3, Contour Plot of z=(3*x+y)-2*cos(x-y)');
hold off

output:
http://i49.tinypic.com/30d8dwj.jpg

This time we are suppose to do the following:
Based on the contour plot you found in a) determine whether the function has any
critical points in the square S defined in a). If there are any such points, provide
estimates from the graph for their x and y coordinates and provide a justification from
the graph as to whether these are relative maximum , minimum or saddle points.

I think the darkest red is the maximum line, and its middle point is a good estimation of point of maximum ; the darkest blue is the min line, and the last portion of the line is probably a good estimation of point of minimum . The saddle point, again, is the green pointy-gap. Actually I think a good estimation would be the sharp point.

What do you think? Thank you so much!
 
  • #4
Well, yes, it definitely looks like you have a saddle point in the greeny region. But it might be easier to read off the coordinates from a contour plot, wouldn't it?
 
  • #5
you mean using data cursor?
 
  • #6
I don't use matlab. But yes, probably. Why don't you use 'contour' again like you did before instead of 'surfc' if you want to find the x-y coordinates? It's tough to read off the x-y coordinates from a 3-d plot.
 
  • #8
jwxie said:
http://i49.tinypic.com/2u5td1l.jpg

i am confused by how to estimate a good point of max and min

It looks to me like you've got only one true critical point inside that region. And it's a saddle again. Doesn't it appear so to you? The rest of the critical points are on the boundary. It's not so hard to guess the min and max along the boundary from the contour plot, is it?
 
  • #9
Hi Dick
These are the points
http://i50.tinypic.com/2jayxvm.jpg

The green is saddle
the one in red is max
the blue is min

what do you think? thank you.

relative max / min - is it the same as saying absolute?
if so, then the greatest red is the absolute max
 
Last edited:
  • #10
Yes, green looks like saddle, red in the lower left looks like interior max. The boundary behavior looks complicated. Do you only need the interior critical points?
 
  • #11
i believe so, since we are bounded by [0,2] for x and [0,2] for y

Based on the contour plot you found in a) determine whether the function has any
critical points in the square S defined in a). If there are any such points, provide
estimates from the graph for their x and y coordinates and provide a justification from
the graph as to whether these are relative maximum , minimum or saddle points.

is relative max, min means absolute?

if so, there are two local max, and two local min, bounded by [0,2] x [0,2]?
http://i50.tinypic.com/2jayxvm.jpg
i think all i am missing the light blue...?

out of those, the greatest, and lowest one are the relative extrema?
 
Last edited:
  • #12
Oh, I don't know. Looks like you have one interior max and one interior saddle point. At this point you can probably guess the rest as well as I can. Run around the exterior and figure out where the local mins and maxs are. It's not so hard, and it's guesswork. If you increase the resolution of your contour plot things might change, right?
 

FAQ: Contour Plot and Saddle Points in Matlab for f(x,y)

What is Matlab and how is it used in finding saddle points?

Matlab is a high-level programming language and interactive environment used for numerical computation, data analysis, and visualization. In finding saddle points, Matlab is used as a tool for solving optimization problems and determining the critical points of a function.

How do you find a saddle point in Matlab?

To find a saddle point in Matlab, you can use the "fminsearch" function. This function uses the downhill simplex method to find the minimum of a user-defined function, which in the case of saddle points, would be the critical points of the function.

Can Matlab handle multi-dimensional saddle points?

Yes, Matlab can handle multi-dimensional saddle points. It has built-in functions such as "fmincon" and "fminunc" that allow for the optimization of functions with multiple variables, making it suitable for finding saddle points in multi-dimensional spaces.

Is Matlab the only tool for finding saddle points?

No, Matlab is not the only tool for finding saddle points. There are other programming languages and software packages that can also be used for finding saddle points, such as Python, R, and Mathematica. However, Matlab is a popular choice due to its user-friendly interface and extensive library of optimization functions.

Can I use Matlab to visualize saddle points?

Yes, Matlab can be used to visualize saddle points. It has built-in functions for creating 2D and 3D plots, making it easy to visualize the critical points of a function, including saddle points. Additionally, Matlab also has tools for creating contour plots, which can be useful for visualizing saddle points in multi-dimensional spaces.

Back
Top