如何将 SymPy 解决方案输出为 LaTex

问题描述 投票:0回答:1

有人知道让 SymPy 以 LaTex 格式显示解决方案的简单方法吗?解决方案是写成一份报告,我不想重新输入整个内容。方程显示得很好,但不是解。 这是我的代码:

L1,L2,L3,L4,L5,theta1,theta2,theta3,theta4,theta5=smp.symbols('L1,L2,L3,L4,L5,theta1,theta2,theta3,theta4,theta5')
def position_vectors():
    R1=np.array([L1*smp.cos(theta1),L1*smp.sin(theta1)])
    R2=np.array([L2*smp.cos(theta2),L2*smp.sin(theta2)])
    R3=np.array([L3*smp.cos(theta3),L3*smp.sin(theta3)])
    R4=np.array([L4*smp.cos(theta4),L4*smp.sin(theta4)])
    R5=np.array([L5*smp.cos(theta5),L5*smp.sin(theta5)])
    return smp.Matrix([R1,R2,R3,R4,R5])
R=position_vectors()
display(R)

i_comps=smp.Eq(R[1,0]+R[2,0]+R[3,0]-R[0,0]-R[4,0],0)
j_comps=smp.Eq(R[1,1]+R[2,1]+R[3,1]-R[0,1]-R[4,1],0)

theta2_solutions=smp.solve([i_comps,j_comps],theta2)
theta5_solutions=smp.solve([i_comps,j_comps],theta5)

display(theta2_solutions)
display(theta5_solutions)

输出:

[(pi - asin((L1*sin(theta1) - L3*sin(theta3) - L4*sin(theta4) + L5*sin(theta5))/L2),),
 (asin((L1*sin(theta1) - L3*sin(theta3) - L4*sin(theta4) + L5*sin(theta5))/L2),)]
[(pi - asin((-L1*sin(theta1) + L2*sin(theta2) + L3*sin(theta3) + L4*sin(theta4))/L5),),
 (asin((-L1*sin(theta1) + L2*sin(theta2) + L3*sin(theta3) + L4*sin(theta4))/L5),)]

我尝试使用 smp.Latex() 函数,但它没有在 markdown 单元格中渲染。我认为 LaTex 代码有问题,但我对 LaTex 语言相对较新,所以我陷入困境。

python latex sympy jupyter-lab
1个回答
0
投票

运行此命令应该使完整的乳胶打印机能够完成其工作。

import sympy as smp
smp.init_printing()

如果这不起作用,请尝试

smp.init_printing(use_latex=True)

© www.soinside.com 2019 - 2024. All rights reserved.