Monte Carlo Samples
montecarlo(F, n, Rvals, [Limits], [dist])—Returns n Monte Carlo samples created by calculating function F for variables randomly generated given the information found in matrix Rvals. With the optional matrix Limits, you can define boundaries outside of which the random variables are clipped. The normal distribution is used for generating the random variables unless specified otherwise in the vector dist.
The matrix returned by montecarlo has a row per sample with the set of the random variables generated in its first columns, and with the sample value calculated by function F in its last column.
The random variables are calculated using the following formula:
variable = mean + σ * r
The mean and σ are defined in Rvals, and r is a random number generated by the normal distribution or by the distribution defined in dist. The montecarlo function reports an error if it encounters a singularity when evaluating F for any set of random variables.
Arguments
F is a real-valued function of an arbitrary number of variables that are randomly simulated during the Monte Carlo sampling.
n is the integer number of samples.
Rvals is a matrix with a string naming each variable in the first column, their nominal (mean) value in the second column, and their standard deviation (σ) in the third column.
The units of each mean and standard deviation must be compatible with the definition of function F. For example, if F(x, y) := x + y and the two rows in Rvals have different dimensions, the montecarlo function returns a unit error.
Limits (optional) is a matrix the same length as Rvals with the lower and upper limits in the first and second columns respectively below or above which each random variable is clipped. When some of the limits are not defined, you must pad the empty elements of Limits with NaNs. Each limit must have units that are compatible with the corresponding random variable.
dist (optional) is a vector of distribution functions the same length as Rvals specifying which statistical distributions are used when generating each random variable. You can use the LogNormal, Normal, Uniform, or Weibull functions. Alternatively, you can define your own distribution functions. By default, the normal distribution is used for generating all the random variables.