Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Matlab & saddle point

  1. Jul 5, 2010 #1
    1. The problem statement, all variables and given/known data

    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

    2. Relevant equations
    3. The attempt at a solution

    I will attach my code and output image

    Code (Text):
    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

    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
  2. jcsd
  3. Jul 5, 2010 #2


    User Avatar
    Science Advisor
    Homework Helper

    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?
  4. Jul 5, 2010 #3
    @ Dick thank you,

    I really have one more simple problem.

    Code (Text):

    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

    This time we are suppose to do the following:
    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!
  5. Jul 5, 2010 #4


    User Avatar
    Science Advisor
    Homework Helper

    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?
  6. Jul 5, 2010 #5
    you mean using data cursor?
  7. Jul 5, 2010 #6


    User Avatar
    Science Advisor
    Homework Helper

    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. Jul 5, 2010 #7
  9. Jul 5, 2010 #8


    User Avatar
    Science Advisor
    Homework Helper

    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?
  10. Jul 5, 2010 #9
    Hi Dick
    These are the points

    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: Jul 5, 2010
  11. Jul 5, 2010 #10


    User Avatar
    Science Advisor
    Homework Helper

    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?
  12. Jul 5, 2010 #11
    i believe so, since we are bounded by [0,2] for x and [0,2] for y

    is relative max, min means absolute?

    if so, there are two local max, and two local min, bounded by [0,2] x [0,2]?
    i think all i am missing the light blue...?

    out of those, the greatest, and lowest one are the relative extrema?
    Last edited: Jul 5, 2010
  13. Jul 5, 2010 #12


    User Avatar
    Science Advisor
    Homework Helper

    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?
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook