我有一个复杂的表达式,涉及用Sympy编写的带有许多符号变量的非线性动力学。是否可以生成一个用python编写的函数,该函数将这些变量作为输入并计算最终输出作为数值?
我有下面的代码来计算机器人的雅可比行列式。 rotB已与theta以外的所有变量一起定义。我希望能够使用theta作为输入将最终的符号表达式转换为函数。有没有办法做到这一点?
我是python的新手,以前在可能的情况下使用过Matlab。 。 。!任何帮助将不胜感激。
i = 0
j = 0
k = 0
diff_l1 = {}
sum_l1 = {}
sumR_l1 = {}
sum_l1[0] = zeros(3,1)
diff_l2 = {}
sum_l2 = {}
sumR_l2 = {}
sum_l2[0] = zeros(3,1)
Jvm={}
J_vm = {}
while i < n:
sumR_manip = Matrix(zeros(3,n))
while j <= i:
k = 0
if j == 0:
while k <= j:
diff_l1[k] = diff(rotB[j+1],theta[k])*b[j+1,:].T
sum_l1[k+1] = sum_l1[k] + diff_l1[k]
sumR_l1[k] = sum_l1[k+1]
diff_l2[k] = zeros(3,1)
sum_l2[k+1] = sum_l2[k] + diff_l2[k]
sumR_l2[k] = sum_l2[k+1]
f = k
p = k
k += 1
else:
k = 0
while k <= j:
diff_l1[k] = diff(rotB[j+1],theta[k])*b[j+1,:].T
sum_l1[k+1] = sum_l1[k] + diff_l1[k]
sumR_l1[k] = sum_l1[k+1]
f = k
k += 1
k = 0
while k <= j-1:
diff_l2[k] = diff(rotB[j],theta[k])*s[j,:].T
sum_l2[k+1] = sum_l2[k] + diff_l2[k]
sumR_l2[k] = sum_l2[k+1]
p = k
k += 1
sumR1 = sumR_l1[f]
sumR2 = sumR_l2[p]
sumR_manip[:,j] = sumR1+sumR2
j += 1
Jvm[i] = sumR_manip
i += 1
j = 0
k = 0
i = 0
while i < n:
J_vm[i] = Jvm[i]
i += 1