peaks

Sample function of two variables made of Gaussian peaks, used to try out surface plots.

Category: Graphics > 2-D and 3-D Plots

Syntax

Z = peaks

Returns the 49-by-49 values of the function on a default grid from -3 to 3.

Z = peaks(n)

Returns an n-by-n matrix over the same range.

Z = peaks(V)

Uses the vector V for both the x and y coordinates.

Z = peaks(X, Y)

Evaluates the function at the matrices X and Y.

[X, Y, Z] = peaks(___)

Also returns the grid coordinates.

Description

The function is a mix of three Gaussians, 3*(1-x).^2.*exp(-x.^2-(y+1).^2) - 10*(x/5-x.^3-y.^5).*exp(-x.^2-y.^2) - exp(-(x+1).^2-y.^2)/3. It has several peaks and valleys, which makes it a handy test for surf, mesh, contour and colormaps. The highest value is about 8.1.

Input arguments

n
Grid size, 49 by default.
V
Vector of coordinates for both directions.
X, Y
Matrices of coordinates of the same size.

Output arguments

Z
Function values, a matrix of the size of the grid.
X, Y
Grid coordinates from meshgrid.

Example

Values on a small grid

Z = peaks(5)
max(max(peaks))
Output
Z = 5×5

    0.0001    0.0042   -0.2450   -0.0298   -0.0000
   -0.0005    0.3265   -5.6803   -0.4405    0.0036
   -0.0365   -2.7736    0.9810    3.2695    0.0331
   -0.0031    0.4784    7.9966    1.1853    0.0044
    0.0000    0.0312    0.2999    0.0320    0.0000
ans = 8.0752

See also

surf mesh contour meshgrid