sympy(python)中的f(x).subs()替换

2024-04-27 04:43:44 发布

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

但我要用“3”来表示。怎么了?在

a, f = symbols('a f')

a(3).subs(a,f)

Tags: subssymbols
2条回答

您已经将f定义为一个函数,然后将其替换为来自symbols()的返回值。在

您可以使用replace来更改函数。这里有一些例子。在

import sympy as sp

f = sp.Function('f')
g = sp.Function('g')
x,y = sp.symbols('x, y')

f(x).replace(f, g)

g(x)

^{pr2}$

sin(x)

f(x,y).replace(f, lambda *args: sp.exp(-5 * args[0] + args[1] ))

exp(-5*x + y)

documentation提供了大量附加示例的列表。在

相关问题 更多 >