有可能将fsolve方法应用于上限和被积分数未知的积分吗???我正在使用Quad方法在python中进行集成。
提前致谢!!!
当然。
假设您要查找x,使得t *(1-x * t)的从t = 0到t = x的t上的积分为0。您可以通过定义两个函数来做到这一点。integrand(t, x)
将评估t *(1-x * t),并将使用进行func(x)
积分,将其作为积分的上限,并作为被积数的额外参数。这是一个演示:integrand
quad
x
import numpy as np
from scipy.integrate import quad
from scipy.optimize import fsolve
def integrand(t, x):
return t*(1 - x*t)
def func(x):
y, err = quad(integrand, 0, x, args=(x,))
return y
# Use 1.0 as the initial guess. Note that a bad initial guess
# might generate a warning and return the degenerate solution at x=0.
sol = fsolve(func, 1.0)
print "Solution: ", sol[0]
# The exact solution that we want is sqrt(3/2)
print "Exact solution:", np.sqrt(1.5)
输出:
Solution: 1.22474487139
Exact solution: 1.22474487139
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句