Есть две функции expFun1 и expFun2, которые я пытаюсь интегрировать от t до s относительно u.
Код: Выделить всё
import sympy as sym
# It returns a symbolic function where u is the only symbol in the function
def expFun1(X1,X2,a1,a2,T,u):
fx= X1*sym.exp(-a1*(T-u))+X2*sym.exp(-a2*(T-u))
return fx
# Squared version of expFun1
def expFun2(X1,X2,a1,a2,T,u):
fx= (X1*sym.exp(-a1*(T-u))+X2*sym.exp(-a2*(T-u))) **2
return fx
Код: Выделить всё
u = sym.symbols('u')
t=0
s=1
T=1.2
X1, X2, a1, a2= [0.5, 0.3, 2, 0.1]
Fx1=sym.integrate(expFun1(X1,X2,a1,a2,T,u), (u,t,s))
Fx2=sym.integrate(expFun2(X1,X2,a1,a2,T,u), (u,t,s))
In the actual application I need to loop through different values for the non-symbolic arguments, and the integration for expFun2 takes forever.
What would be the best way to speed up the computation time given the functional form of expFun2?
Источник: https://stackoverflow.com/questions/662 ... -integrate