Skip to content

Integral (functions/integral.py)

functions/integral.py provides indefinite and definite integration. It returns a single SymPy expression (simplified by radsimp), not a string.

integral — integration

Purpose: integrate integrand f with respect to variable v; when both a and b are given it is a definite integral, otherwise indefinite.

def integral(f, v, fs, a=None, b=None):
    ...
Param Type Meaning
f str integrand expression, Python/SymPy syntax, e.g. "x**2", "exp(x)"
v str integration variable (single symbol string, e.g. "x")
fs dict function dictionary
a str | None lower bound; "" or None means indefinite integral
b str | None upper bound; "" or None means indefinite integral

Returns: a SymPy expression from radsimp(integrate(sympify(f), sympify(v))).

Warning

v is a single integration-variable string, e.g. "x". This function does not support passing a list for repeated integration (e.g. [x, y]); for multiple integrals call repeatedly or integrate the result again.

Example

python integral("x**2", "x", {}, None, None) # -> x**3/3 (indefinite) integral("x**2", "x", {}, "0", "1") # -> 1/3 (definite 0..1)