# Unit3: Lagrange Python file Error

Hello!
On running lagrange.py file of Unit3, getting the error of "cannt set attributes,

I ran this whole code in Jupyter Notebook and i didnot get any error.
Kindly help in solving it.
Thanks

Hello @misbahsuhail123,

The first part of the lagrange.py file, where you build the Lagrangian should look like this:


from __future__ import print_function, division
from sympy import symbols, simplify, trigsimp
from sympy.physics.mechanics import (dynamicsymbols, ReferenceFrame, Point,
inertia, RigidBody, Lagrangian, LagrangesMethod)
from sympy.physics.vector import init_vprinting, vlatex
init_vprinting(use_latex='mathjax', pretty_print=False)

inertial_frame = ReferenceFrame('I')

theta_1, theta_2 = dynamicsymbols('theta_1 theta_2')
dtheta_1, dtheta_2 = dynamicsymbols('theta_1 theta_2', 1)

tau_1, tau_2 = dynamicsymbols('tau_1 tau_2')
l_1, l_2 = symbols('l_1 l_2', positive=True)
r_1, r_2 = symbols('r_1 r_2', positive=True)
m_1, m_2, b, g = symbols('m_1 m_2 b g')
I_1_yy, I_2_yy = symbols('I_{1yy}, I_{2yy}')

shoulder = Point('S')
shoulder.set_vel(inertial_frame, 0)

elbow = Point('E')

CM_1 = Point('CM_1')

CM_2 = Point('CM_2')

I_1 = inertia(lower_link_frame, 0, I_1_yy, 0)

I_2 = inertia(upper_link_frame, 0, I_2_yy, 0)

P_1 = m_1 * g * inertial_frame.z
r_1_CM = CM_1.pos_from(shoulder).express(inertial_frame)
BODY_1.potential_energy = r_1_CM.dot(P_1)

P_2 = m_2 * g * inertial_frame.z
r_2_CM = CM_2.pos_from(shoulder).express(inertial_frame).simplify()
BODY_2.potential_energy = r_2_CM.dot(P_2)

L = Lagrangian(inertial_frame, BODY_1, BODY_2)
print(L)


See if you can find any differences,

Cheers,

Roberto

Hello!
Thanks for your help. code is working now

You are welcome. I am glad it helped you fix the issue.

Roberto

This topic was automatically closed after 21 hours. New replies are no longer allowed.