python:fsolve在积分上限内未知

标签 python scipy integration

是否可以对上限和被积函数中未知的积分应用 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/

相关文章:

Python 使用对象列表迭代对象

Python插入变量字符串作为文件名

python - scipy:哪些发行版实现了 "fit"函数?

Python/Scipy Kolmogorov-Zurbenko 过滤器?

Grails 集成测试不能在空服务对象上调用方法?

python - 同时处理多个版本?

python - Pandas:从列值重构数据框

Python。积分问题。类型错误 : only size-1 arrays can be converted to Python scalars

java - 每个帐户可以创建多少个 Flurry 项目?

javascript - 将 AngularJS 应用程序与 Google Analytics 集成