Surface Plot
Surface Plot
Surface Plot
We will plot the surface of equation z = x2 y 2 as well as the level curves for c = 2, 1, 0, 1, 2. In MATLAB, to get a rectangular domain 2 x 2, 2 y 2 in steps of 0.2, we use the command >> [x, y] = meshgrid([-2:0.2:2],[-2:0.2:2]); We calculate z = x2 y 2 as follows (note the use of .s). >> z = x.^2 - y.^2; To obtain the surface plot, we use either of the following. >> mesh(x,y,z) >> surf(x,y,z) %this one has colors
To plot the level curves for c = 2, 1, 0, 1, 2, we use the following commands. >> [c,h]=contour(x,y,z,[-2,-1,0,1,2]); >> clabel(c,h) %this labels the c values on the contour plot
2
0
1.5 4 1 3
2
-2
0
-2
-1
-1
0
1
2 1
0.5
0
0 -1 -2 -3 -4 2 1 0 0 -1 -2 -2 -1 1 2
0
0
-0.5
1
-1
-1
0
-1.5
-1
-2
-2
-1
-0.5 0 0.5 1 1.5 2
-2 -2
-1.5
-1
The plot of the surface of equation 20 3 + x2 + 2y 2 as well as the level curves for c = 1, 2, 3, 4, 5 are shown below. z=
5
7 6 5
2
2
3
1 4 0 3
5
2 1 0 5 5
-1
4
-2
1
2
1
-3
-4 0 0 -5 -5 -5 -5 -4 -3 -2 -1 0