Scipy-fsolve解一个具有特定需求的方程

2024-10-03 13:25:44 发布

您现在位置:Python中文网/ 问答频道 /正文

下面的一个代码示例包含一个等式,它使用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()

以图形方式显示。

enter image description here


Tags: 代码import示例forasnp时间plt