Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

peaks

Peaks Function (Matlab Style)


Description

An example functions in two variables, with peaks.

Usage

peaks(v = 49, w)

Arguments

v

vector, whose length will be used, or a natural number.

w

another vector, will be used in meshgrid(x,y).

Details

peaks is a function of two variables, obtained by translating and scaling Gaussian distributions, which is useful for demonstrating three-dimensional plots.

Value

Returns three matrices as a list with X, Y, and Z components, the first two being the result of the meshgrid function, and Z the application of the following function at the points of X and 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)

Note

The variant that peaks() will display the 3-dim. graph as in Matlab is not yet implemented.

See Also

Examples

peaks(3)
## Not run: 
P <- peaks()
x <- P$X[1,]; y <- P$Y[, 1]
persp(x, y, P$Z)

## End(Not run)

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.