|
用了mathematica 与 maxima 很多年, 这几年开始用sympy, 感觉比前两个都好用。
这些工具对我来说仅是一个积分微分表, 遇到不熟悉的微分积分,直接在里头验证, 不用另查资料了, 方便快捷, 而且结果最可靠。
以下是我常用的几个命令:
In [1]: from sympy import *
In [2]: x=symbols('x') #define a variable of symbol type
In [3]: f=Function('f')(x) #define a function of a variable x
In [4]: integrate(sin(x)) #calculat infinite integration
In [5]: integrate(x*x*exp(-x*x),(x,-oo,oo)) #compute definite integration
In [6]: diff(x*x,x) #derivative
When defining a variable, we can specify some properties of the variable, For example:
In [27]: a=symbols('a', real=True, zero=False)
Here we specify that the variable 'a' is a nonzero real number。
Without specifying 'a' is nonzero, then it will take much longer time for sympy to figure out the following besselj integration.
In [28]: integrate(besselj(0,a*x)**2*exp(-x*x/2)*x,(x,0,oo))
Out[28]: exp(-a**2)*besseli(0, a**2)
This is one important integration used in deriving the polarization density in gyrokinetic theory.
Here besselj is the bessel function of the first kind, besseli is the modified bessel function of the first kind, see wikepedia.
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-4-18 19:59
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社