Numerical Methods
nroot
A numerical root of an expression in a bracket where it changes sign (Brent's method). Returns a record: x, residual, the final bracket (lower, upper), iterations, evaluations and status.
expr (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
lower (number) -- left end of the bracket
upper (number) -- right end of the bracket
rk4
Solves y' = f(t, y) with fixed-step classical Runge-Kutta (RK4). Returns a record with the final t and y, iterations, evaluations and status.
f (symbolic) -- the right-hand side f(t, y), e.g. y - t
t (string) -- the independent variable, unquoted
y (string) -- the dependent variable, unquoted
t0 (number) -- initial t
y0 (number) -- initial y
h (number) -- step size
steps (number) -- number of steps
bisection
A root by bisection in a bracket where the function changes sign. Slow but always keeps the root bracketed.
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
lower (number) -- left end
upper (number) -- right end
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
newton
A root by Newton's method from a starting guess. Needs the derivative; not guaranteed to converge.
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
df (symbolic) -- the derivative, e.g. 2*x
dvar (string) -- its variable
x0 (number) -- starting guess
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
secant
A root by the secant method from two starting guesses; not guaranteed to converge.
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
x0 (number) -- first guess
x1 (number) -- second guess
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
nderiv
A numerical derivative by central differences with Richardson extrapolation, with an error estimate.
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
at (number) -- the point
h (number) -- the step, e.g. 0.001
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
nderivForward
A numerical derivative by forward differences with Richardson extrapolation.
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
at (number) -- the point
h (number) -- the step
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
nintegrate
A numerical definite integral by adaptive Simpson's rule, with an error estimate.
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
lower (number) -- left end
upper (number) -- right end
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
trapezoid
The composite trapezoid rule with n panels (refined once to estimate the error).
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
lower (number) --
upper (number) --
n (number) -- number of panels
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
simpson
The composite Simpson rule with n panels (n even; refined once to estimate the error).
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
lower (number) --
upper (number) --
n (number) -- number of panels, even
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
lerp
Linear interpolation: the value at x on the line through (x0, y0) and (x1, y1).
x0 (number) --
y0 (number) --
x1 (number) --
y1 (number) --
x (number) --
euler
Solves y' = f(t, y) with fixed-step Euler steps.
f (symbolic) -- the right-hand side f(t, y), e.g. y - t
t (string) -- the independent variable
y (string) -- the dependent variable
t0 (number) -- initial t
y0 (number) -- initial y
h (number) -- step size
steps (number) -- number of steps
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
rk45
Solves y' = f(t, y) up to a target t with adaptive Runge-Kutta-Fehlberg 4(5) steps.
f (symbolic) -- the right-hand side f(t, y), e.g. y - t
t (string) -- the independent variable
y (string) -- the dependent variable
t0 (number) -- initial t
y0 (number) -- initial y
t_end (number) -- the target t
h0 (number) -- first step size
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
nminimize
The minimum of a function on an interval by Brent's method (the function should have one minimum there).
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
lower (number) --
upper (number) --
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
goldenMin
The minimum of a function on an interval by golden-section search.
f (symbolic) -- the function, e.g. x^2 - 2
var (string) -- its variable, unquoted
lower (number) --
upper (number) --
tol (number) -- optional: tolerance for the result, e.g. 1e-6 (default 1e-12)
fitLine
The least-squares line y = intercept + slope*x through data points, with the residual sum of squares.
xs (array) -- x values
ys (array) -- y values
newton2
Newton's method for two equations f1 = 0, f2 = 0 in two variables, from a starting point; the Jacobian is exact (symbolic).
equations (expression list) -- [f1, f2]
x (name) --
y (name) --
x0 (number) --
y0 (number) --
fitOneParameter
The parameter value in [lower, upper] that minimizes an objective (e.g. a sum of squared errors).
objective (expression) --
p (name) --
lower (number) --
upper (number) --
newtonInterp
The interpolating polynomial through the points (xs, ys), in Newton's divided-difference form, evaluated at x.
xs (array) --
ys (array) --
x (number) --
spline
The natural cubic spline through the points (xs, ys), evaluated at x.
xs (array) --
ys (array) --
x (number) --
fft
The discrete Fourier transform of a list whose length is a power of 2 (real or complex).
ifft
The inverse discrete Fourier transform.