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

  • Thread starter Thread starter jwxie
  • Start date Start date
  • Tags Tags
    Matlab Point
Click For Summary
The discussion revolves around generating contour plots for the function f(x,y) = sin(3y - x^2 + 1) + cos(2y^2 - 2x) in MATLAB and identifying saddle points. Participants share code snippets and output images, discussing how to interpret the contour plots to estimate saddle points and critical points. The "pointy-gap" between light green lines is identified as a saddle point, while darker lines indicate local maxima and minima. There is confusion about the definitions of relative versus absolute maxima and minima, but participants agree on the presence of critical points within the defined region. The conversation emphasizes the importance of using data cursors for precise coordinate estimation from contour plots.
jwxie
Messages
278
Reaction score
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
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?
 
@ 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!
 
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?
 
you mean using data cursor?
 
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.
 
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?
 
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?
 

Similar threads

  • · Replies 10 ·
Replies
10
Views
2K
Replies
3
Views
2K
Replies
3
Views
1K
Replies
6
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 8 ·
Replies
8
Views
2K
Replies
8
Views
2K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 18 ·
Replies
18
Views
3K
Replies
22
Views
3K