Qu

exp

Builtin index · Core maths

result = exp(x)

Input: x · Output: result

What it is

e^x, elementwise. x is a scalar, Vec, or Mat/Signal; returns the same shape with every element exponentiated.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = exp(x)
x scalar, Vec, Mat, or Signalnot documented yet
result —
Returns exactly the same type and shape as x.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

model(x, p) := p[0] * exp(-p[1] * x)
fit = curve_fit("model", xdata, ydata, [1, 1])   # initial guess [1, 1]

print("a = {fit.params[0]}, b = {fit.params[1]}, cost = {fit.cost}")

from numerics-dsp

x = 1 to 50
plot(x, exp(0.1 * x))
axis scale y log
output
· plot: figure 2 (50 points)
10−279 10−248 10−217 10−186 10−155 10−124 10−93 10−62 10−31 100 -100 -50 0 50 100 (0, 1.9) 6 dB = 1 bit

from plotting

wavy(p) := -0.5*exp(-(p[0]+2)^2) - 2*exp(-(p[0]-3)^2/2)  # shallow local

                                                            # min at -2,

                                                            # deeper global

                                                            # min at 3

stuck = minimize("wavy", [-2])            # stays at the shallow one

found = basin_hopping("wavy", [-2], n_iter=60, step_size=3)  # finds the deep one

from numerics-dsp

tau   = 0.35
decay = 2.5 * exp(0 - t / tau) + 0.02 * randn(1000, seed = 2)

function resid(p)
    return p[0] * exp(0 - t / p[1]) - decay
end function

fit = least_squares("resid", [1.0, 1.0])
print("amplitude {fit.params[0]:.4f} (true 2.5)")
print("tau       {fit.params[1]:.4f} (true {tau})")
output
amplitude 2.4990 (true 2.5)
tau       0.3502 (true 0.35)

from from-zero