I have a function I need to evaluate numerically.
$$ \int^T_t c(s)^2 e^{-2 \alpha (T-s)}\mathrm{d}s$$
I know the values of $c(s)$ but I don't know its exact functional form. I believe I can use Simpson's rule to integrate numerically.
I am new to numerical integration so I've written some code to evaluate the function in Python. First I create a function for the integrand which basically perform the product between each element evaluation of the function $c$ at each time period by the exponential function for that time period. Then I call the Simpson function from Scipy to get the evaluated integral.
Does the approach make sense? I have posted my code below
Thanks!
import numpy as np
from scipy.integrate import simpson
def integrand(t, T, alpha, c):
deltas = np.array([T-s for s in range(t,T+1)])
return np.exp(- 2 * alpha * deltas) * (c[t:T+1] ** 2)
c=[0.1, 0.2, 0.3]
T=1
t=0
alpha=0.2
simpson(integrand(t, T, alpha, c), np.arange(t, T+1))