Library reference

Exponential growth

Use the natural exponential when a model describes continuous growth or decay. A rate of zero leaves the starting amount unchanged.

exp

Simple example

Evaluate the exponential at zero.

Start0
Result1.0
lesson.mojo
from std.math import exp

def main() raises:
    print(exp(Float64(0.0)))
Output
1.0
Advertisements

Everyday examples

An animation starts with ten dots. Its growth setting is zero. How many dots does the model show?

Start0
Result10.0
lesson.mojo
from std.math import exp

def main() raises:
    print(10.0 * exp(Float64(0.0)))
Output
10.0

A sound effect starts at level eight. After one decay interval its level is eight times the exponential of minus one. What level remains?

Start-1
Result2.943035529370708
lesson.mojo
from std.math import exp

def main() raises:
    print(8.0 * exp(Float64(-1.0)))
Output
2.943035529370708

A classroom growth model starts at five units. After one growth interval what amount does the model predict?

Start1
Result13.591409142299064
lesson.mojo
from std.math import exp

def main() raises:
    print(5.0 * exp(Float64(1.0)))
Output
13.591409142299064
Run the example
Terminal
mojo lesson.mojo
Official documentation