# sim_complex: Simulate real or complex numbers using polar form In gbutils: Simulation of Real and Complex Numbers and Small Programming Utilities

## Description

Simulate complex numbers with given distributions for the modulus and the argument and real numbers with given distributions for the absolute value and the sign. Some of the values may be partially or fully specified.

## Usage

 ```1 2 3 4 5``` ```sim_complex(abs, arg, absgen = "runif", absarg = list(0, 1), arggen = runif, argarg = list(-pi, pi), ...) sim_real(abs, sign, signprob = 0.5, absgen = "runif", absarg = list(0, 1), ...) ```

## Arguments

 `abs` vector of absolute values. `sign` vector of signs (1 or -1). `signprob` probability for a positive sign. `arg` vector of arguments (of complex numbers). `absgen` generator for the absolute values, a function or a character string naming a function. `absarg` arguments for `absgen`. `arggen` generator for the arguments of the complex numbers, a function or a string naming a function. `argarg` arguments for `arggen`. `...` not used, simplifies the call from `sim_numbers`.

## Details

`sim_real` simulates real numbers by simulating separately their absolute values and signs. `sim_complex` simulates complex numbers by simulating separately their moduli and arguments.

Both functions replace `NA`'s in argument `abs` with values simulated by the function specified by `absgen`. Arguments for `absgen` are specified by the (possibly named) list `absarg`.

Similarly, `sim_complex` replaces `NA`'s in argument `arg` with values simulated according to `arggen` and `argarg`.

Further, `sim_real` replaces `NA`'s in argument `sign` with a random sample of ones and minus ones, where the probability for the positive value is `signprob`.

Only `NA` entries in `abs`, `arg` and `sign` are filled with simulated values, the remaining entries are left unchanged. This means that some (and even all) values may be specified partially or completely.

`abs` is combined with `arg` or `sign` to create the result. These arguments are expected to be of matching shape and length but this is not enforced and the usual recycling rules will apply if this is not the case (not recommended to rely on this).

The default range for the (complex) argument is (-pi,pi).

## Value

for `sim_real`, a vector of real numbers

for `sim_complex`, a vector of complex numbers

## Note

Currently the shape of the result for `sim_real` is the same as that of argument `abs`. But `sim_complex` always returns a vector. Probably this inconsistency should be removed.

## Author(s)

Georgi N. Boshnakov

`sim_numbers` which offers more flexible interface to these functions.

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13``` ```## x[1] is fixed to 1, x[2] is negative with random magnitude: x <- sim_real(c(1,NA,NA,NA), c(1, -1, NA, NA)) ## z[1] fixed to 1, the remaining elements of z ## have random magnitude and fixed arguments: z <- sim_complex(c(1,NA,NA,NA), c(0, pi/2, pi, -pi/2)) ## without restrictions sim_complex(rep(NA,4)) sim_real(rep(NA,4)) ## moduli unrestricted; arguments restricted sim_complex(rep(NA,4), c(0, pi/2, pi, -pi/2)) ```

### Example output

```[1]  0.10088384+0.8752700i -0.02668559+0.0448358i -0.55857653-0.6677904i
[4] -0.08261941+0.8120137i
[1] -0.4919963  0.3209151  0.4622181  0.3894716
[1]  0.6155444+0.00000000i  0.0000000+0.78473629i -0.7646831+0.00000000i
[4]  0.0000000-0.01716566i
```

gbutils documentation built on May 2, 2019, 3:38 p.m.