简体   繁体   English

Python-Sympy最小值和最大值

[英]Python - Sympy Minima and Maxima

I'm trying to learn sympy's calculus functions and I'm able to get as far as getting the roots of the second derivative for the critical points of the extrema via: 我正在尝试学习sympy的微积分函数,并且能够通过以下方式获得关于极值临界点的二阶导数的根:

import numpy as np
    from numpy import linspace, math, arange, linspace
    from sympy import *
    import sympy as sp
    import math

    x = Symbol('x')
    f = (x**4) - (24*x**2) + 80  
    fd = diff(f)
    fdd = diff(fd)
    print(fd)
    print(fdd)

    polyRoots = solveset(f,x)
    dRoots = solveset(fd,x) #gets critical x values
    ddRoots = solveset(fdd,x)

How do I substitute the values I get from dRoots into the original equation, f, and have it output a list of values? 如何将从dRoots获得的值替换为原始方程式f,并使其输出值列表?

>>> from sympy import *
>>> x = Symbol('x')
>>> f = x**4 - 24*x**2 + 80
>>> fd = diff(f)
>>> fdd = diff(fd)
>>> polyRoots = solveset(f, x)
>>> dRoots = solveset(fd, x)
>>> ddRoots = solveset(fdd, x)
>>> dRoots
{0, -2*sqrt(3), 2*sqrt(3)}
>>> [_ for _ in dRoots]
[0, -2*sqrt(3), 2*sqrt(3)]
>>> [f.subs(x, _) for _ in dRoots]
[80, -64, -64]

You can verify that this makes sense by doing: 您可以通过执行以下操作来验证这是否有意义:

>>> [f.subs(x, _) for _ in polyRoots]
[0, 0, 0, 0]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python中曲线的最大值和最小值 - Maxima and Minima Point of a Curve in Python 在数据python中查找局部最大值和局部最小值 - Finding the local maxima and local minima in the data python 在某些点找到最大值和最小值 Pandas Python - Finding maxima and minima at certain points Pandas Python Python 中的 2D 局部最大值和最小值 - 2D local maxima and minima in Python 有没有办法计算 python 中快递的最大值和最小值? - Is there a way to calculate maxima and minima of an express in python? 2 个最小值/最大值之间的实际最大值/最小值 - Real maxima/minima between 2 minima/maxima 需要帮助使用 sympy 在 Python 中绘制和查找局部最大值和最小值。 第一部分工作,但无法弄清楚如何做其他部分 - Need help plotting and finding local maxima and minima in Python using sympy. first part works but can't figure out how to do the other parts Python有效地为多个多项式找到局部最大值/最小值 - Python finding local maxima/minima for multiple polynomials efficiently 在python中找到5个局部最大值和最小值点以及极值 - Find 5 local maxima and minima points plus the extremas in python 在 python 中查找多变量多项式的最小值/最大值 - Finding the minima/maxima of a multi-variable polynomial in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM