Python偏导数容易

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30791504/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:59:14  来源:igfitidea点击:

Python partial derivatives easy

pythoncalculus

提问by cnrk

I'm interested in computing partial derivatives in Python. I've seen functions which compute derivatives for single variable functions, but not others.

我对在 Python 中计算偏导数感兴趣。我见过计算单变量函数的导数的函数,但不是其他函数。

It would be great to find something that did the following

找到执行以下操作的东西会很棒

    f(x,y,z) = 4xy + xsin(z)+ x^3 + z^8y
    part_deriv(function = f, variable = x)
    output = 4y + sin(z) +3x^2

Has anyone seen anything like this?

有没有人见过这样的事情?

采纳答案by wtayyeb

use sympy

sympy

>>> from sympy import symbols, diff
>>> x, y, z = symbols('x y z', real=True)
>>> f = 4*x*y + x*sin(z) + x**3 + z**8*y
>>> diff(f, x)
4*y + sin(z) + 3*x**2

回答by Nitish

Use sympy

sympy



From their Docs:

从他们的文档

>>> diff(sin(x)*exp(x), x)
 x           x
? ?sin(x) + ? ?cos(x)

and for your example:

和你的例子:

>>> diff(4*x*y + x*sin(z)+ x**3 + z**8*y,x)
3x**2+4*y+sin(z)