** Next:** Operators in Expressions
** Up:** Plots, Vectors and Expressions
** Previous:** Special Vectors
** Contents**
** Index**

##

Vector Expressions

An expression is an algebraic combination of already defined vectors,
scalars (a scalar is a vector of length 1), constants, operators and
functions. Some examples of expressions are:

`cos(time) + db(v(3))`

`sin(cos(log(10)))`

`TIME*rnd(v(9)) - 15*cos(vin#branch)^7.9e5`

`not ((ac3.freq[32] & tran1.time[10]) gt 3)`

One should note that there are two math subsystems in *WRspice*, the
vector system described here, and a second system for processing
equations found in device descriptions during simulation (see
2.15.1). Although the expressions are syntactically similar,
there are important differences that must be taken into account, and
one should refer to the appropriate documentation for the type of
expression.

Vector expressions can also contain calls to the built-in ``tran''
functions ordinarily used in voltage/current source specifications in
transient analysis. These are the `pulse`, `pwl`, etc.
functions described in 2.15.3. If assigned to a vector, the
vector will have a length equal to the current scale (e.g., the time
values of the last transient analysis plot), and be filled in with
values just as if the analysis was run with the given source
specification. For example

(run transient analysis: tran .1n 10n)

`let a = pulse(0 1 1n 1n)`

Vector `a` will have length 101 and contain the pulse values.
There are three such functions, `sin`, `exp`, and `gauss`, that have the same names as math functions. The math
functions always return data of the same length as the argument(s),
and take 1 argument for `sin`, `exp` and 2 for `gauss`.
When one of these names is encountered in an expression, *WRspice*
counts the arguments. If the number of arguments is 1 for `sin`/`exp` or 1 or 2 for `gauss`, the math function is called,
otherwise the tran function is called. It may be necessary to give
the `gauss` function a phony additional argument to force calling
the tran function.

Vectors can be evaluated by the shell parser by adding the prefix `$&` to the vector's name. This is useful, for example, when the
value of a vector needs to be passed to the shell's **echo**
command, or in circuit description files where vectors are to be
evaluated by the shell as the file is read. Similar to the shell
constructs, `$?&`*word* expands to 1 if *word* is a
defined vector, 0 otherwise. Also `$#&`*word* expands to
the length of *word* if *word* is a defined vector, or 0
if not found. Additionally, the notation `$&(`*vector
expression*) is replaced by the value of the vector expression. A
range specification can be added, for example `echo $&(a+1)[2]`
prints the third entry in `a+1`, or 0 if out of range. If white
space exists in the `$&(...)` construct, it probably should be
quoted. Finally, the shell recognizes the construct `$&v($`*something*) as a reference to a SPICE node voltage, so that one can
index node voltages as `echo $&v($&i)`, for example. A range
specification can be added, which can contain shell variables. This
is true for both vectors (`$&` prefix) and variables.

** Next:** Operators in Expressions
** Up:** Plots, Vectors and Expressions
** Previous:** Special Vectors
** Contents**
** Index**
Stephen R. Whiteley
2017-11-08