Next: Statistical Functions
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 statistical random number sources, as well as
measurement functions exported by the measure command, and a
number of compatibility functions to support HSPICE extensions
available. These are described in sections that follow.
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).
- 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.
- 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.
Next: Statistical Functions
Up: Plots, Vectors and Expressions
Previous: Operators in Expressions
Contents
Index
Stephen R. Whiteley
2024-10-26