如何找到功能的最小值和最大值。我仅限于使用numpy,sympy和matplotlib
我被要求找到少数功能的最大值和最小值。函数之一是y =(9x^3) - (7x^2) +(3x) + 10 到目前为止,我可以编写的代码是:
from sympy import*
import matplotlib.pyplot as plt
x = symbols ('x')
f = (9*x**3) - (7*x**2) + (3*x) + 10
intervals = np.arange(-5, 7)
df = diff(f, x)
df2 = diff(f, x, 2)
f = lambdify (x, f)
y = f(intervals)
print (intervals)
print (y)
我是使用这三个库的新手,所以我不知道如何使用这3个库找到答案
I am asked to find the maxima and minima of few functions. One of the functions is y = (9x^3) - (7x^2) + (3x) + 10
The code I could write so far is:
from sympy import*
import matplotlib.pyplot as plt
x = symbols ('x')
f = (9*x**3) - (7*x**2) + (3*x) + 10
intervals = np.arange(-5, 7)
df = diff(f, x)
df2 = diff(f, x, 2)
f = lambdify (x, f)
y = f(intervals)
print (intervals)
print (y)
I am new to using these 3 libraries so I dont know how to find the answer using these 3 libraries
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Sympy可以告诉您派生和
f
,可以告诉您何时函数为零。由于最大/分钟发生在衍生物为零时,您可以找到零,然后确定这些值是否使第二个衍生物正阳性或负面,例如另请参见在这里。 (如果没有真正的根,那么
x
的真实值就没有极点。)SymPy can tell you the derivative and
f
and can tell you when a function is zero. Since max/min occur when the derivative is zero you can find the zeros and then determine if those values make the 2nd derivative positive or negative, e.g.See also here. (If there are no real roots then there are no extrema for real values of
x
.)如果要将
间隔
的值传递到公式中,然后获取最小值,则可以首先指定Intervals
,然后将此数组放入公式中而不是将其放入公式<代码> x :或者,如果要多次使用公式,则可以将其定义为函数,然后每次需要将其调用,而是再次编写为:
If you want to pass the values of
intervals
into the formula and then get the minimum value, you can specify theintervals
firstly and then just put this array into the formula insteadx
:or if you want to use the formula many times, you can define it as a function and just call it every time you need instead writing it again as: