## Expressions

CircuitLab gives you the ability to create and edit custom mathematical expressions to explore interesting things about your circuit. Expressions can be used in the output boxes for all simulation types. The simplest expressions are populated by CircuitLab by clicking on a node or a circuit terminal while a simulation box is visible (see plotting outputs).

Clicking on a node or wire to plot will create the expression

`V(NAME)`
which will plot the voltage at node NAME.

Clicking on an circuit terminal will create the expression

`I(NAME.TERMINAL)`
which will plot the current going into the TERMINAL of element NAME.

(Note: the current relative to a terminal is always defined as positive going into that terminal. To plot the current going out of a terminal, edit the expression to have a minus sign in front!)

Expressions support the basic mathematical expressions +,-,*, and /. For example, to plot the difference between the voltage a node named V_Plus and the voltage at a node named V_Minus, do:

`V(V_Plus)-V(V_Minus)`

Other powerful expressions include the ability to measure power dissipation, such as

`P(Q1)`
to compute the power dissipated in transistor Q1.

A complete description of supported expressions is below:

Operators for Expressions
Operator Description Contexts*
-SubtractionABCD
*MultiplicationABCD
/DivisionABCD
^ or POW(x,n)ExponentiationABCD
<1 if x < y; 0 otherwiseABCD
>1 if x > y; 0 otherwiseABCD
ABS(x)Absolute value of xABCD
ACOS(x)Inverse cosine of xABCD
ACOSH(x)Inverse hyperbolic cosine of xABCD
ASIN(x)Inverse sine of xABCD
ASINH(x)Inverse hyperbolicsine of xABCD
ATAN(x)Inverse tangent of xABCD
ATANH(x)Inverse hyperbolic tangent of xABCD
CONJ(x)Complex conjugate of number x__C_
COS(x)Cosine of xABCD
COSH(x)Hyperbolic cosine of xABCD
DB(x)Number x in decibels. In the case where x has units of power (Watts), the DB() operator does 10*LOG(x). In all other cases it does 20*LOG(x).ABCD
EXP(x)Exponential functionABCD
I(NAME.TERMINAL)Current into TERMINAL of element NAME_BCD
IF(t, x, y)x if t > 0; y otherwiseABCD
IMAG(x)Imaginary part of complex number x__C_
LIMIT(a, x, y)a, bounded by lower limit x and upper limit yABCD
LN(x)Natural logarithm of xABCD
LOG(x)Base 10 logarithm of xABCD
MAG(x)Magnitude of complex number x__C_
MAX(x, y)The more positive of x and yABCD
MIN(x, y)The more negative of x and yABCD
P(NAME)Power dissipated in circuit element NAME_BC_
PH(x)Phase of complex number x in radians__C_
PHDEG(x)Phase of complex number x in degrees__C_
PWL(t1,x1,t2,x2,...)Piece-wise linear signal with value x1 at t=t1, and so on, with linear interpolation between points. If t1 is not 0, then the point 0,0 is implied. All t1...tn must be in ascending order. All tn and xn must be fixed values -- they can not contain further computation._BCD
PWLREPEAT(t1,x1,t2,x2,...)Like PWL, but repeats indefinitely. The signal to be repeated spans from t=0 to the final specified time point._BCD
PWS(t1,x1,t2,x2,...)Piece-wise step signal with value x1 at t=t1, and so on, changing in stepwise fashion at each timestep. If t1 is not 0, then the point 0,0 is implied. All t1...tn must be in ascending order. All tn and xn must be fixed values -- they can not contain further computation._BCD
PWSREPEAT(t1,x1,t2,x2,...)Like PWS, but repeats indefinitely. The signal to be repeated spans from t=0 to the final specified time point._BCD
REAL(x)Real part of complex number x__C_
SIN(x)Sine of xABCD
SINH(x)Hyperbolic sine of xABCD
SQRT(x)Square root of xABCD
TAN(x)Tangent of xABCD
TANH(x)Hyperbolic tangent of xABCD
UNITLESS(x)Remove units from real quantity x_BC_
URAMP(x)x if x >= 0; 0 if x < 0ABCD
USTEP(x)1 if x >= 0; 0 if x < 0ABCD
V(NODE_NAME)Voltage at node NODE_NAME_BCD

* Contexts: some functions are only applicable in certain modes of CircuitLab operation:

• A: Statically-evaluated parameters, like in a resistor's resistance value.
• B: Plotting expressions in real analysis modes, such as DC Sweep, and Time-domain simulation. Expressions to evaluate for DC simulation.
• C: Plotting expressions in complex analysis modes, such as Frequency-domain simulation.
• D: Behavioral voltage and current expressions to be evaluated for arbitrary behavioral voltage and currents.