Reputation: 69
I'm trying to write a loop that calculates the value of a definite integral at each step. The function bigF
is very complicated. To put it in simple terms, it integrates a bunch of terms with respect to s
, from s=tn-(n/2)
to s=tn+(n/2)
. After the integration, bigF
still has a variable t
. So you can say bigF(t) = integral(f(s,t))
, where f(s,t)
is the big mess of terms after integrate.integ
. In the last line, I want to evaluate bigF(t)
at t=tn
after bigF
computes the integral of f(s,t)
After running, I get the error global name 's' is not defined
. But s
was meant to be just a dummy variable in the integration, since I am computing a convolution. What do I need to do?
import numpy as np
import scipy.integrate as integ
import math
nt=5001#; %since (50-0)/.01 = 5000
dt = .01#; % =H
H=.01
theta_n = np.ones(nt)
theta_n[1]=0#; %theta_o
omega_n = np.ones(nt)
omega_n[1]=-0.4# %omega_o
epsilon=10^(-6)
eta = epsilon*10
t_o=0
def bigF(t, n):
return integrate.integ((422.11/eta)*math.exp((5*(4*((eta*t-s-tn)^2)/eta^2)-1)^(-1))*omega, s,tn-(n/2),tn+(n/2))
for n in range(1,4999)
tn=t_o+n*dt;
theta_n[n+1] = theta_n[n] + H*bigF(tn, n);
Upvotes: 2
Views: 1784
Reputation: 6651
If you're doing a convolution, sounds like you want numpy.convolve.
Upvotes: 0