我有2D曲线rho(t)
import sympy as sy
t = sy.Symbol('t', is_real=True) # curve parameter
rho_x = sy.Function('rho_x', is_real=True)(t)
rho_y = sy.Function('rho_y', is_real=True)(t) # components
rho = sy.Matrix([rho_x, rho_y]) # curve vector
tau = rho.diff() / rho.diff().norm() # tangent
之后我想评估特定实现的曲线参数:
real_shape = {rho_x: sy.sin(t), rho_y: sy.cos(t)}
f1 = tau.subs(real_shape)
print f1
f2 = sy.lambdify(t, f1)
print f2(0.1)
我发现SymPy没有自动评估正弦和余弦函数的导数,在调用print f2(0.1)
后它显示错误信息:
NameError:未定义全局名称“Derivative”
我的例子有什么问题?
答案 0 :(得分:1)
您可以在Matrix上调用doit()
进行评估。
In [49]: f1 = f1.doit()
In [50]: f2 = lambdify(t, f1)
In [51]: print f2(0.1)
[[ 0.99500417]
[-0.09983342]]
另请注意,您假设的方式是错误的。 t
的真实假设应该是这样的:
In [52]: t = Symbol('t', real=True)