INTEGRATE

This function computes symbolic integrals of an expression with respect to a variable. If integration bounds are provided, it computes a definite integral; otherwise it computes an indefinite integral.

Indefinite integration evaluates:

\int f(x)\,dx

Definite integration with bounds a to b evaluates:

\int_a^b f(x)\,dx

The result is returned as a symbolic expression string.

Excel Usage

=INTEGRATE(expression, variable, lower, upper)
  • expression (str, required): Expression to integrate.
  • variable (str, optional, default: “x”): Integration variable name.
  • lower (float, optional, default: null): Lower integration bound for definite integral.
  • upper (float, optional, default: null): Upper integration bound for definite integral.

Returns (str): String representation of the symbolic integral result.

Example 1: Indefinite integral of polynomial

Inputs:

expression variable lower upper
x**2 + 1 x

Excel formula:

=INTEGRATE("x**2 + 1", "x", , )

Expected output:

"x**3/3 + x"

Example 2: Definite integral on unit interval

Inputs:

expression variable lower upper
x**2 x 0 1

Excel formula:

=INTEGRATE("x**2", "x", 0, 1)

Expected output:

"1/3"

Example 3: Indefinite integral of trigonometric expression

Inputs:

expression variable lower upper
cos(x) x

Excel formula:

=INTEGRATE("cos(x)", "x", , )

Expected output:

"sin(x)"

Example 4: Definite integral with custom variable

Inputs:

expression variable lower upper
t t 1 3

Excel formula:

=INTEGRATE("t", "t", 1, 3)

Expected output:

"4"

Python Code

from sympy import Symbol
from sympy import sympify
from sympy import integrate as sympy_integrate

def integrate(expression, variable='x', lower=None, upper=None):
    """
    Compute an indefinite or definite symbolic integral.

    See: https://docs.sympy.org/latest/modules/integrals/integrals.html#sympy.integrals.integrals.integrate

    This example function is provided as-is without any representation of accuracy.

    Args:
        expression (str): Expression to integrate.
        variable (str, optional): Integration variable name. Default is 'x'.
        lower (float, optional): Lower integration bound for definite integral. Default is None.
        upper (float, optional): Upper integration bound for definite integral. Default is None.

    Returns:
        str: String representation of the symbolic integral result.
    """
    try:
        variable_symbol = Symbol(variable)
        normalized_expression = expression.replace("^", "**")
        expr = sympify(normalized_expression)

        if lower is None and upper is None:
            result = sympy_integrate(expr, variable_symbol)
        elif lower is None or upper is None:
            return "Error: lower and upper must both be provided for definite integration"
        else:
            result = sympy_integrate(expr, (variable_symbol, lower, upper))

        return str(result)
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Expression to integrate.
Integration variable name.
Lower integration bound for definite integral.
Upper integration bound for definite integral.