是否可以对上限和被积函数中未知的积分应用 fsolve 方法???我正在使用四元方法在 python 中集成。
提前致谢!!!
最佳答案
当然。
假设您想要找到 x,使得 t*(1-x*t) 的 t=0 到 t=x 的积分为 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
关于python:fsolve在积分上限内未知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27382952/