在python代码中输入符号函数 [英] input a symbolic function in a python code
问题描述
我只是想知道是否有一种方法可以在 python 代码中输入符号函数?
I was just wondering if there is a method to input a symbolic function in a python code?
就像在我的代码中一样:
like in my code I have:
from sympy import *
import numpy as np
import math
myfunction = input("enter your function \n")
l = Symbol('l')
print myfunction(l**2).diff(l)
如果我将 cos、sin 或 exp 作为输入,那么我的输出为:-2*l*sin(l**2)
If I put cos, sin or exp, as an input then I have an output of: -2*l*sin(l**2)
如果我想让输入函数更一般,比如多项式或复函数,或者可能是 cos、sin 和 exp 组合的函数???
What If I want to make the input function more general, say a polynomial or a complex function, or maybe a function of combined cos, sin and exp ???
推荐答案
如果你需要对符号函数的良好支持,你应该考虑使用 圣人.
If you need good support for symbolic funcions, you should consider using sage.
它是 python 的预处理器,有很多数学支持,包括符号函数.Sage 代码可以与普通的 python 代码混合使用.
It is a preprocessor for python, with lots of math support including symbolic functions. Sage code can be intermixed with normal python-code.
包裹很大,但我有很好的体验.它是免费和开源的.
The package is quite big, but I have good experiences with it. It is free and open-source.
这篇关于在python代码中输入符号函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!