# Controlled Source Output Function

The controlled source elements take an output function parameter. The output function takes the inputs, if any, as parameters (which will be `a`, `b`, etc. for a voltage-controlled source, or `i` for a current-controlled source). You can also specify `t` for the current simulation time, `timestep` for the timestep, `pi` for π, and `e` for e (unless there is an input `e`).

The function can use arithmetic like `a+b`, `a*b`, `a^2/(b-1)`, etc. It can also use functions like `sin(x)`, `cos(x)`, `abs(x)`, `exp(x)`, `log(x)`, `sqrt(x)`, `tan(x)`, `floor(x)`, `ceil(x)`, `mod(x,y)`, `max(x,y,...)`, and `min(x,y,...)`.

It can also use conditional expressions like `(a > 5) ? a+1 : b-2`.

The `tri(x)` function is like `sin(x)`, but generates a triangle waveform.

The `saw(x)` function is like `sin(x)`, but generates a sawtooth waveform.

The `step(x)` function is 0 if `x` < 0, and 1 otherwise. (Equivalent to `x >= 0`). The `step(x,y)` function is 1 if 0 < `x` < `y`, and 0 otherwise. (Equivalent to `0 < x && x < y`).

The `clamp(x,lo,hi)` function is equal to `min(max(x, lo), hi)`.

The `select(x,a,b)` function is equal to `b` if `x` is greater than zero, and `a` otherwise. So it's the same as `(x > 0) ? b : a`.

The `pwl(x,x0,y0,x1,y1,x2,y2,...,xn,yn)` function is short for piece-wise linear, and works as follows. If `x < x0`, then the result is `y0`. If `x0 < x < x1`, then the result is a linear interpolation between `y0` and `y1`. If `x1 < x < x2`, the result is a linear interpolation between `y1` and `y2`, etc. If `x > xn`, then the result is `yn`. For example, in the simplest case, `pwl(t,0,0,.1,5)` is a waveform that starts at 0 at time 0 and then ramps to 5 over 100ms, then stays at 5.

`dadt`, `dbdt`, etc. are equal to the time derivative of `a`, `b`, etc. `lasta`, `lastb`, etc. are equal to the value of `a`, `b`, etc. in the previous timestep. `lastoutput` is equal to value of the output function in the previous timestep. Examples:

- Resistor
- Varying Resistor
- Op-Amp
- Op-Amp With Rails
- Multiplier
- Full Rectifier
- Voltage Ramp
- Current Adder
- Integrator
- Differentiator
- Variable Inductor
- Variable Capacitor