Next: Expression Lists
Up: Plots, Vectors and Expressions
Previous: Operators in Expressions
Contents
Index
Math Functions
There are a number of built-in math functions which take and return
vectors. Generally, these functions operate on the supplied vector
term-by-term, returning a vector of the same length as that given.
The pre-defined functions available are listed below. In general, all
operations and functions will work on either real or complex values,
providing complex data output when necessary.
In addition, there are a number of HSPICE compatibility functions
available, described in the following section.
It should be noted that the mathematics subsystem used to evaluate
expressions in voltage/current sources is completely different. In
that subsystem, functions take real valued scalars as input. Although
many of the same functions are available in both systems, the
correspondence is not absolute.
-
- abs(vector)
Each point of the returned vector is the absolute value of the
corresponding point of vector. This is the same as the mag function.
- acos(vector)
Each point of the returned vector is the arc-cosine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- acosh(vector)
Each point of the returned vector is the arc-hyperbolic cosine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- asin(vector)
Each point of the returned vector is the arc-sine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- asinh(vector)
Each point of the returned vector is the arc-hyperbolic sine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- atan(vector)
Each point of the returned vector is the arc-tangent of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- atanh(vector)
Each point of the returned vector is the arc-hyperbolic tangent of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- cbrt(vector)
Each point of the returned vector is a cube root of the corresponding
point of vector.
- ceil(vector)
This function returns the smallest integer greater than or equal to the
argument, in the manner of the C function of the same name. If the
argument is complex, the operation is performed on both components,
with the result being complex. This operation is performed at each
point in the given vector.
- cos(vector)
Each point of the returned vector is the cosine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- cosh(vector)
Each point of the returned vector is the hyperbolic cosine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- db(vector)
Each point of the returned vector is the decibel value (20 *
log10(mag)) of the corresponding point of vector.
- deriv(vector)
This calculates the derivative of the given vector, using
numeric differentiation by interpolating a polynomial. However, it
may be prone to numerical errors, particularly with iterated
differentiation. The implementation only calculates the derivative
with respect to the real component of that vector's scale. The
polynomial degree used for differentiation can be specified with the
dpolydegree variable. If dpolydegree is unset, the value
taken is 2 (quadratic). The valid range is 0-7.
- erf(vector)
Each point of the real returned vector is the error function of the
corresponding real point of vector. Unlike most of the
functions, this function operates only on the real part of a complex
argument, and always returns a real valued result.
- erfc(vector)
Each point of the real returned vector is the complementary error
function of the corresponding real point of vector. Unlike most
of the functions, this function operates only on the real part of a
complex argument, and always returns a real valued result.
- exp(vector)
Each point of the returned vector is the exponentiation (ex)
of the corresponding point of vector.
- fft(vector)
The fft function returns the Fourier transform of vector, using the present scale of vector. The scale should
be linear and monotonic. The length is zero-padded to the next binary
power. Only the real values are considered in the transform, so that
the negative frequency terms are the complex conjugates of the
positive frequency terms. The negative frequency terms are not
included in the (complex) vector returned. A scale for the returned
vector is also generated and linked to the returned vector.
- floor(vector)
This function returns the largest integer less than or equal to the
argument, in the manner of the C function of the same name. If the
argument is complex, the operation is performed on both components,
with the result being complex. The operation is performed at each
point of the argument.
- gamma(vector)
This function returns the gamma value of the real argument (or the
real part of a complex argument), returning real data.
- ifft(vector)
The ifft function returns the inverse Fourier transform of vector, using the present scale of vector. The scale
should be linear and monotonically increasing, starting at 0.
Negative frequency terms are assumed to be complex conjugates of the
positive frequency terms. The length is zero-padded to the next
binary power. A scale for the returned vector is also generated and
linked to the returned vector. The returned vector is always real.
- im(vector)
Each point of the real returned vector is the imaginary part of the
corresponding point of the given vector. This function can
also be calld as ``imag''.
- int(vector)
The returned value is the nearest integer to the argument, in the
manner of the C rint function. If the argument is complex, the
operation is performed on each component with the result being
complex. The operation is performed at each point in the argument.
- integ(vector)
The returned vector is the (trapezoidal) integral of vector
with respect to the vector's scale (which must exist).
- interpolate(vector)
This function takes its data and interpolates it onto a grid which is
determined by the default scale of the currently active plot. The
degree is determined by the polydegree variable. This is useful
if the argument belongs to a plot which is not the current one. Some
restrictions are that the current scale, the vector's scale,
and the argument must be real, and that either both scales must be
strictly increasing or strictly decreasing if they differ.
This function is used when operating on vectors from different plots,
where the scale may differ. For example, the x-increment may be
different, or the points may correspond to internal time points from
transient analysis rather than the user time points. Without
interpolation, operations are generally term-by-term, padding when
necessary. This result is probably not useful if the scales are
different.
For example, the correct way to print the difference between a vector
in the current plot and a vector from another plot with a different
scale would be
print v(2) - interpolate(tran2.v(2))
- j(vector)
Each point of the returned vector is the corresponding point of
vector multiplied by the square root of -1.
- j0(vector)
Each point of the real returned vector is the Bessel order 0 function
of the corresponding real point of vector. Unlike most of the
functions, this function operates only on the real part of a complex
argument, and always returns a real valued result.
- j1(vector)
Each point of the real returned vector is the Bessel order 1 function
of the corresponding real point of vector. Unlike most of the
functions, this function operates only on the real part of a complex
argument, and always returns a real valued result.
- jn(n, vector)
Each point of the real returned vector is the Bessel order n
function of the corresponding real point of vector, with n
the truncated integer value of the imaginary part of vector.
Recall that for most math function, comma argument separators
are interpreted as the comma operator
a,b = (a + j*b)
which resolves to a single complex value. Thus, since scalars are
extended to vectors by replicating the value, on calling this function
as, for example, ``jn(v,3)'' where v is a real vector, the
return will be j3(v) for each element of v.
If vector is real, the effective value of n is 0.
- length(vector)
This function returns the scalar length of vector.
- ln(vector)
Each point of the returned vector is the natural logarithm of the
corresponding point of vector.
- log(vector)
Each point of the returned vector is the base-10 logarithm of the
corresponding point of vector.
- log10(vector)
Each point of the returned vector is the natural logarithm of the
corresponding point of vector (same as ln).
Warning: in releases prior to 3.2.15, the log function
returned the base-10 logarithm (as in Berkeley SPICE3). This was
changed in 3.2.15 for compatibility with device simulation models
intended for HSPICE.
- mag(vector)
Each point of the real returned vector is the magnitude of the
corresponding point of vector.
- mean(vector)
This function returns the (scalar) mean value of the elements in
the argument.
- norm(vector)
Each point of the returned vector is the corresponding point of the
given vector multiplied by the magnitude of the inverse of the largest
value in the given vector. The returned vector is therefor normalized
to 1 (i. e, the largest magnitude of any component will be 1).
- ogauss(vector)
This function returns a real vector which contains normally
distributed random values. The standard deviation and mean are set by
the corresponding real and imaginary coefficients of vector
term-by-term, and the mean is zero if vector is real. The
random number sequence can be reset with the seed command.
- ph(vector)
Each point of the real returned vector is the phase of the
corresponding point of vector, expressed in radians.
- pos(vector)
This function returns a real vector which is 1 if the corresponding
element of the argument has a non-zero real part, and 0 otherwise.
- re(vector)
Each point of the real returned vector is the real part of the
corresponding point of vector. The function can also be called
as ``real''.
- rms(vector)
This function integrates the magnitude-squared of vector over
the vector's scale (using trapezoidal integration), divides by
the scale range, and returns the square root of this result. If the
vector has no scale, the square root of the sum of the squares
of the elements is returned.
- rnd(vector)
This function returns a vector which contains random values between 0
and the corresponding element of vector. If vector is
complex then the random value is also complex. The random number
sequence can be reset with the seed command.
- sgn(vector)
Each value of the output vector is 1, 0, or -1 according to whether
the corresponding value of the input vector is larger than 0, equal to
zero, or less than 0. The vector can be complex or real.
- sin(vector)
Each point of the returned vector is the sine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- sinh(vector)
Each point of the returned vector is the hyperbolic sine of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- sqrt(vector)
Each point of the returned vector is the square root of the
corresponding point of vector.
- sum(vector)
This function returns the (scalar) sum of the elements of vector.
- tan(vector)
Each point of the returned vector is the tangent of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- tanh(vector)
Each point of the returned vector is the hyperbolic tangent of the
corresponding point of vector. This and all trig functions
operate with radians unless the units variable is set to degrees.
- unitvec(vector)
This function returns a real vector consisting of all 1's, with length
equal to the magnitude of the first element of the argument.
- vector(vector)
This function returns a vector consisting of the integers from 0 up to the
magnitude of the first element of its argument.
- y0(vector)
Each point of the real returned vector is the Neumann order 0 function
of the corresponding real point of vector. Unlike most of the
functions, this function operates only on the real part of a complex
argument, and always returns a real valued result.
- y1(vector)
Each point of the real returned vector is the Neumann order 1 function
of the corresponding real point of vector. Unlike most of the
functions, this function operates only on the real part of a complex
argument, and always returns a real valued result.
- yn(n, vector)
Each point of the real returned vector is the Neumann order n
function of the corresponding real point of vector, with n
the truncated integer value of the imaginary part.
Recall that for most math function, comma argument separators
are interpreted as the comma operator
a,b = (a + j*b)
which resolves to a single complex value. Thus, since scalars are
extended to vectors by replicating the value, on calling this function
as, for example, ``yn(v,3)'' where v is a real vector, the
return will be y3(v) for each element of v.
If vector is real, the effective value of n is 0.
In addition, the following functions are available, for compatibility
with HSPICE.
These functions differ from other math functions in that they take
multiple comma-separated arguments, Other math functions
internally accept a single argument, but if there are multiple
comma-separated terms, they will be collapsed into a single
argument through evaluation of the comma operator
a,b = (a + j*b)
which yields a complex value. This will not be true in the functions
listed below - the comma really means separate arguments in this
case.
The first group of functions are equivalent to the HSPICE Monte Carlo
functions that are called in .param lines in HSPICE. In
WRspice, these are regular math functions.
These functions will return mean values unless enabled. They are
enabled while in Monte Carlo analysis, or if the random variable
is set, either from the command line or from a .options line in
a circuit file.
-
- unif(nom, rvar)
Uniform relative random value function.
This returns a vector the same length as nom, complex or real as
nom. If the length of rvar is less than the length of
nom, rvar is extended by replicating the highest index
value of rvar.
If we are not running Monte Carlo analysis, and the random
variable is not set, the return vector is the same as nom (no
random values are generated). Otherwise the return vector contains
uniformly distributed random values, each in the range [nom -
nom*rvar, nom + nom*rvar]
term-by-term.
Below, random is a pseudo-function that returns a random number
between -1 and 1.
- If nom is complex and var is complex:
out[i].real = nom[i].real*(1 + random()*rvar[i].real)
out[i].imag = nom[i].imag*(1 + random()*rvar[i].imag)
- If nom is complex and var is real:
out[i].real = nom[i].real*(1 + random()*rvar[i])
out[i].imag = nom[i].imag*(1 + random()*rvar[i])
- If nom is real and var is complex:
out[i] = nom[i].real*(1 + random()*rvar[i].real)
- If nom is real and var is real:
out[i] = nom[i]*(1 + random()*rvar[i])
- aunif(nom, var)
Uniform absolute random value function.
This returns a vector the same length as nom, complex or real
as nom. If the length of var is less than the length of
nom, var is extended by replicating the highest index
value of var.
If we are not running Monte Carlo analysis, and the random
variable is not set, the return vector is the same as nom (no
random values are generated). Otherwise The return vector contains
uniformly distributed random values, each in the range [nom -
var, nom + var] term-by-term.
Below, random is a pseudo-function that returns a random number
between -1 and 1.
- If nom is complex and var is complex:
out[i].real = nom[i].real + random()*var[i].real
out[i].imag = nom[i].imag + random()*var[i].imag
- If nom is complex and var is real:
out[i].real = nom[i].real + random()*var[i]
out[i].imag = nom[i].imag + random()*var[i]
- If nom is real and var is complex:
out[i] = nom[i].real + random()*var[i].real
- If nom is real and var is real:
out[i] = nom[i] + random()*var[i]
- gauss(nom, rvar,
sigma)
Gaussian relative random number generator.
This returns a vector the same length as nom, complex or real
as nom. If the length of rvar is less than the length
of nom, rvar is extended by replicating the highest
index value of rvar. Only the zero'th (real) component of
sigma is used.
If fewer than three arguments are given, this reverts to the original
WRspice gauss function (now called ogauss).
If we are not running Monte Carlo analysis, and the random
variable is not set, the return vector is the same as nom (no
random values are generated). Otherwise the return vector contains
gaussian-distributed random values. The (scalar) sigma value
gives the specified sigma of the rvar data, generally 1 or 3.
Below, the pseudo-function gauss returns a gaussian random
number with zero mean and unit standard deviation.
- If nom is complex and var is complex:
out[i].real = nom[i].real*(1 + gauss()*rvar[i].real/sigma)
out[i].imag = nom[i].imag*(1 + gauss()*rvar[i].imag/sigma)
- If nom is complex and var is real:
out[i].real = nom[i].real*(1 + gauss()*rvar[i]/sigma)
out[i].imag = nom[i].imag*(1 + gauss()*rvar[i]/sigma)
- If nom is real and var is complex:
out[i] = nom[i].real*(1 + gauss()*rvar[i].real/sigma)
- If nom is real and var is real:
out[i] = nom[i]*(1 + gauss()*rvar[i]/sigma)
- agauss(nom, var,
sigma)
Gaussian absolute random number generator.
This returns a vector the same length as nom, complex or real
as nom. If the length of var is less than the length of
nom, var is extended by replicating the highest index
value of var. Only the zero'th (real) component of sigma is used.
If we are not running Monte Carlo analysis, and the random
variable is not set, the return vector is the same as nom (no
random values are generated). Otherwise the return vector contains
gaussian-distributed random values. The (scalar) sigma value
gives the specified sigma of the var data, generally 1 or 3.
Below, the pseudo-function gauss returns a gaussian random
number with zero mean and unit standard deviation.
- If nom is complex and var is complex:
out[i].real = nom[i].real + gauss()*var[i].real/sigma
out[i].imag = nom[i].imag + gauss()*var[i].imag/sigma
- If nom is complex and var is real:
out[i].real = nom[i].real + gauss()*var[i]/sigma
out[i].imag = nom[i].imag + gauss()*var[i]/sigma
- If nom is real and var is complex:
out[i] = nom[i].real + gauss()*var[i].real/sigma
- If nom is real and var is real:
out[i] = nom[i] + gauss()*var[i]/sigma
- limit(nom, var)
Random limit function.
This returns a vector the same length as nom, complex or real
as nom. If the length of var is less than the length of
nom, var is extended by replicating the highest index
value of var.
If we are not running Monte Carlo analysis, and the random
variable is not set, the return vector is the same as nom (no
random values are generated). Otherwise the return vector contains
either nom + var or nom - var determined
randomly, term-by-term.
- If nom is complex and var is complex:
out[i].real = nom[i].real +/- var[i].real randomly
out[i].imag = nom[i].imag +/- var[i].imag randomly
- If nom is complex and var is real:
out[i].real = nom[i].real +/- var[i] randomly
out[i].imag = nom[i].imag +/- var[i] randomly
- If nom is real and var is complex:
out[i] = nom[i].real +/- var[i].real randomly
- If nom is real and var is real:
out[i] = nom[i] +/- var[i] randomly
The remaining functions are for HSPICE compatibility, but are not
exclusive to the HSPICE Monte Carlo analysis. These also have
multiple arguments.
-
- pow(x, y)
This returns a real or complex vector the same length as x.
If the length of y is less than the length of x, y
is extended by replicating the highest index value of y.
This returns a vector containing xy computed using complex values,
term-by-term, however if y is real, is is truncated to an
integer value.
- If x is complex and y is complex:
out = xy (same as
^ operator)
- If x is complex and y is real:
out = x(int)y (same as
^ operator, but y
is truncated to integer)
- If x is real and y is complex:
out = xy (same as
^ operator)
- If x is real and y is real:
out = x(int)y (same as
^ operator, but y
is truncated to integer)
- pwr(x, y)
This returns a real vector the same length as x. If the
length of y is less than the length of x, y is
extended by replicating the highest index value of y.
- If x is complex and y is complex:
out[i] = (sign of x[i].real)(mag(x[i])
^
y[i].real)
- If x is complex and y is real:
out[i] = (sign of x[i].real)(mag(x[i])
^
y[i])
- If x is real and y is complex:
out[i] = (sign of x[i].real)(abs(x[i])
^
y[i].real)
- If x is real and y is real:
out[i] = (sign of x[i])(abs(x[i])
^ y[i])
- sign(x, y)
This returns a vector the same length as x, complex or real as
x. If the length of y is less than the length of x, y is extended by replicating the highest index value of
y.
- If x is complex and y is complex:
out[i].real = (sign of y[i].real)abs(x[i].real)
out[i].imag = (sign of y[i].imag)abs(x[i].imag)
- If x is complex and y is real:
out[i].real = (sign of y[i])abs(x[i].real)
out[i].imag = (sign of y[i])abs(x[i].imag)
- If x is real and y is complex:
out[i] = (sign of y[i].real)abs(x[i])
- If x is real and y is real:
out[i] = (sign of y[i])abs(x[i])
Next: Expression Lists
Up: Plots, Vectors and Expressions
Previous: Operators in Expressions
Contents
Index
Stephen R. Whiteley
2012-09-24