diary
Your MATLAB session has timed out. All license keys have been returned.
help peaks
PEAKS A sample function of two variables.
PEAKS is a function of two variables, obtained by translating and
scaling Gaussian distributions, which is useful for demonstrating
MESH, SURF, PCOLOR, CONTOUR, etc.
There are several variants of the calling sequence:
Z = PEAKS;
Z = PEAKS(N);
Z = PEAKS(V);
Z = PEAKS(X,Y);
PEAKS;
PEAKS(N);
PEAKS(V);
PEAKS(X,Y);
[X,Y,Z] = PEAKS;
[X,Y,Z] = PEAKS(N);
[X,Y,Z] = PEAKS(V);
The first variant produces a 49-by-49 matrix.
The second variant produces an N-by-N matrix.
The third variant produces an N-by-N matrix where N = length(V).
The fourth variant evaluates the function at the given X and Y,
which must be the same size. The resulting Z is also that size.
The next four variants, with no output arguments, do a SURF
plot of the result.
The last three variants also produce two matrices, X and Y, for
use in commands such as PCOLOR(X,Y,Z) or SURF(X,Y,Z,DEL2(Z)).
If not given as input, the underlying matrices X and Y are
[X,Y] = MESHGRID(V,V)
where V is a given vector, or V is a vector of length N with
elements equally spaced from -3 to 3. If no input argument is
given, the default N is 49.
Reference page in Help browser
doc peaks
x=linspace(-3,3,200); [X,Y]=meshgrid(x,x);
z=peaks(X,Y);
surf(x,x,z), shading interp, light
mesh(x,x,z);
contour(x,x,z), axis equal
contour(x,x,z,20), axis equal
contourf(x,x,z,20), axis equal, colorbar
axis image
contour(x,x,z,[-2 1 0 1 2])
contour3(x,x,z,20), axis equal
cla
contour3(x,x,z,20), axis equal
surf(x,x,z), shading interp, light
axis off
hold
Current plot held
contour3(x,x,z,20)
help gradient
GRADIENT Approximate gradient.
[FX,FY] = GRADIENT(F) returns the numerical gradient of the
matrix F. FX corresponds to dF/dx, the differences in x (horizontal)
direction. FY corresponds to dF/dy, the differences in y (vertical)
direction. The spacing between points in each direction is assumed to
be one. When F is a vector, DF = GRADIENT(F)is the 1-D gradient.
[FX,FY] = GRADIENT(F,H), where H is a scalar, uses H as the
spacing between points in each direction.
[FX,FY] = GRADIENT(F,HX,HY), when F is 2-D, uses the spacing
specified by HX and HY. HX and HY can either be scalars to specify
the spacing between coordinates or vectors to specify the
coordinates of the points. If HX and HY are vectors, their length
must match the corresponding dimension of F.
[FX,FY,FZ] = GRADIENT(F), when F is a 3-D array, returns the
numerical gradient of F. FZ corresponds to dF/dz, the differences
in the z direction. GRADIENT(F,H), where H is a scalar,
uses H as the spacing between points in each direction.
[FX,FY,FZ] = GRADIENT(F,HX,HY,HZ) uses the spacing given by
HX, HY, HZ.
[FX,FY,FZ,...] = GRADIENT(F,...) extends similarly when F is N-D
and must be invoked with N outputs and either 2 or N+1 inputs.
Note: The first output FX is always the gradient along the 2nd
dimension of F, going across columns. The second output FY is always
the gradient along the 1st dimension of F, going across rows. For the
third output FZ and the outputs that follow, the Nth output is the
gradient along the Nth dimension of F.
Examples:
[x,y] = meshgrid(-2:.2:2, -2:.2:2);
z = x .* exp(-x.^2 - y.^2);
[px,py] = gradient(z,.2,.2);
contour(z), hold on, quiver(px,py), hold off
Class support for input F:
float: double, single
See also diff, del2.
Reference page in Help browser
doc gradient
hold
Current plot held
hold
Current plot held
hold
Current plot released
[px,py]=gradient(z);
surf(x,x,px), shading interp, light
surf(x,x,py), shading interp, light
quiver(X,Y,px,py);
xx=linspace(-3,3,20); [XX,YY]=meshgrid(xx,xx);
zz=peaks(XX,YY);
[px,py]=gradient(zz);
quiver(XX,YY,px,py);
hold
Current plot held
contourf(x,x,z,20), axis equal, colorbar
contour(x,x,z,20), axis equal
hold
Current plot held
quiver(XX,YY,px,py);
clear all
x=linspace(-2,2,200); [X,Y]=meshgrid(x,x);
z=X.^2+Y;
surf(x,x,z), shading float
??? Error using ==> shading at 106
Shading methods are flat, faceted, and interp.
surf(x,x,z), shading flat
contourf(x,x,z,15), axis equal, colorbar
z=X.^2+4*Y.^2;
surf(x,x,z), shading flat
axis equal
contourf(x,x,z,15), axis equal, colorbar
contourf(x,x,z,15), colorbar
z=X.^2-Y.^2;
contourf(x,x,z,15), colorbar
surf(x,x,z), shading flat, light
hold, contour3(x,x,z,20)
Current plot held
clear all
theta=linspace(0,2*pi,300); phi=linspace(0,pi,300); [T,P]=meshgrid(theta,phi);
R=2;
x=R*sin(P).*cos(T); y=R*sin(P).*sin(T); z=R*cos(P);
surf(x,y,z), shading flat, light
axis equal
axis off
theta=linspace(0,2*pi,300); phi=linspace(0,2*pi,300); [T,P]=meshgrid(theta,phi);
R=4; r=2;
x=cos(T).*(R+r*cos(P)); y=sin(T).*(R+r*cos(P)); z=r*sin(P);
surf(x,y,z), shading flat, light
axis equal, axis off
r=2*log(1+T);
x=cos(T).*(R+r.*cos(P)); y=sin(T).*(R+r.*cos(P)); z=r.*sin(P);
surf(x,y,z), shading flat, light, axis equal, axis off
R=4*log(1+T);
x=cos(T).*(R+r.*cos(P)); y=sin(T).*(R+r.*cos(P)); z=r.*sin(P);
surf(x,y,z), shading flat, light, axis equal, axis off
diary