没有SciPy的Python数值积分?
我需要集成函数:y(x)=e-axcos(x)而不使用SciPy/NumPy等。我很挣扎。我知道这一点:没有SciPy的Python数值积分?,python,math,numerical-methods,numerical-integration,Python,Math,Numerical Methods,Numerical Integration,我需要集成函数:y(x)=e-axcos(x)而不使用SciPy/NumPy等。我很挣扎。我知道这一点: def integrand(x): return 对于返回位,我想使用以下等式:y(xi)(xi-x(I-1))的从I=1到N的和 我该怎么写呢?简单地定义为: from math import cos, e def y(x): return (e**(-a*x))*cos(x) def integrand(x): return sum(
def integrand(x):
return
对于返回位,我想使用以下等式:y(xi)(xi-x(I-1))的从I=1到N
的和
我该怎么写呢?简单地定义为:
from math import cos, e
def y(x):
return (e**(-a*x))*cos(x)
def integrand(x):
return sum(y(x[i])*(x[i]-x[i-1]) for i in range(1,len(x)))
总数可能是从1
到N-1
?谢谢。然而,我现在不知道如何继续。我已经习惯了使用SciPy。我希望它在“a”=0时打印积分值。是的,我已经这样做了。只是不确定如何从这里开始。在你的另一个问题中,你创建了一个x=linspace(..)
并调用integrand(x)
…名称“linspace”没有定义?@webberwizard:来自numpy import linspace
??
from math import exp, cos
def y(x):
return exp(-a*x)*cos(x)