Learn R Programming

mosaic (version 0.3-13)

rfun: Generate a natural-looking function

Description

Produce a random function that is sum of gaussians

rpoly2 generates a random 2nd degree poly of 2 vars (as a function)

Usage

rfun(vars = ~x & y, seed = NULL, n = 0)

rpoly2(seed = NULL)

Arguments

vars
a formula; the LHS is empty and the RHS indicates the variables used for input to the function (separated by &)
seed
seed for random number generator, passed to set.seed.
n
the number of gaussians. By default, this will be selected randomly.

Value

  • a function with the appropriate number of inputs

    a function defined by a 2nd degree polynomial of 2 variables with coefficients selected randomly according to a Unif(-1,1) distribution.

Details

rfun is an easy way to generate a natural-looking but random function with ups and downs much as you might draw on paper. In two variables, a good way to produce a random landscape that is smooth. Things happen in the domain -5 to 5. The function is pretty flat outside of that. Use seed to create a fixed function that will be the same for everybody

Examples

Run this code
f <- rfun( ~ u & v)
plotFun(f(u,v)~u&v,u=range(-5,5),v=range(-5,5))
myfun <- rfun(~ u & v, seed=1959)

Run the code above in your browser using DataLab