
Comments:
Creating the contour plot of the peaks function. Viewing this plot,
it is easy to identify the critical points of the function. There is
one global maximum, one global minimum, two local maxima and
a local minimum. Additionally, from the color-bar that is created
with the command:
c
c
o
o
l
l
o
o
r
r
b
b
a
a
r
r, and from the values printed next to
the contour curves, it is obvious that the peaks functions around
its critical points exhibits a flatness (saddle points) (Note: the “*”
that indicate a critical point are plotted approximately); the text
next to each critical point was placed with the
g
g
t
t
e
e
x
x
t
t command.
Alternatively, we can approximate the maximum of the peaks function by
searching exhaustively the
Z
Z matrix (to do so, we should re-define the
x
x and
y
y vectors to have high dense). This is done with the following code:
Matlab’s command:
>> close all; x=-2:0.05:2; y=-4:0.25:4; [X,Y]=meshgrid(x,y);
>> Z =3*(1-X).^2.*exp(-(X.^2) - (Y+1).^2)- ...
10*(X/5-X.^3-Y.^5).*exp(-X.^2-Y.^2)-1/3*exp(-(X+1).^2-Y.^2);
>> V=-10:1:10; [c,h] = contour(x,y,Z,V); clabel(c,h), colorbar; hold
on
>> xlabel('x'); ylabel('y'); title('Contour plot of the peaks function');
>> Fmax=max(max(Z)); P=find(Z==Fmax); xy=[X(P) Y(P)];
>> plot(xy(1),xy(2),'rp', 'MarkerSize',10);
>> text(xy(1)+0.05,xy(2), 'Maximum Point');
Matlab’s response:
-2 -1.5 -1 -0.5 0 0.5 1 1.5 2
-4
-3
-2
-1
0
1
2
3
4
x
y
Contour plot of the peaks function
-6
-5
-5
-4
-4
-3
-3
-3
-3
-2
-2
-2
-2
-2
-1
-1
-1
-1
-1
-1
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
1
22
2
2
2
2
2
2
3
3
3
3
3
3
3
4
4
4
5
5
5
6
6
7
7
Maximum Point
-6
-4
-2
0
2
4
6
Komentáře k této Příručce