简体   繁体   中英

Computing definite integrals in python

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);

如果要进行卷积,听起来像是numpy.convolve

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM