pythonsympycalculus

Computing Riemann-Liouville Integral using Sympy


New to calculus and not sure where this goes...

I'm trying to compute the Riemann-Liouville interpretation of the integral in Python using sympy. However the resulting integral when running my code between 0 and T contains T as a variable, which I do not want. What should I do to fix this?

Code:

def integral(f, order):
    gamma_recip = 1/gamma(order)
    T = sympy.Symbol('T')
    r = sympy.Symbol('r')
    eq = (T-r) ** order - 1
    function_eq = eq * f(r)
    integral = sympy.integrate(function_eq, (r, 0, T))
    return integral

Equation:

enter image description here

Sample call as requested: -0.333333333333333*T**3 + 0.0833333333333333*T**4.0

Function and order used:

def f(x):
    return x**2
print(integral(f, 1.0))

Expected result:

r**3/3


Solution

  • Two issues:

    1. you are using "T" as the integral limit so you will end up with that in the result; if you want "r" in the result, swap the use of T and r in your function
    2. you didn't put parentheses around the order - 1 in your definition of eq; if you do you will (with your current code) get the expected T**3/3