我正在寻找一种在SymPy中创建函数的方法(u,v) - > (x,y,z)将两个元素转换为三个,然后从结果向量中获取导数。它在Sage看起来像这样:
u = var('u')
v = var('v')
x = (2 + sin(u) *sin(v)) *sin(3*v/2)
y = cos(u) *sin(v) + 2 *v/pi - 2
z = (2 + sin(u) *sin(v)) *cos(3*v/2)
r(u, v) = [x, y, z]
e1 = derivative(r, u)
答案 0 :(得分:3)
SymPy有一个Vector module,它面向各种坐标系中的微积分。但是,如果您不需要进行坐标转换,则将矢量表示为单列矩阵Matrix([x, y, z])
更为直接,如下所示:
from sympy import *
var('u v')
x = (2 + sin(u) *sin(v)) *sin(3*v/2)
y = cos(u) *sin(v) + 2 *v/pi - 2
z = (2 + sin(u) *sin(v)) *cos(3*v/2)
# everything so far was as in your code
r = Matrix([x, y, z])
e1 = r.diff(u)
pprint(e1) # "pretty" print
输出(假设没有LaTeX处理):
⎡ ⎛3⋅v⎞ ⎤
⎢sin(v)⋅sin⎜───⎟⋅cos(u)⎥
⎢ ⎝ 2 ⎠ ⎥
⎢ ⎥
⎢ -sin(u)⋅sin(v) ⎥
⎢ ⎥
⎢ ⎛3⋅v⎞⎥
⎢sin(v)⋅cos(u)⋅cos⎜───⎟⎥
⎣ ⎝ 2 ⎠⎦