PEBLMath - Mathematical

This module contains compiled mathematical and statistical functions.

Abs()

Returns the absolute value of the number

Description:

Returns the absolute value of the number.

Usage:

Abs(<num>)

Example:

Abs(-300)    # ==300
Abs(23)      # ==23

See Also:

Round(), Floor(), AbsFloor(), Sign(), Ceiling()

AbsFloor()

Description:

Rounds <num> toward 0 to an integer.

Usage:

AbsFloor(<num>)

Example:

AbsFloor(-332.7)     # == -332
AbsFloor(32.88)      # == 32

See Also:

Round(), Floor(), Abs(), Sign(), Ceiling()

ACos()

Description:

Inverse cosine of <num>, in degrees.

Usage:

ACos(<num>)

See Also:

Cos(), Sin(), Tan(), ATan(), ATan()

ASin()

Description:

Inverse Sine of <num>, in degrees.

Usage:

ASin(<num>)

See Also:

Cos(), Sin(), Tan(), ATan(), ACos(), ATan()

ATan()

Description:

Inverse Tan of <num>, in degrees.

See Also:

Cos(), Sin(), Tan(), ATan(), ACos(), ATan()

Ceiling()

Description:

Rounds <num> up to the next integer.

Usage:

Ceiling(<num>)

Example:

Ceiling(33.23)       # == 34
Ceiling(-33.02)      # == -33

See Also:

Round(), Floor(), AbsFloor(), Ceiling()

Cos()

Description:

Cosine of <deg> degrees.

Example:

Cos(33.5)
  Cos(-32)

See Also:

Sin(), Tan(), ATan(), ACos(), ATan()

DegToRad()

Converts degrees to radians

Description:

Converts degrees to radians.

Usage:

DegToRad(<deg>)

Example:

DegToRad(180) # == 3.14159...

See Also:

Cos(), Sin(), Tan(), ATan(), ACos(), ATan()

Div()

Description:

Returns round(<num>/<mod>)

Usage:

Div(<num>, <mod>)

See Also:

Mod()

Exp()

Description:

$e$ to the power of <pow>.

Usage:

Exp(<pow>)

Example:

Exp(0)               # == 1
Exp(3)               # == 20.0855

See Also:

Log()

Floor()

Description:

Rounds <num> down to the next integer.

Usage:

Floor(<num>)

Example:

Floor(33.23) # == 33
Floor(3.999)         # ==3
Floor(-32.23)        # == -33

See Also:

AbsFloor(), Round(), Ceiling()

Ln()

Description:

Natural log of <num>.

Usage:

Ln(<num>)

See Also:

Log(), Log2(), LogN(), Exp()

LogN()

Description:

Log base <base> of <num>.

Usage:

LogN(<num>, <base>)

Example:

LogN(100,10) # == 2
LogN(256,2)  # == 8

See Also:

Log(), Log2(), Ln(), Exp()

Mod()

Description:

Returns <num>, <mod>, or remainder of <num>/<mod>

Usage:

Mod( <num> <mod>)

Example:

Mod(34, 10)  # == 4
Mod(3, 10)   # == 3

See Also:

Div()

NthRoot()

Description:

<num> to the power of 1/<root>.

Usage:

NthRoot(<num>, <root>)

Pow()

Description:

Raises or lowers <num> to the power of <pow>.

Usage:

Pow(<num>, <pow>)

Example:

Pow(2,6)     # == 64
Pow(5,0)     # == 1

RadToDeg()

Converts radians to degrees

Description:

Converts <rad> radians to degrees.

Usage:

RadToDeg( <rad>)

See Also:

DegToRad(), Tan(), Cos(), Sin(), ATan(), ASin(), ACos()

Random()

Returns a random number between 0 and 1

Description:

Returns a random number between 0 and 1.

Usage:

Random()

Example:

a <- Random()

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomLogNormal(), RandomNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomBernoulli()

Description:

Returns 0 with probability (1-<p>) and 1 with probability <p>.

Usage:

RandomBernoulli(<p>)

Example:

RandomBernoulli(.3)

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomLogNormal(), RandomNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomBinomial()

Description:

Returns a random number according to the Binomial distribution with probability <p> and repetitions <n>, i.e., the number of <p> Bernoulli trials that succeed out of <n> attempts.

Usage:

RandomBinomial(<p> <n>)

Example:

RandomBinomial(.3, 10) # returns number from 0 to 10

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomLogNormal(), RandomNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomDiscrete()

Description:

Returns a random integer between 1 and the argument (inclusive), each with equal probability. If the argument is a floating-point value, it will be truncated down; if it is less than 1, it will return 1, and possibly a warning message.

Usage:

RandomDiscrete(<num>)

Example:

# Returns a random integer between 1 and 30:
RandomDiscrete(30)

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomLogNormal(), RandomNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomExponential()

Description:

Returns a random number according to exponential distribution with mean <mean> (or decay 1/mean).

Usage:

RandomExponential(<mean>)

Example:

RandomExponential(100)

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomLogistic(), RandomLogNormal(), RandomNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomizeTimer()

Seeds the RNG with the current time

Description:

Seeds the RNG with the current time.

Usage:

RandomizeTimer()

Example:

RandomizeTimer()
x <- Random()

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomLogNormal(), RandomNormal(), RandomUniform(), SeedRNG()

RandomLogistic()

Description:

Returns a random number according to the logistic distribution with parameter <p>: f(x) = exp(x)/(1+exp(x))

Usage:

RandomLogistic(<p>)

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogNormal(), RandomNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomLogNormal()

Description:

Returns a random number according to the log-normal distribution with parameters <median> and <spread>. Generated by calculating $median * exp(spread * RandomNormal(0,1))$. <spread> is a shape parameter, and only affects the variance as a function of the median; similar to the coefficient of variation. A value near 0 is a sharp distribution (.1-.3), larger values are more spread out; values greater than 2 make little difference in the shape.

Usage:

RandomLogNormal(<median>, <spread>)

Example:

RandomLogNormal(5000, .1)

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomNormal()

Description:

Returns a random number according to the standard normal distribution with <mean> and <stdev>.

Usage:

RandomNormal(<mean>, <stdev>)

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomLogNormal(), RandomUniform(), RandomizeTimer(), SeedRNG()

RandomUniform()

Description:

Returns a random floating-point number between 0 and <num>.

Usage:

RandomUniform(<num>)

See Also:

Random(), RandomBernoulli(), RandomBinomial(), RandomDiscrete(), RandomExponential(), RandomLogistic(), RandomLogNormal(), RandomNormal(), RandomizeTimer(), SeedRNG()

Round()

Description:

Rounds <num> to nearest integer, or if optional <precision> argument is included, to nearest $10^{-precision}$.

Usage:

Round(<num>)
Round(<num>,<precision>)

Example:

Round(33.23)       # == 33
Round(56.65)       # == 57
Round(33.12234,2)  # == 33.12
Round(43134.23,-2) # == 43100

See Also:

Ceiling(), Floor(), AbsFloor(), ToInt()

SeedRNG()

Description:

Seeds the random number generator with <num> to reproduce a random sequence. This function can be used cleverly to create a multi-session experiment: Start by seeding the RNG with a single number for each subject; generate the stimulus sequence, then extract the appropriate stimuli for the current block. Remember to RandomizeTimer() afterward if necessary.

Usage:

SeedRNG(<num>)

Example:

##This makes sure you get the same random order
    ## across sessions for individual subjects.
     SeedRNG(gSubNum)
     stimTmp <- Sequence(1:100,1)
     stim <- Shuffle(stimTmp)
     RandomizeTimer()

See Also:

RandomizeTimer()

Sign()

Returns +1 or -1, depending on sign of argument

Description:

Returns +1 or -1, depending on sign of argument.

Usage:

Sign(<num>)

Example:

Sign(-332.1)  # == -1
Sign(65)      # == 1

See Also:

Abs()

Sin()

Description:

Sine of <deg> degrees.

Usage:

Sin(<deg>)

Example:

Sin(180)
 Sin(0)

See Also:

Cos(), Tan(), ATan(), ACos(), ATan()

Sqrt()

Description:

Square root of <num>.

Usage:

Sqrt(<num>)

Example:

Sqrt(100)  # == 10

Tan()

Description:

Tangent of <deg> degrees.

Usage:

Tan(<deg>)

Example:

Tan(180)

See Also:

Cos(), Sin(), ATan(), ACos(), ATan()

ToFloat()

Converts number to internal floating-point representation

Description:

Converts number to internal floating-point representation.

Usage:

ToFloat(<number>)

ToInteger()

Rounds a number to an integer, and changes internal representation

Description:

Rounds a number to an integer, changing internal representation.

Usage:

ToInteger(<number>)
ToInteger(<floating-point>)
ToInteger(<string-as-number>)

Example:

ToInteger(33.332)  # == 33
ToInteger("3213")  # == 3213

See Also:

Round(), Ceiling(), AbsCeiling(), Floor(), AbsFloor()

ToNumber()

Description:

Converts a variant to a number. Most useful for character strings that are interpretable as a number, but may also work for other subtypes.

Usage:

ToNumber(<string)
ToNumber(<number>)

Example:

a <- ToNumber("3232")
Print(a + 1)         # produces the output 3233.

See Also:

ToString(), ToFloat(), Round()

ToString()

Converts a numerical value to a string representation

Description:

Converts value to a string representation. Most useful for numerical values. This conversion is done automatically when strings are combined with numbers.

Usage:

ToString(<number>)
ToString(<string>)

Example:

a <- ToString(333.232)
Print(a + "111")
# produces the output '333.232111'.

See Also:

ToString(), +.