如何在Sympy中进行功能组合? [英] How to do function composition in Sympy?

查看:112
本文介绍了如何在Sympy中进行功能组合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想做类似h = f(g(x))的事情,并且能够区分h,例如h.diff(x).实际上,对于像h = cos(x)这样的一个函数,这是可能的,并且文档中明确指出了这一点.

I want to do something like h = f(g(x)) and be able to differentiate h, like h.diff(x). For just one function like h = cos(x) this is in fact possible and the documentation makes it clear.

但是对于功能组合并不清楚.如果您这样做,请给我看一个例子或将我链接到相关文档.

But for function compositions it is not so clear. If you have done this, kindly show me an example or link me to the relevant document.

(如果Sympy无法做到这一点,您是否知道其他任何可以做到这一点的软件包,即使它不是非python)

(If Sympy can't do this, do you know of any other packages that does this, even if it is non-python)

谢谢.

推荐答案

似乎函数组合按预期在sympy中起作用:

It seems that function composition works as you would expect in sympy:

import sympy
h = sympy.cos('x')
g = sympy.sin(h)
g
Out[245]: sin(cos(x))

或者,如果您愿意

from sympy.abc import x,y
g = sympy.sin('y')
f = g.subs({'y':h})

然后,您可以调用diff以获得导数.

Then you can just call diff to get your derivative.

g.diff()
Out[246]: -sin(x)*cos(cos(x))

这篇关于如何在Sympy中进行功能组合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆