下面的一个代码示例包含一个等式,它使用scipy.fsolve以x轴求零
1-如何运行fsolve并要求在特定时间间隔内搜索f.ex-75和75
2-有时要求在结果变为2000时找到x值,如何通过fsolve实现
from scipy.optimize import fsolve
def func(x, a, b, c):
result = a * x ** 2 + b * x + c
return result
result = fsolve(func, 0.01, args = (1, 2, 3))
print(result)
import matplotlib.pyplot as plt
import numpy as np
# Data for plotting
x = np.arange(-100.0, 100.0, 0.1)
fig, ax = plt.subplots()
ax.plot(x, func(x, 1, 2, 3))
ax.set(xlabel='x', ylabel='result',
title='Just for illustration')
ax.grid()
plt.show()
以图形方式显示。
fsolve不支持边界。如果您有本地化时间间隔,请选择brentq
只需找到
lambda x, a, b, c: func(x, a, b c) -2000
的根相关问题 更多 >
编程相关推荐