Packages

Numeric algorithms in Elixir. Version 0.1.0 includes a Newton solver for nonlinear equations in one dimension.

Current section

Files

Jump to
fluxion lib ode.ex
Raw

lib/ode.ex

defmodule Fluxion.ODE do
@moduledoc """
An Ordinary Differential Equation which can be used to solve initial value
problems.
@y'(t) = f(t, y(t)), t \\ge 0@
## Examples
Define an ODE module for the equation @y'(t) = te^t@.
iex> defmodule Exp do
...> @behaviour Fluxion.ODE
...> @impl true
...> def f(t, y_t), do: t * :math.exp(t)
...> end
iex> IO.puts(Exp.f(1, 2))
:ok
"""
@type t() :: module()
@doc """
Compute the derivative at a given point in time.
e.g. compute @f(t, y\\_t)@ for a given value of @t@.
"""
@callback f(t :: number(), y_t :: number()) :: number()
@doc """
Evaluate an ODE module with the provided time and value.
## Examples
iex> defmodule Const do
...> @behaviour Fluxion.ODE
...> @impl true
...> def f(t, y_t), do: 2.0
...> end
iex> Fluxion.ODE.f!(Const, 10.0, -87.0)
2.0
"""
@spec f!(ode :: t(), t :: number, y_t :: number) :: number
def f!(ode, t, y_t) do
ode.f(t, y_t)
end
end