%23%20%2F%2F%2F%20script%0A%23%20requires-python%20%3D%20%22%3E%3D3.11%22%0A%23%20dependencies%20%3D%20%5B%22marimo%3E%3D0.23.9%22%2C%20%22numpy%3E%3D2.0%22%2C%20%22matplotlib%3E%3D3.9%22%2C%20%22scipy%3E%3D1.14%22%2C%20%22sympy%3E%3D1.13%22%2C%20%22seaborn%3E%3D0.13%22%2C%20%22ipython%22%5D%0A%23%20%2F%2F%2F%0A%0Aimport%20marimo%0A%0A__generated_with%20%3D%20%220.25.2%22%0Aapp%20%3D%20marimo.App()%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%20Lagrangian%20mechanics%0A%0A%20%20%20%20%3E%20Marcos%20Duarte%2C%20Renato%20Naville%20Watanabe%3Cbr%3E%0A%20%20%20%20%3E%20%5BLaboratory%20of%20Biomechanics%20and%20Motor%20Control%5D(https%3A%2F%2Fbmclab.pesquisa.ufabc.edu.br%2F)%3Cbr%3E%0A%20%20%20%20%3E%20Federal%20University%20of%20ABC%2C%20Brazil%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20How%20to%20use%20this%20guide%0A%0A%20%20%20%20We%20will%20choose%20independent%20coordinates%2C%20write%20kinetic%20and%20potential%20energy%2C%20and%20use%20Euler%E2%80%93Lagrange%20equations.%20Follow%20the%20simple%20pendulum%20before%20the%20coupled%20systems.%20Then%20add%20nonconservative%20generalized%20forces%20and%20recover%20constraint%20forces%20when%20they%20are%20actually%20needed.%0A%0A%20%20%20%20Try%20the%20distributed%20**Exercises**%20before%20opening%20their%20collapsed%20worked%20solutions.%20Then%20use%20the%20**Checkpoint%20questions**%20and%20attempt%20the%20**Problems**%20independently%3B%20their%20panels%20contain%20final%20answers%20only.%20Predict%20the%20effect%20of%20a%20parameter%20change%20before%20running%20it%2C%20and%20check%20units%20and%20limiting%20cases.%0A%0A%20%20%20%20**Opening%20challenge.**%20A%20pendulum%E2%80%99s%20string%20tension%20changes%20during%20a%20swing.%20Can%20you%20obtain%20the%20angle%20equation%20without%20first%20calculating%20that%20tension%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Python%20setup%0A%0A%20%20%20%20The%20dependency%20declaration%20at%20the%20top%20of%20this%20file%20lists%20the%20packages%20used%20by%20this%20guide.%20Marimo%20runs%20cells%20in%20dependency%20order.%20Run%20the%20notebook%20in%20an%20editor%20to%20use%20its%20displays%20and%20controls%3B%20the%20computational%20examples%20below%20explain%20their%20inputs%20before%20using%20them.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%3Ccenter%3E%3Cdiv%20style%3D%22background-color%3A%23f2f2f2%3Bborder%3A1px%20solid%20black%3Bwidth%3A72%25%3Bpadding%3A5px%2010px%205px%2010px%3Btext-align%3Aleft%3B%22%3E%0A%20%20%20%20%3Ci%3E%22The%20theoretical%20development%20of%20the%20laws%20of%20motion%20of%20bodies%20is%20a%20problem%20of%20such%20interest%20and%20importance%2C%20that%20it%20has%20engaged%20the%20attention%20of%20all%20the%20most%20eminent%20mathematicians%2C%20since%20the%20invention%20of%20dynamics%20as%20a%20mathematical%20science%20by%20%3Cb%3EGalileo%3C%2Fb%3E%2C%20and%20especially%20since%20the%20wonderful%20extension%20which%20was%20given%20to%20that%20science%20by%20%3Cb%3ENewton%3C%2Fb%3E.%20Among%20the%20successors%20of%20those%20illustrious%20men%2C%20%3Cb%3ELagrange%3C%2Fb%3E%20has%20perhaps%20done%20more%20than%20any%20other%20analyst%2C%20to%20give%20extent%20and%20harmony%20to%20such%20deductive%20researches%2C%20by%20showing%20that%20the%20most%20varied%20consequences%20respecting%20the%20motions%20of%20systems%20of%20bodies%20may%20be%20derived%20from%20one%20radical%20formula%3B%20the%20beauty%20of%20the%20method%20so%20suiting%20the%20dignity%20of%20the%20results%2C%20as%20to%20make%20of%20his%20great%20work%20a%20kind%20of%20scientific%20poem.%22%3C%2Fi%3E%20%26nbsp%3B%20%3Cb%3EHamilton%3C%2Fb%3E%20(1834)%0A%20%20%20%20%3C%2Fdiv%3E%3C%2Fcenter%3E%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20%23%20import%20necessary%20libraries%20and%20configure%20environment%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20seaborn%20as%20sns%0A%20%20%20%20sns.set_context('notebook'%2C%20font_scale%3D1.2%2C%20rc%3D%7B%22lines.linewidth%22%3A%202%7D)%0A%20%20%20%20%23%20import%20Sympy%20functions%0A%20%20%20%20import%20sympy%20as%20sym%0A%20%20%20%20from%20sympy%20import%20Symbol%2C%20symbols%2C%20cos%2C%20sin%2C%20Matrix%2C%20simplify%2C%20Eq%2C%20latex%2C%20expand%0A%20%20%20%20from%20sympy.solvers.solveset%20import%20nonlinsolve%0A%20%20%20%20from%20sympy.physics.mechanics%20import%20dynamicsymbols%2C%20mlatex%2C%20init_vprinting%0A%20%20%20%20init_vprinting()%0A%20%20%20%20from%20IPython.display%20import%20display%2C%20Math%0A%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20Eq%2C%0A%20%20%20%20%20%20%20%20Math%2C%0A%20%20%20%20%20%20%20%20Symbol%2C%0A%20%20%20%20%20%20%20%20cos%2C%0A%20%20%20%20%20%20%20%20display%2C%0A%20%20%20%20%20%20%20%20dynamicsymbols%2C%0A%20%20%20%20%20%20%20%20latex%2C%0A%20%20%20%20%20%20%20%20mlatex%2C%0A%20%20%20%20%20%20%20%20nonlinsolve%2C%0A%20%20%20%20%20%20%20%20np%2C%0A%20%20%20%20%20%20%20%20plt%2C%0A%20%20%20%20%20%20%20%20simplify%2C%0A%20%20%20%20%20%20%20%20sin%2C%0A%20%20%20%20%20%20%20%20sym%2C%0A%20%20%20%20%20%20%20%20symbols%2C%0A%20%20%20%20)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Introduction%0A%0A%20%20%20%20We%20know%20that%20some%20problems%20in%20dynamics%20can%20be%20solved%20using%20the%20principle%20of%20conservation%20of%20mechanical%20energy%2C%20that%20the%20total%20mechanical%20energy%20in%20a%20system%20(the%20sum%20of%20potential%20and%20kinetic%20energies)%20is%20constant%20when%20only%20conservative%20forces%20are%20present%20in%20the%20system.%20Such%20approach%20is%20one%20kind%20of%20energy%20methods%2C%20see%20for%20example%2C%20pages%20495-512%20in%20Ruina%20and%20Pratap%20(2019).%0A%0A%20%20%20%20Lagrangian%20mechanics%20(after%20%5BJoseph-Louis%20Lagrange%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FJoseph-Louis_Lagrange))%20can%20be%20seen%20as%20another%20kind%20of%20energy%20methods%2C%20but%20much%20more%20general%2C%20to%20the%20extent%20is%20an%20alternative%20to%20Newtonian%20mechanics.%0A%0A%20%20%20%20The%20Lagrangian%20mechanics%20is%20a%20formulation%20of%20classical%20mechanics%20where%20the%20equations%20of%20motion%20are%20obtained%20from%20the%20kinetic%20and%20potential%20energy%20of%20the%20system%20(scalar%20quantities)%20represented%20in%20generalized%20coordinates%20instead%20of%20using%20Newton's%20laws%20of%20motion%20to%20deduce%20the%20equations%20of%20motion%20from%20the%20forces%20on%20the%20system%20(vector%20quantities)%20represented%20in%20Cartesian%20coordinates.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Generalized%20coordinates%0A%0A%20%20%20%20The%20direct%20application%20of%20Newton's%20laws%20to%20mechanical%20systems%20results%20in%20a%20set%20of%20equations%20of%20motion%20in%20terms%20of%20Cartesian%20coordinates%20of%20each%20of%20the%20particles%20that%20make%20up%20the%20system.%20In%20many%20cases%2C%20this%20is%20not%20the%20most%20convenient%20coordinate%20system%20to%20solve%20the%20problem%20or%20describe%20the%20movement%20of%20the%20system.%20For%20example%2C%20for%20a%20serial%20chain%20of%20rigid%20links%2C%20such%20as%20a%20member%20of%20the%20human%20body%20or%20from%20a%20robot%20manipulator%2C%20it%20may%20be%20simpler%20to%20describe%20the%20positions%20of%20each%20link%20by%20the%20angles%20between%20links.%0A%0A%20%20%20%20Coordinate%20systems%20such%20as%20angles%20of%20a%20chain%20of%20links%20are%20referred%20as%20%5Bgeneralized%20coordinates%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGeneralized_coordinates).%20Generalized%20coordinates%20uniquely%20specify%20the%20positions%20of%20the%20particles%20in%20a%20system.%20Although%20there%20may%20be%20several%20generalized%20coordinates%20to%20describe%20a%20system%2C%20usually%20a%20judicious%20choice%20of%20generalized%20coordinates%20provides%20the%20minimum%20number%20of%20independent%20coordinates%20that%20define%20the%20configuration%20of%20a%20system%20(which%20is%20the%20number%20of%20%3Ca%20href%3D%22https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FDegrees_of_freedom_(mechanics)%22%3Edegrees%20of%20freedom%3C%2Fa%3E%20of%20the%20system)%2C%20turning%20the%20problem%20simpler%20to%20solve.%20In%20this%20case%2C%20when%20the%20number%20of%20generalized%20coordinates%20equals%20the%20number%20of%20degrees%20of%20freedom%2C%20the%20system%20is%20referred%20as%20a%20holonomic%20system.%20In%20a%20non-holonomic%20system%2C%20the%20number%20of%20generalized%20coordinates%20necessary%20do%20describe%20the%20system%20depends%20on%20the%20path%20taken%20by%20the%20system.%0A%0A%20%20%20%20Being%20a%20little%20more%20technical%2C%20according%20to%20%5BWikipedia%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FConfiguration_space_(physics))%3A%3Cbr%3E%0A%20%20%20%20%22In%20classical%20mechanics%2C%20the%20parameters%20that%20define%20the%20configuration%20of%20a%20system%20are%20called%20generalized%20coordinates%2C%20and%20the%20vector%20space%20defined%20by%20these%20coordinates%20is%20called%20the%20configuration%20space%20of%20the%20physical%20system.%20It%20is%20often%20the%20case%20that%20these%20parameters%20satisfy%20mathematical%20constraints%2C%20such%20that%20the%20set%20of%20actual%20configurations%20of%20the%20system%20is%20a%20manifold%20in%20the%20space%20of%20generalized%20coordinates.%20This%20manifold%20is%20called%20the%20configuration%20manifold%20of%20the%20system.%22%0A%0A%20%20%20%20In%20problems%20where%20it%20is%20desired%20to%20use%20generalized%20coordinates%2C%20one%20can%20write%20Newton's%20equations%20of%20motion%20in%20terms%20of%20Cartesian%20coordinates%20and%20then%20transform%20them%20into%20generalized%20coordinates.%20However%2C%20it%20would%20be%20desirable%20and%20convenient%20to%20have%20a%20general%20method%20that%20would%20directly%20establish%20the%20equations%20of%20motion%20in%20terms%20of%20a%20set%20of%20convenient%20generalized%20coordinates.%20In%20addition%2C%20general%20methods%20for%20writing%2C%20and%20perhaps%20solving%2C%20the%20equations%20of%20motion%20in%20terms%20of%20any%20coordinate%20system%20would%20also%20be%20desirable.%20The%20%5BLagrangian%20mechanics%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FLagrangian_mechanics)%20is%20such%20a%20method.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Euler%E2%80%93Lagrange%20equations%0A%0A%20%20%20%20See%20%5Bthis%20notebook%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Flagrangian_mechanics_generalized.py)%20for%20a%20deduction%20of%20the%20Lagrange's%20equation%20in%20generalized%20coordinates.%0A%0A%20%20%20%20Consider%20a%20system%20whose%20configuration%20(positions)%20can%20be%20described%20by%20a%20set%20of%20%24N%24%20generalized%20coordinates%20%24q_i%5C%2C(i%3D1%2C%5Cdotsc%2CN)%24.%0A%0A%20%20%20%20Let's%20define%20the%20Lagrange%20or%20Lagrangian%20function%20%24%5Cmathcal%7BL%7D%24%20as%20the%20difference%20between%20the%20total%20kinetic%20energy%20%24T%24%20and%20the%20total%20potential%20energy%20%24V%24%20of%20the%20system%20in%20terms%20of%20the%20generalized%20coordinates%20as%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BL%7D(t%2Cq%2C%5Cdot%7Bq%7D)%20%3D%20T(%5Cdot%7Bq%7D_1(t)%2C%5Cdotsc%2C%5Cdot%7Bq%7D_N(t))%20-%20V(q_1(t)%2C%5Cdotsc%2Cq_N(t))%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20the%20total%20potential%20energy%20is%20only%20due%20to%20conservative%20forces%2C%20that%20is%2C%20forces%20in%20which%20the%20total%20work%20done%20to%20move%20the%20system%20between%20two%20points%20is%20independent%20of%20the%20path%20taken.%0A%0A%20%20%20%20The%20Euler%E2%80%93Lagrange%20equations%20(or%20Lagrange's%20equations%20of%20the%20second%20kind)%20of%20the%20system%20are%20(omitting%20the%20functions'%20dependencies%20for%20sake%20of%20clarity)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Bq%7D_i%20%7D%7D%0A%20%20%20%20%5Cright)-%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20q_i%20%7D%20%3D%20Q_%7BNCi%7D%20%5Cquad%20i%3D1%2C%5Cdotsc%2CN%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24Q_%7BNCi%7D%24%20are%20the%20generalized%20forces%20due%20to%20non-conservative%20forces%20acting%20on%20the%20system%2C%20any%20forces%20that%20can't%20be%20expressed%20in%20terms%20of%20a%20potential.%0A%0A%20%20%20%20Once%20all%20derivatives%20of%20the%20Lagrangian%20function%20are%20calculated%20and%20substitute%20them%20in%20the%20equations%20above%2C%20the%20result%20is%20the%20equation%20of%20motion%20(EOM)%20for%20each%20generalized%20coordinate.%20There%20will%20be%20%24N%24%20equations%20for%20a%20system%20with%20%24N%24%20generalized%20coordinates.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Steps%20to%20deduce%20the%20Euler-Lagrange%20equations%0A%0A%20%20%20%201.%20Model%20the%20problem.%20Define%20the%20number%20of%20degrees%20of%20freedom.%20Carefully%20select%20the%20corresponding%20generalized%20coordinates%20to%20describe%20the%20system%3B%0A%20%20%20%202.%20Calculate%20the%20total%20kinetic%20and%20total%20potential%20energies%20of%20the%20system.%20Calculate%20the%20Lagrangian%3B%0A%20%20%20%203.%20Calculate%20the%20generalized%20forces%20for%20each%20generalized%20coordinate%3B%0A%20%20%20%204.%20For%20each%20generalized%20coordinate%2C%20calculate%20the%20three%20derivatives%20present%20on%20the%20left%20side%20of%20the%20Euler-Lagrange%20equation%3B%0A%20%20%20%205.%20For%20each%20generalized%20coordinate%2C%20substitute%20the%20result%20of%20these%20three%20derivatives%20in%20the%20left%20side%20and%20the%20corresponding%20generalized%20forces%20in%20the%20right%20side%20of%20the%20Euler-Lagrange%20equation.%0A%0A%20%20%20%20The%20EOM's%2C%20one%20for%20each%20generalized%20coordinate%2C%20are%20the%20result%20of%20the%20last%20step.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Particle%20moving%20under%20the%20influence%20of%20a%20conservative%20force%0A%0A%20%20%20%20Let's%20deduce%20the%20EOM%20of%20a%20particle%20with%20mass%20%24m%24%20moving%20in%20the%20three-dimensional%20space%20under%20the%20influence%20of%20a%20%5Bconservative%20force%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FConservative_force).%0A%0A%20%20%20%20The%20model%20is%20the%20particle%20moving%20in%203D%20space%20and%20there%20is%20no%20generalized%20force%20(non-conservative%20force)%3B%20the%20particle%20has%20three%20degrees%20of%20freedom%20and%20we%20need%20three%20generalized%20coordinates%2C%20which%20can%20be%20%24(x%2C%20y%2C%20z)%24%2C%20where%20%24y%24%20is%20vertical%2C%20in%20a%20Cartesian%20frame%20of%20reference.%3Cbr%3E%0A%20%20%20%20The%20Lagrangian%20%24(%5Cmathcal%7BL%7D%20%3D%20T%20-%20V)%24%20of%20the%20particle%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BL%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7Dm(%5Cdot%20x%5E2(t)%20%2B%20%5Cdot%20y%5E2(t)%20%2B%20%5Cdot%20z%5E2(t))%20-%20V(x(t)%2Cy(t)%2Cz(t))%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20equations%20of%20motion%20for%20the%20particle%20are%20found%20by%20applying%20the%20Euler%E2%80%93Lagrange%20equation%20for%20each%20coordinate.%3Cbr%3E%0A%20%20%20%20For%20the%20%24x%24%20coordinate%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Bx%7D%7D%7D%0A%20%20%20%20%5Cright)%20-%20%5Cfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20x%20%7D%20%3D%200%0A%20%20%20%20%24%24%0A%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20x%7D%20%26%3D%26%20-%5Cdfrac%7B%5Cpartial%20V%7D%7B%5Cpartial%20x%7D%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Bx%7D%7D%20%26%3D%26%20m%5Cdot%7Bx%7D%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Bx%7D%7D%7D%20%5Cright)%20%26%3D%26%20m%5Cddot%7Bx%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Finally%2C%20the%20EOM%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20m%5Cddot%7Bx%7D%20%2B%20%5Cdfrac%7B%5Cpartial%20V%7D%7B%5Cpartial%20x%7D%20%3D%200%20%5Cquad%20%5Crightarrow%20%5C%5C%0A%20%20%20%20m%5Cddot%7Bx%7D%20%3D%20-%5Cdfrac%7B%5Cpartial%20V%7D%7B%5Cpartial%20x%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20and%20same%20procedure%20for%20the%20%24y%24%20and%20%24z%24%20coordinates.%0A%0A%20%20%20%20The%20equation%20above%20is%20the%20Newton's%20second%20law%20of%20motion.%0A%0A%20%20%20%20For%20instance%2C%20if%20the%20conservative%20force%20is%20due%20to%20the%20gravitational%20field%20near%20Earth's%20surface%20%24(V%3D%5B0%2C%20mgy%2C%200%5D)%24%2C%20the%20Euler%E2%80%93Lagrange%20equations%20(the%20EOM's)%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20m%5Cddot%7Bx%7D%20%26%3D%26%20-%5Cdfrac%7B%5Cpartial%20(0)%7D%7B%5Cpartial%20x%7D%20%26%3D%26%200%20%5C%5C%0A%20%20%20%20m%5Cddot%7By%7D%20%26%3D%26%20-%5Cdfrac%7B%5Cpartial%20(mgy)%7D%7B%5Cpartial%20y%7D%20%26%3D%26%20-mg%20%5C%5C%0A%20%20%20%20m%5Cddot%7Bz%7D%20%26%3D%26%20-%5Cdfrac%7B%5Cpartial%20(0)%7D%7B%5Cpartial%20z%7D%20%26%3D%26%200%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%201%20%E2%80%94%20Build%20a%20Lagrangian.**%20For%20a%20horizontal%20spring%E2%80%93mass%20system%20with%20extension%20%24x%24%2C%20write%20%24L%24%20and%20obtain%20its%20equation%20of%20motion.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%201%0A%0A%20%20%20%20%24L%3D%5Ctfrac12m%5Cdot%20x%5E2-%5Ctfrac12kx%5E2%24.%20The%20Euler%E2%80%93Lagrange%20terms%20are%20%24d(%5Cpartial%20L%2F%5Cpartial%5Cdot%20x)%2Fdt%3Dm%5Cddot%20x%24%20and%20%24%5Cpartial%20L%2F%5Cpartial%20x%3D-kx%24%2C%20giving%20%24m%5Cddot%20x%2Bkx%3D0%24.%20Energy%20bookkeeping%20reproduces%20force%20balance.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Ideal%20mass-spring%20system%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fmassspring_lagrange.png%3Fraw%3D1%22%20width%3D%22220%22%20alt%3D%22mass%20spring%22%20style%3D%22float%3Aright%3Bmargin%3A%200px%2020px%2010px%2020px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20a%20system%20with%20a%20mass%20%24m%24%20attached%20to%20an%20ideal%20spring%20(massless%2C%20length%20%24%5Cell_0%24%2C%20and%20spring%20constant%20%24k%24)%20at%20the%20horizontal%20direction%20%24x%24.%20A%20force%20is%20momentarily%20applied%20to%20the%20mass%20and%20then%20the%20system%20is%20left%20unperturbed.%3Cbr%3E%0A%20%20%20%20Let's%20deduce%20the%20EOM%20of%20this%20system.%0A%0A%20%20%20%20The%20system%20can%20be%20modeled%20as%20a%20particle%20attached%20to%20a%20spring%20moving%20at%20the%20direction%20%24x%24%2C%20the%20only%20generalized%20coordinate%20needed%20(with%20origin%20of%20the%20Cartesian%20reference%20frame%20at%20the%20wall%20where%20the%20spring%20is%20attached)%2C%20and%20there%20is%20no%20generalized%20force.%3Cbr%3E%0A%20%20%20%20The%20Lagrangian%20%24(%5Cmathcal%7BL%7D%20%3D%20T%20-%20V)%24%20of%20the%20system%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BL%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7Dm%5Cdot%20x%5E2%20-%20%5Cfrac%7B1%7D%7B2%7Dk(x-%5Cell_0)%5E2%0A%20%20%20%20%24%24%0A%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20x%7D%20%26%3D%26%20-k(x-%5Cell_0)%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Bx%7D%7D%20%26%3D%26%20m%5Cdot%7Bx%7D%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Bx%7D%7D%7D%20%5Cright)%20%26%3D%26%20m%5Cddot%7Bx%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Finally%2C%20the%20Euler%E2%80%93Lagrange%20equation%20(the%20EOM)%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20m%5Cddot%7Bx%7D%20%2B%20k(x-%5Cell_0)%20%3D%200%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Simple%20pendulum%20under%20the%20influence%20of%20gravity%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fsimplependulum_lagrange.png%3Fraw%3D1%22%20width%3D%22220%22%20alt%3D%22simple%20pendulum%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2050px%2010px%2050px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20a%20pendulum%20with%20a%20massless%20rod%20of%20length%20%24d%24%20and%20a%20mass%20%24m%24%20at%20the%20extremity%20swinging%20in%20a%20plane%20forming%20the%20angle%20%24%5Ctheta%24%20with%20the%20vertical.%3Cbr%3E%0A%20%20%20%20Let's%20deduce%20the%20EOM%20of%20this%20system.%0A%0A%20%20%20%20The%20model%20is%20a%20particle%20oscillating%20as%20a%20pendulum%20under%20a%20constant%20gravitational%20force%20%24-mg%24.%3Cbr%3E%0A%20%20%20%20Although%20the%20pendulum%20moves%20at%20the%20plane%2C%20it%20only%20has%20one%20degree%20of%20freedom%2C%20which%20can%20be%20described%20by%20the%20angle%20%24%5Ctheta%24%2C%20the%20generalized%20coordinate.%20Let's%20adopt%20the%20origin%20of%20the%20reference%20frame%20at%20the%20point%20of%20the%20pendulum%20suspension.%0A%0A%20%20%20%20The%20kinetic%20energy%20of%20the%20system%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20T%20%3D%20%5Cfrac%7B1%7D%7B2%7Dmv%5E2%20%3D%20%5Cfrac%7B1%7D%7B2%7Dm(%5Cdot%7Bx%7D%5E2%2B%5Cdot%7By%7D%5E2)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24%5Cdot%7Bx%7D%24%20and%20%24%5Cdot%7By%7D%24%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20x%20%3D%20d%5Csin(%5Ctheta)%20%5C%5C%0A%20%20%20%20y%20%3D%20-d%5Ccos(%5Ctheta)%20%5C%5C%0A%20%20%20%20%5Cdot%7Bx%7D%20%3D%20d%5Ccos(%5Ctheta)%5Cdot%7B%5Ctheta%7D%20%5C%5C%0A%20%20%20%20%5Cdot%7By%7D%20%3D%20d%5Csin(%5Ctheta)%5Cdot%7B%5Ctheta%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Consequently%2C%20the%20kinetic%20energy%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20T%20%3D%20%5Cfrac%7B1%7D%7B2%7Dm%5Cleft((d%5Ccos(%5Ctheta)%5Cdot%7B%5Ctheta%7D)%5E2%20%2B%20(d%5Csin(%5Ctheta)%5Cdot%7B%5Ctheta%7D)%5E2%5Cright)%20%3D%20%5Cfrac%7B1%7D%7B2%7Dmd%5E2%5Cdot%7B%5Ctheta%7D%5E2%0A%20%20%20%20%24%24%0A%0A%20%20%20%20And%20the%20potential%20energy%20of%20the%20system%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20V%20%3D%20-mgy%20%3D%20-mgd%5Ccos%5Ctheta%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20Lagrangian%20function%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BL%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7Dmd%5E2%5Cdot%5Ctheta%5E2%20%2B%20mgd%5Ccos%5Ctheta%0A%20%20%20%20%24%24%0A%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Ctheta%7D%20%26%3D%26%20-mgd%5Csin%5Ctheta%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7B%5Ctheta%7D%7D%20%26%3D%26%20md%5E2%5Cdot%7B%5Ctheta%7D%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7B%5Ctheta%7D%7D%7D%20%5Cright)%20%26%3D%26%20md%5E2%5Cddot%7B%5Ctheta%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Finally%2C%20the%20Euler%E2%80%93Lagrange%20equation%20(the%20EOM)%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20md%5E2%5Cddot%5Ctheta%20%2B%20mgd%5Csin%5Ctheta%20%3D%200%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Note%20that%20although%20the%20generalized%20coordinate%20of%20the%20system%20is%20%24%5Ctheta%24%2C%20we%20had%20to%20employ%20Cartesian%20coordinates%20at%20the%20beginning%20to%20derive%20expressions%20for%20the%20kinetic%20and%20potential%20energies.%20For%20kinetic%20energy%2C%20we%20could%20have%20used%20its%20equivalent%20definition%20for%20circular%20motion%20%24(T%3DI%5Cdot%7B%5Ctheta%7D%5E2%2F2%3Dmd%5E2%5Cdot%7B%5Ctheta%7D%5E2%2F2)%24%2C%20but%20for%20the%20potential%20energy%20there%20is%20no%20other%20way%20since%20the%20gravitational%20force%20acts%20in%20the%20vertical%20direction.%0A%20%20%20%20In%20cases%20like%20this%2C%20a%20fundamental%20aspect%20is%20to%20express%20the%20Cartesian%20coordinates%20in%20terms%20of%20the%20generalized%20coordinates.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%23%20Numerical%20solution%20of%20the%20equation%20of%20motion%20for%20the%20simple%20pendulum%0A%0A%20%20%20%20A%20classical%20approach%20to%20solve%20analytically%20the%20EOM%20for%20the%20simple%20pendulum%20is%20to%20consider%20the%20motion%20for%20small%20angles%20where%20%24%5Csin%5Ctheta%20%5Capprox%20%5Ctheta%24%20and%20the%20differential%20equation%20is%20linearized%20to%20%24d%5Cddot%5Ctheta%20%2B%20g%5Ctheta%20%3D%200%24.%20This%20equation%20has%20an%20analytical%20solution%20of%20the%20type%20%24%5Ctheta(t)%20%3D%20A%20%5Csin(%5Comega%20t%20%2B%20%5Cphi)%24%2C%20where%20%24%5Comega%20%3D%20%5Csqrt%7Bg%2Fd%7D%24%20and%20%24A%24%20and%20%24%5Cphi%24%20are%20constants%20related%20to%20the%20initial%20position%20and%20velocity.%3Cbr%3E%0A%20%20%20%20For%20didactic%20purposes%2C%20let's%20solve%20numerically%20the%20differential%20equation%20for%20the%20pendulum%20using%20%5BEuler%E2%80%99s%20method%5D(ordinary_differential_equation.py%23euler-method).%0A%0A%20%20%20%20Remember%20that%20we%20have%20to%3A%3Cbr%3E%0A%20%20%20%201.%20Transform%20the%20second-order%20ODE%20into%20two%20coupled%20first-order%20ODEs%2C%3Cbr%3E%0A%20%20%20%202.%20Approximate%20the%20derivative%20of%20each%20variable%20by%20its%20discrete%20first%20order%20difference%3Cbr%3E%0A%20%20%20%203.%20Write%20an%20equation%20to%20calculate%20the%20variable%20in%20a%20recursive%20way%2C%20updating%20its%20value%20with%20an%20equation%20based%20on%20the%20first%20order%20difference.%0A%0A%20%20%20%20We%20will%20also%20implement%20different%20variations%20of%20the%20Euler%20method%3A%20Forward%20(standard)%2C%20Semi-implicit%2C%20and%20Semi-implicit%20variation%20(same%20results%20as%20Semi-implicit).%0A%0A%20%20%20%20Implementing%20these%20steps%20in%20Python%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plt)%3A%0A%20%20%20%20def%20euler_method(T%3D10%2C%20y0%3D%5B0%2C%200%5D%2C%20h%3D0.01%2C%20method%3D2%2C%20dvdt%3DNone)%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20First-order%20numerical%20approximation%20for%20solving%20two%20coupled%20first-order%20ODEs.%0A%0A%20%20%20%20%20%20%20%20A%20first-order%20differential%20equation%20is%20an%20initial%20value%20problem%20of%20the%20form%3A%0A%20%20%20%20%20%20%20%20y'(t)%20%3D%20f(t%2C%20y(t))%20%20%3B%20%20y(t0)%20%3D%20y0%0A%0A%20%20%20%20%20%20%20%20Parameters%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20T%3A%20total%20period%20(in%20s)%20of%20the%20numerical%20integration%0A%20%20%20%20%20%20%20%20%20%20%20%20y0%3A%20initial%20state%20%5Bposition%2C%20velocity%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20h%3A%20step%20for%20the%20numerical%20integration%0A%20%20%20%20%20%20%20%20%20%20%20%20method%3A%20Euler%20method%20implementation%2C%20one%20of%20the%20following%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%201%3A%20'forward'%20(standard)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%202%3A%20'semi-implicit'%20(a.k.a.%2C%20symplectic%2C%20Euler%E2%80%93Cromer)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%203%3A%20'semi-implicit%20variation'%20(same%20results%20as%20'semi-implicit')%0A%20%20%20%20%20%20%20%20%20%20%20%20dvdt%3A%20function%20dvdt(t%2C%20y)%20for%20the%20acceleration%20(default%3A%20simple%20pendulum)%0A%20%20%20%20%20%20%20%20Two%20coupled%20first-order%20ODEs%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20dydt%20%3D%20v%0A%20%20%20%20%20%20%20%20%20%20%20%20dvdt%20%3D%20a%20%20%23%20calculate%20the%20expression%20for%20acceleration%20at%20each%20step%0A%20%20%20%20%20%20%20%20Two%20equations%20to%20update%20the%20values%20of%20the%20variables%20based%20on%20first-order%20difference%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20y%5Bi%2B1%5D%20%3D%20y%5Bi%5D%20%2B%20h*v%5Bi%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20v%5Bi%2B1%5D%20%3D%20v%5Bi%5D%20%2B%20h*dvdt%5Bi%5D%0A%20%20%20%20%20%20%20%20Returns%20arrays%20time%2C%20%5Bposition%2C%20velocity%5D%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20if%20dvdt%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20def%20dvdt(t%2C%20y)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%22%22%22Simple%20pendulum%20acceleration%20for%20d%20%3D%200.5%20m%2C%20g%20%3D%2010%20m%2Fs%C2%B2.%22%22%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20return%20-10%20%2F%200.5%20*%20np.sin(y%5B0%5D)%0A%20%20%20%20%20%20%20%20N%20%3D%20int(np.ceil(T%20%2F%20h))%0A%20%20%20%20%20%20%20%20y%20%3D%20np.zeros((2%2C%20N))%0A%20%20%20%20%20%20%20%20y%5B%3A%2C%200%5D%20%3D%20y0%0A%20%20%20%20%20%20%20%20t%20%3D%20np.linspace(0%2C%20T%2C%20N%2C%20endpoint%3DFalse)%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(N%20-%201)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20method%20%3D%3D%201%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%5B0%2C%20i%20%2B%201%5D%20%3D%20y%5B0%2C%20i%5D%20%2B%20h%20*%20y%5B1%2C%20i%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%5B1%2C%20i%20%2B%201%5D%20%3D%20y%5B1%2C%20i%5D%20%2B%20h%20*%20dvdt(t%5Bi%5D%2C%20y%5B%3A%2C%20i%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20method%20%3D%3D%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%5B1%2C%20i%20%2B%201%5D%20%3D%20y%5B1%2C%20i%5D%20%2B%20h%20*%20dvdt(t%5Bi%5D%2C%20y%5B%3A%2C%20i%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%5B0%2C%20i%20%2B%201%5D%20%3D%20y%5B0%2C%20i%5D%20%2B%20h%20*%20y%5B1%2C%20i%20%2B%201%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20elif%20method%20%3D%3D%203%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%5B0%2C%20i%20%2B%201%5D%20%3D%20y%5B0%2C%20i%5D%20%2B%20h%20*%20y%5B1%2C%20i%5D%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20y%5B1%2C%20i%20%2B%201%5D%20%3D%20y%5B1%2C%20i%5D%20%2B%20h%20*%20dvdt(t%5Bi%5D%2C%20%5By%5B0%2C%20i%20%2B%201%5D%2C%20y%5B1%2C%20i%5D%5D)%0A%20%20%20%20%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError('Valid%20options%20for%20method%20are%201%2C%202%2C%203.')%0A%20%20%20%20%20%20%20%20return%20(t%2C%20y)%0A%0A%20%20%20%20def%20plot(t%2C%20y%2C%20labels)%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Plot%20data%20given%20in%20t%2C%20y%2C%20v%20with%20labels%20%5Btitle%2C%20ylabel%40left%2C%20ylabel%40right%5D%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20(fig%2C%20ax1)%20%3D%20plt.subplots(1%2C%201%2C%20figsize%3D(10%2C%204))%0A%20%20%20%20%20%20%20%20ax1.set_title(labels%5B0%5D)%0A%20%20%20%20%20%20%20%20ax1.plot(t%2C%20y%5B0%2C%20%3A%5D%2C%20'b'%2C%20label%3D'%20')%0A%20%20%20%20%20%20%20%20ax1.set_xlabel('Time%20(s)')%0A%20%20%20%20%20%20%20%20ax1.set_ylabel(u'%E2%80%94%20'%20%2B%20labels%5B1%5D%2C%20color%3D'b')%0A%20%20%20%20%20%20%20%20ax1.tick_params('y'%2C%20colors%3D'b')%0A%20%20%20%20%20%20%20%20ax2%20%3D%20ax1.twinx()%0A%20%20%20%20%20%20%20%20ax2.plot(t%2C%20y%5B1%2C%20%3A%5D%2C%20'r-.'%2C%20label%3D'%20')%0A%20%20%20%20%20%20%20%20ax2.set_ylabel(u'%E2%80%94%20%E2%80%A7%20'%20%2B%20labels%5B2%5D%2C%20color%3D'r')%0A%20%20%20%20%20%20%20%20ax2.tick_params('y'%2C%20colors%3D'r')%0A%20%20%20%20%20%20%20%20plt.tight_layout()%0A%20%20%20%20%20%20%20%20plt.show()%0A%0A%20%20%20%20return%20euler_method%2C%20plot%0A%0A%0A%40app.cell%0Adef%20_(euler_method%2C%20np%2C%20plot)%3A%0A%20%20%20%20(T%2C%20_y0%2C%20_h)%20%3D%20(10%2C%20%5B45%20*%20np.pi%20%2F%20180%2C%200%5D%2C%200.01)%0A%20%20%20%20(_t%2C%20theta)%20%3D%20euler_method(T%2C%20_y0%2C%20_h%2C%20method%3D2)%0A%20%20%20%20_labels%20%3D%20%5B'Trajectory%20of%20simple%20pendulum%20under%20gravity'%2C%20'Angular%20position%20(%24%5Eo%24)'%2C%20'Angular%20velocity%20(%24%5Eo%2Fs%24)'%5D%0A%20%20%20%20plot(_t%2C%20np.rad2deg(theta)%2C%20_labels)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Python%20code%20to%20automate%20the%20calculation%20of%20the%20Euler%E2%80%93Lagrange%20equation%0A%0A%20%20%20%20The%20three%20derivatives%20in%20the%20Euler%E2%80%93Lagrange%20equations%20are%20first-order%20derivatives%20and%20behind%20the%20scenes%20we%20are%20using%20latex%20to%20write%20the%20equations.%20Both%20tasks%20are%20boring%20and%20error%20prone.%3Cbr%3E%0A%20%20%20%20Let's%20write%20a%20function%20using%20the%20Sympy%20library%20to%20automate%20the%20calculation%20of%20the%20derivative%20terms%20in%20the%20Euler%E2%80%93Lagrange%20equations%20and%20display%20them%20nicely.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eq%2C%20Math%2C%20Symbol%2C%20display%2C%20latex%2C%20mlatex%2C%20nonlinsolve%2C%20simplify)%3A%0A%20%20%20%20t%20%3D%20Symbol('t')%0A%20%20%20%20%23%20helping%20function%0A%20%20%20%20def%20printeq(lhs%2C%20rhs%3DNone)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Rich%20display%20of%20Sympy%20expression%20as%20lhs%20%3D%20rhs.%22%22%22%0A%20%20%20%20%20%20%20%20if%20rhs%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20display(Math(r'%7B%7D'.format(lhs)))%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20display(Math(r'%7B%7D%20%3D%20'.format(lhs)%20%2B%20mlatex(simplify(rhs%2C%20ratio%3D1.7))))%0A%0A%0A%20%20%20%20def%20lagrange_terms(L%2C%20q%2C%20show%3DTrue)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Calculate%20terms%20of%20Euler-Lagrange%20equations%20given%20the%20Lagrangian%20and%20q's.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20if%20not%20isinstance(q%2C%20list)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20q%20%3D%20%5Bq%5D%0A%20%20%20%20%20%20%20%20Lterms%20%3D%20%5B%5D%0A%20%20%20%20%20%20%20%20if%20show%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20s%20%3D%20''%20if%20len(q)%20%3D%3D%201%20else%20's'%0A%20%20%20%20%20%20%20%20%20%20%20%20printeq(r%22%5Ctext%7BTerms%20of%20the%20Euler-Lagrange%20equation%25s%3A%7D%22%25(s))%0A%20%20%20%20%20%20%20%20for%20qi%20in%20q%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20dLdqi%20%3D%20simplify(L.diff(qi))%0A%20%20%20%20%20%20%20%20%20%20%20%20Lterms.append(dLdqi)%0A%20%20%20%20%20%20%20%20%20%20%20%20dLdqdi%20%3D%20simplify(L.diff(qi.diff(t)))%0A%20%20%20%20%20%20%20%20%20%20%20%20Lterms.append(dLdqdi)%0A%20%20%20%20%20%20%20%20%20%20%20%20dtdLdqdi%20%3D%20simplify(dLdqdi.diff(t))%0A%20%20%20%20%20%20%20%20%20%20%20%20Lterms.append(dtdLdqdi)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20show%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20printeq(r'%5Ctext%7BFor%20generalized%20coordinate%7D%5C%3B%25s%3A'%25latex(qi.func))%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20printeq(r'%5Cquad%5Cdfrac%7B%5Cpartial%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%25s%7D'%25latex(qi.func)%2C%20dLdqi)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20printeq(r'%5Cquad%5Cdfrac%7B%5Cpartial%5Cmathcal%7BL%7D%7D%7B%5Cpartial%5Cdot%7B%25s%7D%7D'%25latex(qi.func)%2C%20dLdqdi)%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20printeq(r'%5Cquad%5Cdfrac%7B%5Cmathrm%20d%7D%7B%5Cmathrm%7Bdt%7D%7D%5Cleft(%7B%5Cdfrac%7B'%2B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20r'%5Cpartial%5Cmathcal%7BL%7D%7D%7B%5Cpartial%5Cdot%7B%25s%7D%7D%7D%5Cright)'%25latex(qi.func)%2C%20dtdLdqdi)%0A%20%20%20%20%20%20%20%20return%20Lterms%0A%0A%0A%20%20%20%20def%20lagrange_eq(Lterms%2C%20Qnc%3DNone)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Display%20Euler-Lagrange%20equation%20given%20the%20Lterms.%22%22%22%0A%20%20%20%20%20%20%20%20s%20%3D%20''%20if%20len(Lterms)%20%3D%3D%203%20else%20's'%0A%20%20%20%20%20%20%20%20if%20Qnc%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20Qnc%20%3D%20int(len(Lterms)%2F3)%20*%20%5B0%5D%0A%20%20%20%20%20%20%20%20printeq(r%22%5Ctext%7BEuler-Lagrange%20equation%25s%20(EOM)%3A%7D%22%25(s))%0A%20%20%20%20%20%20%20%20for%20i%20in%20range(int(len(Lterms)%2F3))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%23display(Eq(simplify(Lterms%5B3*i%2B2%5D-Lterms%5B3*i%5D)%2C%20Qnc%5Bi%5D%2C%20evaluate%3DFalse))%0A%20%20%20%20%20%20%20%20%20%20%20%20printeq(r'%5Cquad%20'%20%2B%20mlatex(simplify(Lterms%5B3*i%2B2%5D-Lterms%5B3*i%5D))%2C%20Qnc%5Bi%5D)%0A%0A%0A%20%20%20%20def%20lagrange_eq_solve(Lterms%2C%20q%2C%20Qnc%3DNone)%3A%0A%20%20%20%20%20%20%20%20%22%22%22Display%20Euler-Lagrange%20equation%20given%20the%20Lterms.%22%22%22%0A%20%20%20%20%20%20%20%20if%20not%20isinstance(q%2C%20list)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20q%20%3D%20%5Bq%5D%0A%20%20%20%20%20%20%20%20if%20Qnc%20is%20None%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20Qnc%20%3D%20int(len(Lterms)%2F3)%20*%20%5B0%5D%0A%20%20%20%20%20%20%20%20system%20%3D%20%5Bsimplify(Lterms%5B3*i%2B2%5D-Lterms%5B3*i%5D-Qnc%5Bi%5D)%20for%20i%20in%20range(len(q))%5D%0A%20%20%20%20%20%20%20%20qdds%20%3D%20%5Bqi.diff(t%2C%202)%20for%20qi%20in%20q%5D%0A%20%20%20%20%20%20%20%20sol%20%3D%20nonlinsolve(system%2C%20qdds)%0A%20%20%20%20%20%20%20%20s%20%3D%20''%20if%20len(Lterms)%20%3D%3D%203%20else%20's'%0A%20%20%20%20%20%20%20%20printeq(r%22%5Ctext%7BEuler-Lagrange%20equation%25s%20(EOM)%3A%7D%22%25(s))%0A%20%20%20%20%20%20%20%20if%20len(sol.args)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20for%20i%20in%20range(int(len(Lterms)%2F3))%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20display(Eq(qdds%5Bi%5D%2C%20simplify(sol.args%5B0%5D%5Bi%5D)%2C%20evaluate%3DFalse))%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20display(sol)%0A%0A%20%20%20%20%20%20%20%20return%20sol%0A%0A%20%20%20%20return%20lagrange_eq%2C%20lagrange_eq_solve%2C%20lagrange_terms%2C%20printeq%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Let's%20recalculate%20the%20EOM%20of%20the%20simple%20pendulum%20using%20Sympy%20and%20the%20code%20for%20automation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dynamicsymbols%2C%20sym)%3A%0A%20%20%20%20t_1%20%3D%20sym.Symbol('t')%0A%20%20%20%20(m%2C%20d%2C%20g)%20%3D%20sym.symbols('m%2C%20d%2C%20g'%2C%20positive%3DTrue)%0A%20%20%20%20%CE%B8%20%3D%20dynamicsymbols('theta')%0A%20%20%20%20return%20d%2C%20g%2C%20m%2C%20t_1%2C%20%CE%B8%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Position%20and%20velocity%20of%20the%20simple%20pendulum%20under%20the%20influence%20of%20gravity%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cos%2C%20d%2C%20printeq%2C%20sin%2C%20t_1%2C%20%CE%B8)%3A%0A%20%20%20%20(x%2C%20y)%20%3D%20(d%20*%20sin(%CE%B8)%2C%20-d%20*%20cos(%CE%B8))%0A%20%20%20%20(xd%2C%20yd)%20%3D%20(x.diff(t_1)%2C%20y.diff(t_1))%0A%20%20%20%20printeq('x'%2C%20x)%0A%20%20%20%20printeq('y'%2C%20y)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D'%2C%20xd)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D'%2C%20yd)%0A%20%20%20%20return%20xd%2C%20y%2C%20yd%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Kinetic%20and%20potential%20energies%20of%20the%20simple%20pendulum%20under%20the%20influence%20of%20gravity%20and%20the%20corresponding%20Lagrangian%20function%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(g%2C%20m%2C%20printeq%2C%20xd%2C%20y%2C%20yd)%3A%0A%20%20%20%20T_1%20%3D%20m%20*%20(xd%20**%202%20%2B%20yd%20**%202)%20%2F%202%0A%20%20%20%20V%20%3D%20m%20*%20g%20*%20y%0A%20%20%20%20printeq('T'%2C%20T_1)%0A%20%20%20%20printeq('V'%2C%20V)%0A%20%20%20%20L%20%3D%20T_1%20-%20V%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L)%0A%20%20%20%20return%20(L%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20the%20automated%20part%20for%20the%20derivatives%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(L%2C%20lagrange_terms%2C%20%CE%B8)%3A%0A%20%20%20%20Lterms%20%3D%20lagrange_terms(L%2C%20%CE%B8)%0A%20%20%20%20return%20(Lterms%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Finally%2C%20the%20EOM%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms%2C%20lagrange_eq)%3A%0A%20%20%20%20lagrange_eq(Lterms)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20rearranging%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms%2C%20lagrange_eq_solve%2C%20%CE%B8)%3A%0A%20%20%20%20sol%20%3D%20lagrange_eq_solve(Lterms%2C%20q%3D%CE%B8%2C%20Qnc%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Same%20result%20as%20before.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%202%20%E2%80%94%20Check%20a%20pendulum%20sign.**%20For%20a%20point%20pendulum%20with%20angle%20from%20the%20downward%20vertical%2C%20use%20%24V%3D-mg%5Cell%5Ccos%5Ctheta%24%20to%20find%20its%20gravity%20term.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%202%0A%0A%20%20%20%20%24%5Cpartial%20V%2F%5Cpartial%5Ctheta%3Dmg%5Cell%5Csin%5Ctheta%24%20and%20%24I%3Dm%5Cell%5E2%24.%20Thus%20%24m%5Cell%5E2%5Cddot%5Ctheta%2Bmg%5Cell%5Csin%5Ctheta%3D0%24.%20A%20small%20positive%20angle%20produces%20negative%20acceleration%2C%20as%20a%20restoring%20force%20should.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Double%20pendulum%20under%20the%20influence%20of%20gravity%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fdoublependulum_lagrange.png%3Fraw%3D1%22%20width%3D%22200%22%20alt%3D%22double%20pendulum%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2050px%2010px%2050px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20a%20double%20pendulum%20(one%20pendulum%20attached%20to%20another)%20with%20massless%20rods%20of%20length%20%24d_1%24%20and%20%24d_2%24%20and%20masses%20%24m_1%24%20and%20%24m_2%24%20at%20the%20extremities%20of%20each%20rod%20swinging%20in%20a%20plane%20forming%20the%20angles%20%24%5Ctheta_1%24%20and%20%24%5Ctheta_2%24%20with%20vertical.%3Cbr%3E%0A%20%20%20%20The%20system%20has%20two%20particles%20with%20two%20degrees%20of%20freedom%3B%20two%20adequate%20generalized%20coordinates%20to%20describe%20the%20system's%20configuration%20are%20the%20angles%20in%20relation%20to%20the%20vertical%20(%24%5Ctheta_1%2C%20%5Ctheta_2%24).%20Let's%20adopt%20the%20origin%20of%20the%20reference%20frame%20at%20the%20point%20of%20the%20upper%20pendulum%20suspension.%0A%0A%20%20%20%20Let's%20use%20Sympy%20to%20solve%20this%20problem.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Symbol%2C%20dynamicsymbols%2C%20symbols)%3A%0A%20%20%20%20t_2%20%3D%20Symbol('t')%0A%20%20%20%20(d1%2C%20d2%2C%20m1%2C%20m2%2C%20g_1)%20%3D%20symbols('d1%2C%20d2%2C%20m1%2C%20m2%2C%20g'%2C%20positive%3DTrue)%0A%20%20%20%20(%CE%B81%2C%20%CE%B82)%20%3D%20dynamicsymbols('theta1%2C%20theta2')%0A%20%20%20%20return%20d1%2C%20d2%2C%20g_1%2C%20m1%2C%20m2%2C%20t_2%2C%20%CE%B81%2C%20%CE%B82%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20positions%20and%20velocities%20of%20masses%20%24m_1%24%20and%20%24m_2%24%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cos%2C%20d1%2C%20d2%2C%20printeq%2C%20sin%2C%20t_2%2C%20%CE%B81%2C%20%CE%B82)%3A%0A%20%20%20%20_x1%20%3D%20d1%20*%20sin(%CE%B81)%0A%20%20%20%20y1%20%3D%20-d1%20*%20cos(%CE%B81)%0A%20%20%20%20_x2%20%3D%20d1%20*%20sin(%CE%B81)%20%2B%20d2%20*%20sin(%CE%B82)%0A%20%20%20%20y2%20%3D%20-d1%20*%20cos(%CE%B81)%20-%20d2%20*%20cos(%CE%B82)%0A%20%20%20%20(x1d%2C%20y1d)%20%3D%20(_x1.diff(t_2)%2C%20y1.diff(t_2))%0A%20%20%20%20(x2d%2C%20y2d)%20%3D%20(_x2.diff(t_2)%2C%20y2.diff(t_2))%0A%20%20%20%20printeq('x_1'%2C%20_x1)%0A%20%20%20%20printeq('y_1'%2C%20y1)%0A%20%20%20%20printeq('x_2'%2C%20_x2)%0A%20%20%20%20printeq('y_2'%2C%20y2)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D_1'%2C%20x1d)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D_1'%2C%20y1d)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D_2'%2C%20x2d)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D_2'%2C%20y2d)%0A%20%20%20%20return%20x1d%2C%20x2d%2C%20y1%2C%20y1d%2C%20y2%2C%20y2d%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20kinetic%20and%20potential%20energies%20of%20the%20system%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(g_1%2C%20m1%2C%20m2%2C%20printeq%2C%20x1d%2C%20x2d%2C%20y1%2C%20y1d%2C%20y2%2C%20y2d)%3A%0A%20%20%20%20T_2%20%3D%20m1%20*%20(x1d%20**%202%20%2B%20y1d%20**%202)%20%2F%202%20%2B%20m2%20*%20(x2d%20**%202%20%2B%20y2d%20**%202)%20%2F%202%0A%20%20%20%20V_1%20%3D%20m1%20*%20g_1%20*%20y1%20%2B%20m2%20*%20g_1%20*%20y2%0A%20%20%20%20printeq('T'%2C%20T_2)%0A%20%20%20%20printeq('V'%2C%20V_1)%0A%20%20%20%20return%20T_2%2C%20V_1%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20Lagrangian%20function%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(T_2%2C%20V_1%2C%20printeq)%3A%0A%20%20%20%20L_1%20%3D%20T_2%20-%20V_1%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L_1)%0A%20%20%20%20return%20(L_1%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(L_1%2C%20lagrange_terms%2C%20%CE%B81%2C%20%CE%B82)%3A%0A%20%20%20%20Lterms_1%20%3D%20lagrange_terms(L_1%2C%20%5B%CE%B81%2C%20%CE%B82%5D)%0A%20%20%20%20return%20(Lterms_1%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Finally%2C%20the%20EOM%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms_1%2C%20lagrange_eq)%3A%0A%20%20%20%20lagrange_eq(Lterms_1)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20EOM's%20are%20a%20system%20with%20two%20coupled%20equations%2C%20%24%5Ctheta_1%24%20and%20%24%5Ctheta_2%24%20appear%20on%20both%20equations.%0A%0A%20%20%20%20The%20motion%20of%20a%20double%20pendulum%20is%20very%20interesting%3B%20most%20of%20times%20it%20presents%20a%20chaotic%20behavior.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%23%20Numerical%20solution%20of%20the%20equation%20of%20motion%20for%20the%20double%20pendulum%0A%0A%20%20%20%20The%20analytical%20solution%20in%20infeasible%20to%20deduce.%20For%20the%20numerical%20solution%2C%20first%20we%20have%20to%20rearrange%20the%20equations%20to%20find%20separate%20expressions%20for%20%24%5Ctheta_1%24%20and%20%24%5Ctheta_2%24%20(solve%20the%20system%20of%20equations%20algebraically).%3Cbr%3E%0A%20%20%20%20Using%20Sympy%2C%20here%20are%20the%20two%20expressions%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms_1%2C%20lagrange_eq_solve%2C%20%CE%B81%2C%20%CE%B82)%3A%0A%20%20%20%20sol_1%20%3D%20lagrange_eq_solve(Lterms_1%2C%20q%3D%5B%CE%B81%2C%20%CE%B82%5D%2C%20Qnc%3DNone)%0A%20%20%20%20return%20(sol_1%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20In%20order%20to%20solve%20numerically%20the%20ODEs%20for%20the%20double%20pendulum%20we%20have%20to%20transform%20each%20equation%20above%20into%20two%20first%20ODEs.%20But%20we%20should%20avoid%20using%20Euler's%20method%20because%20of%20the%20non-negligible%20error%20in%20the%20numerical%20integration%20in%20this%20case%3B%20more%20accurate%20methods%20such%20as%20%5BRunge-Kutta%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FRunge%25E2%2580%2593Kutta_methods)%20should%20be%20employed.%20See%20such%20solution%20in%20%5Bhttps%3A%2F%2Fwww.myphysicslab.com%2Fpendulum%2Fdouble-pendulum-en.html%5D(https%3A%2F%2Fwww.myphysicslab.com%2Fpendulum%2Fdouble-pendulum-en.html).%0A%0A%20%20%20%20We%20can%20use%20Sympy%20to%20transform%20the%20symbolic%20equations%20into%20Numpy%20functions%20that%20can%20be%20used%20for%20the%20numerical%20solution.%20Here%20is%20the%20code%20for%20that%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(d1%2C%20d2%2C%20g_1%2C%20m1%2C%20m2%2C%20sol_1%2C%20sym%2C%20t_2%2C%20%CE%B81%2C%20%CE%B82)%3A%0A%20%20%20%20%CE%B81dd_fun%20%3D%20sym.lambdify((g_1%2C%20m1%2C%20d1%2C%20%CE%B81%2C%20%CE%B81.diff(t_2)%2C%20m2%2C%20d2%2C%20%CE%B82%2C%20%CE%B82.diff(t_2))%2C%20sol_1.args%5B0%5D%5B0%5D%2C%20'numpy')%0A%20%20%20%20%CE%B82dd_fun%20%3D%20sym.lambdify((g_1%2C%20m1%2C%20d1%2C%20%CE%B81%2C%20%CE%B81.diff(t_2)%2C%20m2%2C%20d2%2C%20%CE%B82%2C%20%CE%B82.diff(t_2))%2C%20sol_1.args%5B0%5D%5B1%5D%2C%20'numpy')%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20reader%20is%20invited%20to%20write%20the%20code%20for%20the%20numerical%20simulation.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Double%20compound%20pendulum%20under%20the%20influence%20of%20gravity%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fpendula_lagrange.png%3Fraw%3D1%22%20width%3D%22200%22%20alt%3D%22double%20pendulum%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2050px%2010px%2050px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20the%20double%20compound%20pendulum%20(or%20physical%20pendulum)%20shown%20on%20the%20the%20right%20with%20length%20%24d%24%20and%20mass%20%24m%24%20of%20each%20rod%20swinging%20in%20a%20plane%20forming%20the%20angles%20%24%5Ctheta_1%24%20and%20%24%5Ctheta_2%24%20with%20vertical%20and%20%24g%3D10%20m%2Fs%5E2%24.%3Cbr%3E%0A%20%20%20%20The%20system%20has%20two%20degrees%20of%20freedom%20and%20we%20need%20two%20generalized%20coordinates%20(%24%5Ctheta_1%2C%20%5Ctheta_2%24)%20to%20describe%20the%20system's%20configuration.%0A%0A%20%20%20%20Let's%20use%20the%20Lagrangian%20mechanics%20to%20derive%20the%20equations%20of%20motion%20for%20each%20pendulum.%0A%0A%20%20%20%20To%20calculate%20the%20potential%20and%20kinetic%20energy%20of%20the%20system%2C%20we%20will%20need%20to%20calculate%20the%20position%20and%20velocity%20of%20each%20pendulum.%20Now%20each%20pendulum%20is%20a%20rod%20with%20distributed%20mass%20and%20we%20will%20have%20to%20calculate%20the%20moment%20of%20rotational%20inertia%20of%20the%20rod.%20In%20this%20case%2C%20the%20kinetic%20energy%20of%20each%20pendulum%20will%20be%20given%20as%20the%20kinetic%20energy%20due%20to%20rotation%20of%20the%20pendulum%20plus%20the%20kinetic%20energy%20due%20to%20the%20speed%20of%20the%20center%20of%20mass%20of%20the%20pendulum%2C%20such%20that%20the%20total%20kinetic%20energy%20of%20the%20system%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20T%20%3D%20%5Coverbrace%7B%5Cunderbrace%7B%5C%2C%5Cfrac%7B1%7D%7B2%7DI_%7B1%2Ccm%7D%5Cdot%5Ctheta_1%5E2%5C%2C%7D_%7B%5Ctext%7Brotation%7D%7D%20%2B%20%5Cunderbrace%7B%5Cfrac%7B1%7D%7B2%7Dm(%5Cdot%20x_%7B1%2Ccm%7D%5E2%20%2B%20%5Cdot%20y_%7B1%2Ccm%7D%5E2)%7D_%7B%5Ctext%7Btranslation%7D%7D%7D%5E%7B%5Ctext%7Bpendulum%201%7D%7D%20%2B%20%5Coverbrace%7B%5Cunderbrace%7B%5C%2C%5Cfrac%7B1%7D%7B2%7DI_%7B2%2Ccm%7D%5Cdot%5Ctheta_2%5E2%5C%2C%7D_%7B%5Ctext%7Brotation%7D%7D%20%2B%20%5Cunderbrace%7B%5Cfrac%7B1%7D%7B2%7Dm(%5Cdot%20x_%7B2%2Ccm%7D%5E2%20%2B%20%5Cdot%20y_%7B2%2Ccm%7D%5E2)%7D_%7B%5Ctext%7Btranslation%7D%7D%7D%5E%7B%5Ctext%7Bpendulum%202%7D%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20And%20the%20potential%20energy%20of%20the%20system%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20V%20%3D%20mg%5Cbig(y_%7B1%2Ccm%7D%20%2B%20y_%7B2%2Ccm%7D%5Cbig)%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Let's%20use%20Sympy%20once%20again.%0A%0A%20%20%20%20The%20position%20and%20velocity%20of%20the%20center%20of%20mass%20of%20the%20rods%20%241%24%20and%20%242%24%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cos%2C%20dynamicsymbols%2C%20printeq%2C%20sin%2C%20symbols%2C%20t_2)%3A%0A%20%20%20%20(d_1%2C%20m_1%2C%20g_2)%20%3D%20symbols('d%2C%20m%2C%20g'%2C%20positive%3DTrue)%0A%20%20%20%20(%CE%B81_1%2C%20%CE%B82_1)%20%3D%20dynamicsymbols('theta1%2C%20theta2')%0A%20%20%20%20I%20%3D%20m_1%20*%20d_1%20*%20d_1%20%2F%2012%0A%20%20%20%20_x1%20%3D%20d_1%20*%20sin(%CE%B81_1)%20%2F%202%0A%20%20%20%20y1_1%20%3D%20-d_1%20*%20cos(%CE%B81_1)%20%2F%202%0A%20%20%20%20_x2%20%3D%20d_1%20*%20sin(%CE%B81_1)%20%2B%20d_1%20*%20sin(%CE%B82_1)%20%2F%202%0A%20%20%20%20y2_1%20%3D%20-d_1%20*%20cos(%CE%B81_1)%20-%20d_1%20*%20cos(%CE%B82_1)%20%2F%202%0A%20%20%20%20(x1d_1%2C%20y1d_1)%20%3D%20(_x1.diff(t_2)%2C%20y1_1.diff(t_2))%0A%20%20%20%20(x2d_1%2C%20y2d_1)%20%3D%20(_x2.diff(t_2)%2C%20y2_1.diff(t_2))%0A%20%20%20%20printeq('x_1'%2C%20_x1)%0A%20%20%20%20printeq('y_1'%2C%20y1_1)%0A%20%20%20%20printeq('x_2'%2C%20_x2)%0A%20%20%20%20printeq('y_2'%2C%20y2_1)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D_1'%2C%20x1d_1)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D_1'%2C%20y1d_1)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D_2'%2C%20x2d_1)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D_2'%2C%20y2d_1)%0A%20%20%20%20return%20I%2C%20g_2%2C%20m_1%2C%20x1d_1%2C%20x2d_1%2C%20y1_1%2C%20y1d_1%2C%20y2_1%2C%20y2d_1%2C%20%CE%B81_1%2C%20%CE%B82_1%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20kinetic%20and%20potential%20energies%20of%20the%20system%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20I%2C%0A%20%20%20%20g_2%2C%0A%20%20%20%20m_1%2C%0A%20%20%20%20printeq%2C%0A%20%20%20%20t_2%2C%0A%20%20%20%20x1d_1%2C%0A%20%20%20%20x2d_1%2C%0A%20%20%20%20y1_1%2C%0A%20%20%20%20y1d_1%2C%0A%20%20%20%20y2_1%2C%0A%20%20%20%20y2d_1%2C%0A%20%20%20%20%CE%B81_1%2C%0A%20%20%20%20%CE%B82_1%2C%0A)%3A%0A%20%20%20%20T_3%20%3D%20I%20%2F%202%20*%20%CE%B81_1.diff(t_2)%20**%202%20%2B%20m_1%20%2F%202%20*%20(x1d_1%20**%202%20%2B%20y1d_1%20**%202)%20%2B%20I%20%2F%202%20*%20%CE%B82_1.diff(t_2)%20**%202%20%2B%20m_1%20%2F%202%20*%20(x2d_1%20**%202%20%2B%20y2d_1%20**%202)%0A%20%20%20%20V_2%20%3D%20m_1%20*%20g_2%20*%20y1_1%20%2B%20m_1%20*%20g_2%20*%20y2_1%0A%20%20%20%20printeq('T'%2C%20T_3)%0A%20%20%20%20printeq('V'%2C%20V_2)%0A%20%20%20%20return%20T_3%2C%20V_2%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20Lagrangian%20function%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(T_3%2C%20V_2%2C%20printeq)%3A%0A%20%20%20%20L_2%20%3D%20T_3%20-%20V_2%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L_2)%0A%20%20%20%20return%20(L_2%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(L_2%2C%20lagrange_terms%2C%20%CE%B81_1%2C%20%CE%B82_1)%3A%0A%20%20%20%20Lterms_2%20%3D%20lagrange_terms(L_2%2C%20%5B%CE%B81_1%2C%20%CE%B82_1%5D)%0A%20%20%20%20return%20(Lterms_2%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Finally%2C%20the%20EOM%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms_2%2C%20lagrange_eq)%3A%0A%20%20%20%20lagrange_eq(Lterms_2)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20rearranging%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms_2%2C%20lagrange_eq_solve%2C%20%CE%B81_1%2C%20%CE%B82_1)%3A%0A%20%20%20%20sol_2%20%3D%20lagrange_eq_solve(Lterms_2%2C%20q%3D%5B%CE%B81_1%2C%20%CE%B82_1%5D%2C%20Qnc%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Double%20compound%20pendulum%20in%20joint%20space%0A%0A%20%20%20%20Let's%20recalculate%20the%20former%20example%20but%20employing%20generalized%20coordinates%20in%20the%20joint%20space%3A%20%24%5Calpha_1%3D%5Ctheta_1%24%20and%20%24%5Calpha_2%3D%5Ctheta_2-%5Ctheta_1%24.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cos%2C%20dynamicsymbols%2C%20printeq%2C%20sin%2C%20symbols%2C%20t_2)%3A%0A%20%20%20%20(d_2%2C%20m_2%2C%20g_3)%20%3D%20symbols('d%2C%20m%2C%20g'%2C%20positive%3DTrue)%0A%20%20%20%20(%CE%B11%2C%20%CE%B12)%20%3D%20dynamicsymbols('alpha1%2C%20alpha2')%0A%20%20%20%20I_1%20%3D%20m_2%20*%20d_2%20*%20d_2%20%2F%2012%0A%20%20%20%20_x1%20%3D%20d_2%20*%20sin(%CE%B11)%20%2F%202%0A%20%20%20%20y1_2%20%3D%20-d_2%20*%20cos(%CE%B11)%20%2F%202%0A%20%20%20%20_x2%20%3D%20d_2%20*%20sin(%CE%B11)%20%2B%20d_2%20*%20sin(%CE%B11%20%2B%20%CE%B12)%20%2F%202%0A%20%20%20%20y2_2%20%3D%20-d_2%20*%20cos(%CE%B11)%20-%20d_2%20*%20cos(%CE%B11%20%2B%20%CE%B12)%20%2F%202%0A%20%20%20%20(x1d_2%2C%20y1d_2)%20%3D%20(_x1.diff(t_2)%2C%20y1_2.diff(t_2))%0A%20%20%20%20(x2d_2%2C%20y2d_2)%20%3D%20(_x2.diff(t_2)%2C%20y2_2.diff(t_2))%0A%20%20%20%20printeq('x_1'%2C%20_x1)%0A%20%20%20%20printeq('y_1'%2C%20y1_2)%0A%20%20%20%20printeq('x_2'%2C%20_x2)%0A%20%20%20%20printeq('y_2'%2C%20y2_2)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D_1'%2C%20x1d_2)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D_1'%2C%20y1d_2)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D_2'%2C%20x2d_2)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D_2'%2C%20y2d_2)%0A%20%20%20%20return%20I_1%2C%20g_3%2C%20m_2%2C%20x1d_2%2C%20x2d_2%2C%20y1_2%2C%20y1d_2%2C%20y2_2%2C%20y2d_2%2C%20%CE%B11%2C%20%CE%B12%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20I_1%2C%0A%20%20%20%20g_3%2C%0A%20%20%20%20m_2%2C%0A%20%20%20%20printeq%2C%0A%20%20%20%20t_2%2C%0A%20%20%20%20x1d_2%2C%0A%20%20%20%20x2d_2%2C%0A%20%20%20%20y1_2%2C%0A%20%20%20%20y1d_2%2C%0A%20%20%20%20y2_2%2C%0A%20%20%20%20y2d_2%2C%0A%20%20%20%20%CE%B11%2C%0A%20%20%20%20%CE%B12%2C%0A)%3A%0A%20%20%20%20T_4%20%3D%20I_1%20%2F%202%20*%20%CE%B11.diff(t_2)%20**%202%20%2B%20m_2%20%2F%202%20*%20(x1d_2%20**%202%20%2B%20y1d_2%20**%202)%20%2B%20I_1%20%2F%202%20*%20(%CE%B11.diff(t_2)%20%2B%20%CE%B12.diff(t_2))%20**%202%20%2B%20m_2%20%2F%202%20*%20(x2d_2%20**%202%20%2B%20y2d_2%20**%202)%0A%20%20%20%20V_3%20%3D%20m_2%20*%20g_3%20*%20y1_2%20%2B%20m_2%20*%20g_3%20*%20y2_2%0A%20%20%20%20L_3%20%3D%20T_4%20-%20V_3%0A%20%20%20%20printeq('T'%2C%20T_4)%0A%20%20%20%20printeq('V'%2C%20V_3)%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L_3)%0A%20%20%20%20return%20(L_3%2C)%0A%0A%0A%40app.cell%0Adef%20_(L_3%2C%20lagrange_terms%2C%20%CE%B11%2C%20%CE%B12)%3A%0A%20%20%20%20Lterms_3%20%3D%20lagrange_terms(L_3%2C%20%5B%CE%B11%2C%20%CE%B12%5D)%0A%20%20%20%20return%20(Lterms_3%2C)%0A%0A%0A%40app.cell%0Adef%20_(Lterms_3%2C%20lagrange_eq)%3A%0A%20%20%20%20lagrange_eq(Lterms_3)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms_3%2C%20lagrange_eq_solve%2C%20%CE%B11%2C%20%CE%B12)%3A%0A%20%20%20%20sol_3%20%3D%20lagrange_eq_solve(Lterms_3%2C%20q%3D%5B%CE%B11%2C%20%CE%B12%5D%2C%20Qnc%3DNone)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Forces%20on%20the%20pendulum**%0A%0A%20%20%20%20We%20can%20see%20that%20besides%20the%20terms%20proportional%20to%20gravity%20%24g%24%2C%20there%20are%20three%20types%20of%20forces%20in%20the%20equations%2C%20two%20of%20these%20forces%20we%20already%20saw%20in%20the%20solution%20of%20the%20double%20pendulum%20employing%20generalized%20coordinates%20in%20the%20segment%20space%3A%20forces%20proportional%20to%20angular%20velocity%20squared%20%24%5Cdot%7B%5Ctheta%7D_i%5E2%24%20(now%20proportional%20to%20%24%5Cdot%7B%5Calpha%7D_i%5E2%24)%20and%20forces%20proportional%20to%20the%20angular%20acceleration%20%24%5Cddot%7B%5Ctheta%7D_i%24%20(now%20proportional%20to%20%24%5Cddot%7B%5Calpha%7D_i%24).%20These%20are%20the%20centripetal%20forces%20and%20tangential%20forces.%3Cbr%3E%0A%20%20%20%20A%20new%20type%20of%20force%20appeared%20explicitly%20in%20the%20equations%20when%20we%20employed%20generalized%20coordinates%20in%20the%20joint%20space%3A%20forces%20proportional%20to%20the%20product%20of%20the%20two%20angular%20velocities%20in%20joint%20space%20%24%5Cdot%7B%5Calpha%7D_1%5Cdot%7B%5Calpha%7D_2%24.%20These%20are%20the%20force%20of%20Coriolis.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Mass%20attached%20to%20a%20spring%20on%20a%20horizontal%20plane%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fruina_prob13_1_7.png%3Fraw%3D1%22%20width%3D%22300%22%20alt%3D%22mass-spring%20on%20a%20table%22%20style%3D%22float%3Aright%3Bmargin%3A%200px%200px%200px%205px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Let's%20solve%20the%20exercise%2013.1.7%20of%20Ruina%20and%20Pratap%20(2019)%3A%3Cbr%3E%0A%20%20%20%20%22Two%20ice%20skaters%20whirl%20around%20one%20another.%20They%20are%20connected%20by%20a%20linear%20elastic%20cord%20whose%20center%20is%20stationary%20in%20space.%20We%20wish%20to%20consider%20the%20motion%20of%20one%20of%20the%20skaters%20by%20modeling%20her%20as%20a%20mass%20m%20held%20by%20a%20cord%20that%20exerts%20k%20Newtons%20for%20each%20meter%20it%20is%20extended%20from%20the%20central%20position.%3Cbr%3E%0A%20%20%20%20a)%20Draw%20a%20free-body%20diagram%20showing%20the%20forces%20that%20act%20on%20the%20mass%20is%20at%20an%20arbitrary%20position.%3Cbr%3E%0A%20%20%20%20b)%20Write%20the%20differential%20equations%20that%20describe%20the%20motion.%22%0A%0A%20%20%20%20Let's%20solve%20item%20b%20using%20Lagrangian%20mechanics.%0A%0A%20%20%20%20To%20calculate%20the%20potential%20and%20kinetic%20energy%20of%20the%20system%2C%20we%20will%20need%20to%20calculate%20the%20position%20and%20velocity%20of%20the%20mass.%20It's%20convenient%20to%20use%20as%20generalized%20coordinates%2C%20the%20radial%20position%20%24r%24%20and%20the%20angle%20%24%5Ctheta%24.%0A%0A%20%20%20%20Using%20Sympy%2C%20declaring%20our%20parameters%20and%20coordinates%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Symbol%2C%20dynamicsymbols%2C%20symbols)%3A%0A%20%20%20%20t_3%20%3D%20Symbol('t')%0A%20%20%20%20(m_3%2C%20k)%20%3D%20symbols('m%2C%20k'%2C%20positive%3DTrue)%0A%20%20%20%20(r%2C%20%CE%B8_1)%20%3D%20dynamicsymbols('r%2C%20theta')%0A%20%20%20%20return%20k%2C%20m_3%2C%20r%2C%20t_3%2C%20%CE%B8_1%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20position%20and%20velocity%20of%20the%20skater%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cos%2C%20printeq%2C%20r%2C%20sin%2C%20t_3%2C%20%CE%B8_1)%3A%0A%20%20%20%20(x_1%2C%20y_1)%20%3D%20(r%20*%20cos(%CE%B8_1)%2C%20r%20*%20sin(%CE%B8_1))%0A%20%20%20%20(xd_1%2C%20yd_1)%20%3D%20(x_1.diff(t_3)%2C%20y_1.diff(t_3))%0A%20%20%20%20printeq('x'%2C%20x_1)%0A%20%20%20%20printeq('y'%2C%20y_1)%0A%20%20%20%20printeq('%5C%5Cdot%7Bx%7D'%2C%20xd_1)%0A%20%20%20%20printeq('%5C%5Cdot%7By%7D'%2C%20yd_1)%0A%20%20%20%20return%20xd_1%2C%20yd_1%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20So%2C%20the%20kinetic%20and%20potential%20energies%20of%20the%20skater%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Math%2C%20display%2C%20k%2C%20m_3%2C%20mlatex%2C%20printeq%2C%20r%2C%20xd_1%2C%20yd_1)%3A%0A%20%20%20%20T_5%20%3D%20m_3%20*%20(xd_1%20**%202%20%2B%20yd_1%20**%202)%20%2F%202%0A%20%20%20%20V_4%20%3D%20k%20*%20r%20**%202%20%2F%202%0A%20%20%20%20display(Math('T%3D'%20%2B%20mlatex(T_5)))%0A%20%20%20%20display(Math('V%3D'%20%2B%20mlatex(V_4)))%0A%20%20%20%20printeq('T'%2C%20T_5)%0A%20%20%20%20printeq('V'%2C%20V_4)%0A%20%20%20%20return%20T_5%2C%20V_4%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Where%20we%20considered%20the%20equilibrium%20length%20of%20the%20spring%20as%20zero.%0A%0A%20%20%20%20The%20Lagrangian%20function%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(T_5%2C%20V_4%2C%20printeq)%3A%0A%20%20%20%20L_4%20%3D%20T_5%20-%20V_4%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L_4)%0A%20%20%20%20return%20(L_4%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(L_4%2C%20lagrange_terms%2C%20r%2C%20%CE%B8_1)%3A%0A%20%20%20%20Lterms_4%20%3D%20lagrange_terms(L_4%2C%20%5Br%2C%20%CE%B8_1%5D)%0A%20%20%20%20return%20(Lterms_4%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Finally%2C%20the%20EOM%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Lterms_4%2C%20lagrange_eq)%3A%0A%20%20%20%20lagrange_eq(Lterms_4)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20In%20Ruina%20and%20Pratap's%20book%20they%20give%20as%20solution%20the%20equation%3A%242r%5Cdot%7Br%7D%5Cdot%7B%5Ctheta%7D%20%2B%20r%5E3%5Cddot%7B%5Ctheta%7D%3D0%24%2C%20but%20%20using%20dimensional%20analysis%20we%20can%20check%20the%20book's%20solution%20is%20not%20correct.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%203%20%E2%80%94%20Recognize%20a%20coupled%20kinetic%20energy.**%20Two%20point%20masses%20in%20a%20double%20pendulum%20have%20absolute%20angles%20%24%5Ctheta_1%2C%5Ctheta_2%24.%20Why%20does%20kinetic%20energy%20contain%20a%20term%20proportional%20to%20%24%5Cdot%5Ctheta_1%5Cdot%5Ctheta_2%5Ccos(%5Ctheta_1-%5Ctheta_2)%24%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%203%0A%0A%20%20%20%20The%20second%20mass%20velocity%20is%20the%20sum%20of%20velocities%20from%20both%20links.%20Squaring%20that%20sum%20introduces%20twice%20their%20dot%20product.%20Their%20tangent%20directions%20have%20dot%20product%20%24%5Ccos(%5Ctheta_1-%5Ctheta_2)%24%2C%20producing%20the%20cross%20term%20and%20an%20off-diagonal%20mass-matrix%20entry.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Generalized%20forces%0A%0A%20%20%20%20How%20non-conservative%20forces%20are%20treated%20in%20the%20Lagrangian%20Mechanics%20is%20different%20than%20in%20Newtonian%20mechanics.%3Cbr%3E%0A%20%20%20%20Newtonian%20mechanics%20consider%20the%20forces%20(and%20moment%20of%20forces)%20acting%20on%20each%20body%20(via%20FBD)%20and%20write%20down%20the%20equations%20of%20motion%20for%20each%20body%2Fcoordinate.%3Cbr%3E%0A%20%20%20%20In%20Lagrangian%20Mechanics%2C%20we%20consider%20the%20forces%20(and%20moment%20of%20forces)%20acting%20on%20each%20generalized%20coordinate.%20For%20such%2C%20the%20effects%20of%20the%20non-conservative%20forces%20have%20to%20be%20calculated%20in%20the%20direction%20of%20each%20generalized%20coordinate%2C%20these%20will%20be%20the%20generalized%20forces.%0A%0A%20%20%20%20A%20robust%20approach%20to%20determine%20the%20generalized%20forces%20on%20each%20generalized%20coordinate%20is%20to%20compute%20the%20work%20done%20by%20the%20forces%20to%20produce%20a%20small%20variation%20of%20the%20system%20on%20the%20direction%20of%20the%20generalized%20coordinate.%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fpendulumforce.png%3Fraw%3D1%22%20width%3D%22260%22%20alt%3D%22pendulum%22%20style%3D%22float%3Aright%3Bmargin%3A%205px%2010px%205px%205px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20For%20example%2C%20consider%20a%20pendulum%20with%20a%20massless%20rod%20of%20length%20%24d%24%20and%20a%20mass%20%24m%24%20at%20the%20extremity%20swinging%20in%20a%20plane%20forming%20the%20angle%20%24%5Ctheta%24%20with%20the%20vertical.%3Cbr%3E%0A%20%20%20%20An%20external%20force%20acts%20on%20the%20tip%20of%20the%20pendulum%20at%20the%20horizontal%20direction.%3Cbr%3E%0A%20%20%20%20The%20pendulum%20cord%20is%20inextensible%20and%20the%20tip%20of%20the%20pendulum%20can%20only%20move%20along%20the%20arc%20of%20a%20circumference%20with%20radius%20%24d%24.%0A%0A%20%20%20%20The%20work%20done%20by%20this%20force%20to%20produce%20a%20small%20variation%20%24%5Cdelta%20%5Ctheta%24%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20%5Cdelta%20W_%7BNC%7D%20%3D%20%5Cvec%7BF%7D%20%5Ccdot%20%5Cdelta%20%5Cvec%7Br%7D%20%5C%5C%0A%20%20%20%20%5Cdelta%20W_%7BNC%7D%20%3D%20F%20d%20%5Ccos(%5Ctheta)%20%5Cdelta%20%5Ctheta%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20We%20now%20reexpress%20the%20work%20as%20the%20product%20of%20the%20corresponding%20generalized%20force%20%24Q_%7BNC%7D%24%20and%20the%20generalized%20coordinate%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cdelta%20W_%7BNC%7D%20%3D%20Q_%7BNC%7D%20%5Cdelta%20%5Ctheta%0A%20%20%20%20%24%24%0A%0A%20%20%20%20And%20comparing%20the%20last%20two%20equations%2C%20the%20generalized%20force%20(in%20fact%2C%20a%20moment%20of%20force)%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20Q_%7BNC%7D%20%3D%20F%20d%20%5Ccos(%5Ctheta)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Note%20that%20the%20work%20done%20by%20definition%20was%20expressed%20in%20Cartesian%20coordinates%20as%20the%20scalar%20product%20between%20vectors%20%24%5Cvec%20F%24%20and%20%24%5Cdelta%20%5Cvec%7Br%7D%24%20and%20after%20the%20scalar%20product%20was%20evaluated%20we%20end%20up%20with%20the%20work%20done%20expressed%20in%20terms%20of%20the%20generalized%20coordinate.%20This%20is%20somewhat%20similar%20to%20the%20calculation%20of%20kinetic%20and%20potential%20energy%2C%20these%20quantities%20are%20typically%20expressed%20first%20in%20terms%20of%20Cartesian%20coordinates%2C%20which%20in%20turn%20are%20expressed%20in%20terms%20of%20the%20generalized%20coordinates%2C%20so%20we%20end%20up%20with%20only%20generalized%20coordinates.%3Cbr%3E%0A%20%20%20%20Also%20note%2C%20we%20employ%20the%20term%20generalized%20force%20to%20refer%20to%20a%20non-conservative%20force%20or%20moment%20of%20force%20expressed%20in%20the%20generalized%20coordinate.%0A%0A%20%20%20%20If%20the%20force%20had%20components%20on%20both%20directions%2C%20we%20would%20calculate%20the%20work%20computing%20the%20scalar%20product%20between%20the%20variation%20in%20displacement%20and%20the%20force%2C%20as%20usual.%20For%20example%2C%20consider%20a%20force%20%24%5Cvec%7BF%7D%3D2%5Chat%7Bi%7D%2B7%5Chat%7Bj%7D%24%2C%20the%20work%20done%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20%5Cdelta%20W_%7BNC%7D%20%3D%20%5Cvec%7BF%7D%20%5Ccdot%20%5Cdelta%20%5Cvec%7Br%7D%20%5C%5C%0A%20%20%20%20%5Cdelta%20W_%7BNC%7D%20%3D%20%5B2%5Chat%7Bi%7D%2B7%5Chat%7Bj%7D%5D%20%5Ccdot%20%5Bd%5Ccos(%5Ctheta)%20%5Cdelta%20%5Ctheta%20%5Chat%7Bi%7D%20%2B%20d%5Csin(%5Ctheta)%20%5Cdelta%20%5Ctheta%20%5Chat%7Bj%7D%5D%20%5C%5C%0A%20%20%20%20%5Cdelta%20W_%7BNC%7D%20%3D%20d%5B2%5Ccos(%5Ctheta)%20%2B%207%5Csin(%5Ctheta)%5D%20%5Cdelta%20%5Ctheta%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Finally%2C%20the%20generalized%20force%20(a%20moment%20of%20force)%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20Q_%7BNC%7D%20%3D%20d%5B2%5Ccos(%5Ctheta)%20%2B%207%5Csin(%5Ctheta)%5D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20a%20system%20with%20%24N%24%20generalized%20coordinates%20and%20%24n%24%20non-conservative%20forces%2C%20to%20determine%20the%20generalized%20force%20at%20each%20generalized%20coordinate%2C%20we%20would%20compute%20the%20work%20as%20the%20sum%20of%20the%20works%20done%20by%20each%20force%20at%20each%20small%20variation%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cdelta%20W_%7BNC%7D%20%3D%20%5Csum%5Climits_%7Bj%3D1%7D%5En%20F_%7Bj%7D%20%5Ccdot%20%5Cdelta%20x_j(%5Cdelta%20q_1%2C%20%5Cdotsc%2C%20%5Cdelta%20q_N%20)%20%3D%20%5Csum%5Climits_%7Bi%3D1%7D%5EN%20%20Q_%7Bi%7D%20%5Cdelta%20q_i%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20simpler%20problems%2C%20in%20which%20we%20can%20separately%20analyze%20each%20non-conservative%20force%20acting%20on%20each%20generalized%20coordinate%2C%20the%20work%20done%20by%20each%20force%20on%20a%20given%20generalized%20coordinate%20can%20be%20calculated%20by%20making%20all%20other%20coordinates%20immovable%20('frozen')%20and%20then%20sum%20the%20generalized%20forces.%0A%0A%20%20%20%20The%20next%20examples%20will%20help%20to%20understand%20how%20to%20calculate%20the%20generalized%20force.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Simple%20pendulum%20on%20moving%20cart%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fmasspend_lagrange.png%3Fraw%3D1%22%20width%3D%22250%22%20alt%3D%22cart%20pendulum%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2050px%2010px%2050px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20a%20simple%20pendulum%20with%20massless%20rod%20of%20length%20%24d%24%20and%20mass%20%24m%24%20at%20the%20extremity%20of%20the%20rod%20forming%20an%20angle%20%24%5Ctheta%24%20with%20the%20vertical%20direction%20under%20the%20action%20of%20gravity.%20The%20pendulum%20swings%20freely%20from%20a%20cart%20with%20mass%20%24M%24%20that%20moves%20at%20the%20horizontal%20direction%20pushed%20by%20a%20force%20%24F_x%24.%0A%0A%20%20%20%20Let's%20use%20the%20Lagrangian%20mechanics%20to%20derive%20the%20EOM%20for%20the%20system.%0A%0A%20%20%20%20We%20will%20model%20the%20cart%20as%20a%20particle%20moving%20along%20the%20axis%20%24x%24%2C%20i.e.%2C%20%24y%3D0%24.%20The%20system%20has%20two%20degrees%20of%20freedom%20and%20because%20of%20the%20constraints%20introduced%20by%20the%20constant%20length%20of%20the%20rod%20and%20the%20motion%20the%20cart%20can%20perform%2C%20good%20generalized%20coordinates%20to%20describe%20the%20configuration%20of%20the%20system%20are%20%24x%24%20and%20%24%5Ctheta%24.%0A%0A%20%20%20%20**Determination%20of%20the%20generalized%20force**%3Cbr%3E%0A%20%20%20%20The%20force%20%24F%24%20acts%20along%20the%20same%20direction%20of%20the%20generalized%20coordinate%20%24x%24%2C%20this%20means%20%24F%24%20contributes%20entirely%20to%20the%20work%20done%20at%20the%20direction%20%24x%24.%20At%20this%20generalized%20coordinate%2C%20the%20generalized%20force%20due%20to%20%24F%24%20is%20%24F%24.%3Cbr%3E%0A%20%20%20%20At%20the%20generalized%20coordinate%20%24%CE%B8%24%2C%20if%20we%20'freeze'%20the%20generalized%20coordinate%20%24x%24%20and%20let%20%24F%24%20act%20on%20the%20system%2C%20there%20is%20no%20movement%20at%20the%20generalized%20coordinate%20%24%CE%B8%24%2C%20so%20no%20work%20is%20done.%20At%20this%20generalized%20coordinate%2C%20the%20generalized%20force%20due%20to%20%24F%24%20is%20%240%24.%0A%0A%20%20%20%20Let's%20now%20use%20Sympy%20to%20determine%20the%20EOM.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20positions%20of%20the%20cart%20(c)%20and%20of%20the%20pendulum%20tip%20(p)%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Symbol%2C%20dynamicsymbols%2C%20symbols)%3A%0A%20%20%20%20t_4%20%3D%20Symbol('t')%0A%20%20%20%20(M%2C%20m_4%2C%20d_3)%20%3D%20symbols('M%2C%20m%2C%20d'%2C%20positive%3DTrue)%0A%20%20%20%20(x_2%2C%20y_2%2C%20%CE%B8_2%2C%20Fx)%20%3D%20dynamicsymbols('x%2C%20y%2C%20theta%2C%20F_x')%0A%20%20%20%20return%20Fx%2C%20M%2C%20d_3%2C%20m_4%2C%20t_4%2C%20x_2%2C%20y_2%2C%20%CE%B8_2%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20positions%20of%20the%20cart%20(c)%20and%20of%20the%20pendulum%20tip%20(p)%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cos%2C%20d_3%2C%20printeq%2C%20sin%2C%20t_4%2C%20x_2%2C%20y_2%2C%20%CE%B8_2)%3A%0A%20%20%20%20(xc%2C%20yc)%20%3D%20(x_2%2C%20y_2%20*%200)%0A%20%20%20%20(xcd%2C%20ycd)%20%3D%20(xc.diff(t_4)%2C%20yc.diff(t_4))%0A%20%20%20%20(xp%2C%20yp)%20%3D%20(x_2%20%2B%20d_3%20*%20sin(%CE%B8_2)%2C%20-d_3%20*%20cos(%CE%B8_2))%0A%20%20%20%20(xpd%2C%20ypd)%20%3D%20(xp.diff(t_4)%2C%20yp.diff(t_4))%0A%20%20%20%20printeq('x_c'%2C%20xc)%0A%20%20%20%20printeq('y_c'%2C%20yc)%0A%20%20%20%20printeq('x_p'%2C%20xp)%0A%20%20%20%20printeq('y_p'%2C%20yp)%0A%20%20%20%20return%20xcd%2C%20xpd%2C%20yc%2C%20ycd%2C%20yp%2C%20ypd%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20velocities%20of%20the%20cart%20and%20of%20the%20pendulum%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(printeq%2C%20xcd%2C%20xpd%2C%20ycd%2C%20ypd)%3A%0A%20%20%20%20printeq(r'%5Cdot%7Bx%7D_c'%2C%20xcd)%0A%20%20%20%20printeq(r'%5Cdot%7By%7D_c'%2C%20ycd)%0A%0A%20%20%20%20printeq(r'%5Cdot%7Bx%7D_p'%2C%20xpd)%0A%20%20%20%20printeq(r'%5Cdot%7By%7D_p'%2C%20ypd)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20total%20kinetic%20and%20total%20potential%20energies%20and%20the%20Lagrangian%20of%20the%20system%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(M%2C%20g_3%2C%20m_4%2C%20printeq%2C%20xcd%2C%20xpd%2C%20yc%2C%20ycd%2C%20yp%2C%20ypd)%3A%0A%20%20%20%20T_6%20%3D%20M%20*%20(xcd%20**%202%20%2B%20ycd%20**%202)%20%2F%202%20%2B%20m_4%20*%20(xpd%20**%202%20%2B%20ypd%20**%202)%20%2F%202%0A%20%20%20%20V_5%20%3D%20M%20*%20g_3%20*%20yc%20%2B%20m_4%20*%20g_3%20*%20yp%0A%20%20%20%20printeq('T'%2C%20T_6)%0A%20%20%20%20printeq('V'%2C%20V_5)%0A%20%20%20%20L_5%20%3D%20T_6%20-%20V_5%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L_5)%0A%20%20%20%20return%20(L_5%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(L_5%2C%20lagrange_terms%2C%20x_2%2C%20%CE%B8_2)%3A%0A%20%20%20%20Lterms_5%20%3D%20lagrange_terms(L_5%2C%20%5Bx_2%2C%20%CE%B8_2%5D)%0A%20%20%20%20return%20(Lterms_5%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Finally%2C%20the%20EOM%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Fx%2C%20Lterms_5%2C%20lagrange_eq)%3A%0A%20%20%20%20lagrange_eq(Lterms_5%2C%20%5BFx%2C%200%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Fx%2C%20Lterms_5%2C%20lagrange_eq_solve%2C%20x_2%2C%20%CE%B8_2)%3A%0A%20%20%20%20sol_4%20%3D%20lagrange_eq_solve(Lterms_5%2C%20q%3D%5Bx_2%2C%20%CE%B8_2%5D%2C%20Qnc%3D%5BFx%2C%200%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Note%20that%20although%20the%20force%20%24F_x%24%20acts%20solely%20on%20the%20cart%2C%20the%20acceleration%20of%20the%20pendulum%20%24%5Cddot%7B%5Ctheta%7D%24%20is%20also%20dependent%20on%20%24F%24%2C%20as%20expected.%0A%0A%20%20%20%20%5BClik%20here%20for%20solutions%20to%20this%20problem%20using%20the%20Newtonian%20and%20Lagrangian%20approaches%20and%20how%20this%20system%20of%20two%20coupled%20second%20order%20differential%20equations%20can%20be%20rearranged%20for%20its%20numerical%20solution%5D(http%3A%2F%2Fwww.emomi.com%2Fdownload%2Fneumann%2Fpendulum_cart.html).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Two%20masses%20and%20two%20springs%20under%20the%20influence%20of%20gravity%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fsprings_masses_g.png%3Fraw%3D1%22%20width%3D%22200%22%20alt%3D%22double%20pendulum%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2050px%2010px%2050px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20a%20system%20composed%20by%20two%20masses%20%24m_1%2C%5C%2C%20m_2%24%20and%20two%20ideal%20springs%20(massless%2C%20lengths%20%24%5Cell_1%2C%5C%2C%20%5Cell_2%24%2C%20and%20spring%20constants%20%24k_1%2C%5C%2Ck_2%24)%20attached%20in%20series%20under%20gravity%20and%20a%20force%20%24F%24%20acting%20directly%20on%20%24m_2%24.%0A%0A%20%20%20%20We%20can%20model%20this%20system%20as%20composed%20by%20two%20particles%20with%20two%20degrees%20of%20freedom%20and%20we%20need%20two%20generalized%20coordinates%20to%20describe%20the%20system's%20configuration%3B%20two%20obvious%20options%20are%3A%0A%0A%20%20%20%20-%20%24%7By_1%2C%20y_2%7D%24%2C%20positions%20of%20masses%20%24m_1%2C%5C%2C%20m_2%24%20w.r.t.%20ceiling%20(origin).%3Cbr%3E%0A%20%20%20%20-%20%24%7Bz_1%2C%20z_2%7D%24%2C%20position%20of%20mass%20%24m_1%24%20w.r.t.%20ceiling%20and%20position%20of%20mass%20%24m_2%24%20w.r.t.%20mass%20%24m_1%24.%0A%0A%20%20%20%20The%20set%20%24%7By_1%2C%20y_2%7D%24%20is%20at%20an%20inertial%20reference%20frame%2C%20while%20the%20second%20set%20it's%20not.%3Cbr%3E%0A%20%20%20%20Let's%20find%20the%20EOM's%20using%20both%20sets%20of%20generalized%20coordinates%20and%20compare%20them.%0A%0A%20%20%20%20**Generalized%20forces**%3Cbr%3E%0A%20%20%20%20Using%20%24%7By_1%2C%20y_2%7D%24%2C%20force%20%24F%24%20acts%20on%20mass%20%24m_2%24%20at%20the%20same%20direction%20of%20the%20generalized%20coordinate%20%24y_2%24.%20At%20this%20coordinate%2C%20the%20generalized%20force%20of%20%24F%24%20is%20%24F%24.%20At%20the%20generalized%20coordinate%20%24y_1%24%2C%20if%20we%20'freeze'%20the%20generalized%20coordinate%20%24y_2%24%20and%20let%20%24F%24%20act%20on%20the%20system%2C%20there%20is%20no%20movement%20at%20the%20generalized%20coordinate%20%24y_1%24%20and%20no%20work%20is%20done.%20At%20this%20generalized%20coordinate%2C%20the%20generalized%20force%20due%20to%20%24F%24%20is%20%240%24.%0A%0A%20%20%20%20Using%20%24%7Bz_1%2C%20z_2%7D%24%2C%20force%20%24F%24%20acts%20on%20mass%20%24m_2%24%20at%20the%20same%20direction%20of%20the%20generalized%20coordinate%20%24z_2%24.%20At%20this%20coordinate%2C%20the%20generalized%20force%20of%20%24F%24%20is%20%24F%24.%20At%20the%20generalized%20coordinate%20%24z_1%24%2C%20if%20we%20'freeze'%20the%20generalized%20coordinate%20%24z_2%24%20and%20let%20%24F%24%20act%20on%20the%20system%2C%20mass%20%24m_1%24%20suffers%20the%20action%20of%20force%20%24F%24%20at%20the%20generalized%20coordinate%20%24y_1%24.%20At%20this%20generalized%20coordinate%2C%20the%20generalized%20force%20due%20to%20%24F%24%20is%20%24F%24.%0A%0A%20%20%20%20Sympy%20is%20our%20friend%20once%20again%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Symbol%2C%20dynamicsymbols%2C%20symbols)%3A%0A%20%20%20%20t_5%20%3D%20Symbol('t')%0A%20%20%20%20(m1_1%2C%20m2_1%2C%20l01%2C%20l02%2C%20g_4%2C%20k1%2C%20k2)%20%3D%20symbols('m1%2C%20m2%2C%20ell01%2C%20ell02%2C%20g%2C%20k1%2C%20k2'%2C%20positive%3DTrue)%0A%20%20%20%20(y1_3%2C%20y2_3%2C%20F)%20%3D%20dynamicsymbols('y1%2C%20y2%2C%20F')%0A%20%20%20%20return%20F%2C%20g_4%2C%20k1%2C%20k2%2C%20l01%2C%20l02%2C%20m1_1%2C%20m2_1%2C%20t_5%2C%20y1_3%2C%20y2_3%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20total%20kinetic%20and%20total%20potential%20energies%20of%20the%20system%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(g_4%2C%20k1%2C%20k2%2C%20l01%2C%20l02%2C%20m1_1%2C%20m2_1%2C%20printeq%2C%20t_5%2C%20y1_3%2C%20y2_3)%3A%0A%20%20%20%20(y1d_3%2C%20y2d_3)%20%3D%20(y1_3.diff(t_5)%2C%20y2_3.diff(t_5))%0A%20%20%20%20T_7%20%3D%20m1_1%20*%20y1d_3%20**%202%20%2F%202%20%2B%20m2_1%20*%20y2d_3%20**%202%20%2F%202%0A%20%20%20%20V_6%20%3D%20k1%20*%20(y1_3%20-%20l01)%20**%202%20%2F%202%20%2B%20k2%20*%20(y2_3%20-%20y1_3%20-%20l02)%20**%202%20%2F%202%20-%20m1_1%20*%20g_4%20*%20y1_3%20-%20m2_1%20*%20g_4%20*%20y2_3%0A%20%20%20%20printeq('T'%2C%20T_7)%0A%20%20%20%20printeq('V'%2C%20V_6)%0A%20%20%20%20return%20T_7%2C%20V_6%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20For%20sake%20of%20clarity%2C%20let's%20consider%20the%20resting%20lengths%20of%20the%20springs%20to%20be%20zero%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(V_6%2C%20l01%2C%20l02%2C%20printeq)%3A%0A%20%20%20%20V_7%20%3D%20V_6.subs(%5B(l01%2C%200)%2C%20(l02%2C%200)%5D)%0A%20%20%20%20printeq('V'%2C%20V_7)%0A%20%20%20%20return%20(V_7%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20Lagrangian%20function%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(T_7%2C%20V_7%2C%20printeq)%3A%0A%20%20%20%20L_6%20%3D%20T_7%20-%20V_7%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L_6)%0A%20%20%20%20return%20(L_6%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20And%20the%20derivatives%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(L_6%2C%20lagrange_terms%2C%20y1_3%2C%20y2_3)%3A%0A%20%20%20%20Lterms_6%20%3D%20lagrange_terms(L_6%2C%20%5By1_3%2C%20y2_3%5D)%0A%20%20%20%20return%20(Lterms_6%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Finally%2C%20the%20EOM%20are%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(F%2C%20Lterms_6%2C%20lagrange_eq)%3A%0A%20%20%20%20lagrange_eq(Lterms_6%2C%20%5B0%2C%20F%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(F%2C%20Lterms_6%2C%20lagrange_eq_solve%2C%20y1_3%2C%20y2_3)%3A%0A%20%20%20%20lagrange_eq_solve(Lterms_6%2C%20%5By1_3%2C%20y2_3%5D%2C%20%5B0%2C%20F%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Same%20problem%2C%20but%20with%20the%20other%20set%20of%20coordinates**%0A%0A%20%20%20%20Using%20%24%7Bz_1%2C%20z_2%7D%24%20as%20the%20position%20of%20mass%20%24m_1%24%20w.r.t.%20the%20ceiling%20and%20the%20position%20of%20mass%20%24m_2%24%20w.r.t.%20the%20mass%20%24m_1%24%2C%20the%20solution%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(dynamicsymbols%2C%20g_4%2C%20k1%2C%20k2%2C%20l01%2C%20l02%2C%20m1_1%2C%20m2_1%2C%20printeq%2C%20t_5)%3A%0A%20%20%20%20(z1%2C%20z2)%20%3D%20dynamicsymbols('z1%2C%20z2')%0A%20%20%20%20(z1d%2C%20z2d)%20%3D%20(z1.diff(t_5)%2C%20z2.diff(t_5))%0A%20%20%20%20T_8%20%3D%20m1_1%20*%20z1d%20**%202%20%2F%202%20%2B%20m2_1%20*%20(z1d%20%2B%20z2d)%20**%202%20%2F%202%0A%20%20%20%20V_8%20%3D%20k1%20*%20(z1%20-%20l01)%20**%202%20%2F%202%20%2B%20k2%20*%20(z2%20-%20l02)%20**%202%20%2F%202%20-%20m1_1%20*%20g_4%20*%20z1%20-%20m2_1%20*%20g_4%20*%20(z1%20%2B%20z2)%0A%20%20%20%20printeq('T'%2C%20T_8)%0A%20%20%20%20printeq('V'%2C%20V_8)%0A%20%20%20%20return%20T_8%2C%20V_8%2C%20z1%2C%20z2%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20For%20sake%20of%20clarity%2C%20let's%20consider%20the%20resting%20lengths%20of%20the%20springs%20to%20be%20zero%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(V_8%2C%20l01%2C%20l02%2C%20printeq)%3A%0A%20%20%20%20V_9%20%3D%20V_8.subs(%5B(l01%2C%200)%2C%20(l02%2C%200)%5D)%0A%20%20%20%20printeq('V'%2C%20V_9)%0A%20%20%20%20return%20(V_9%2C)%0A%0A%0A%40app.cell%0Adef%20_(T_8%2C%20V_9%2C%20printeq)%3A%0A%20%20%20%20L_7%20%3D%20T_8%20-%20V_9%0A%20%20%20%20printeq('%5C%5Cmathcal%7BL%7D'%2C%20L_7)%0A%20%20%20%20return%20(L_7%2C)%0A%0A%0A%40app.cell%0Adef%20_(F%2C%20L_7%2C%20lagrange_eq%2C%20lagrange_terms%2C%20z1%2C%20z2)%3A%0A%20%20%20%20Lterms_7%20%3D%20lagrange_terms(L_7%2C%20%5Bz1%2C%20z2%5D)%0A%20%20%20%20lagrange_eq(Lterms_7%2C%20%5BF%2C%20F%5D)%0A%20%20%20%20return%20(Lterms_7%2C)%0A%0A%0A%40app.cell%0Adef%20_(F%2C%20Lterms_7%2C%20lagrange_eq_solve%2C%20z1%2C%20z2)%3A%0A%20%20%20%20lagrange_eq_solve(Lterms_7%2C%20%5Bz1%2C%20z2%5D%2C%20%5BF%2C%20F%5D)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20The%20solutions%20using%20the%20two%20sets%20of%20coordinates%20seem%20different%3B%20the%20reader%20is%20invited%20to%20verify%20that%20in%20fact%20they%20are%20the%20same%20(remember%20that%20%24y_1%20%3D%20z_1%2C%5C%2C%20y_2%20%3D%20z_1%2Bz_2%2C%5C%2C%20%5Cddot%7By%7D_2%20%3D%20%5Cddot%7Bz%7D_1%2B%5Cddot%7Bz%7D_2%24).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Mass-spring-damper%20system%20with%20gravity%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fmass_spring_damper_gravity.png%3Fraw%3D1%22%20width%3D%22220%22%20alt%3D%22mass-spring-damper%20system%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2050px%2010px%2050px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20a%20mass-spring-damper%20system%20under%20the%20action%20of%20the%20gravitational%20force%20and%20an%20external%20force%20acting%20on%20the%20mass.%3Cbr%3E%0A%20%20%20%20The%20massless%20spring%20has%20a%20stiffness%20coefficient%20%24k%24%20and%20length%20at%20rest%20%24%5Cell_0%24.%3Cbr%3E%0A%20%20%20%20The%20massless%20damper%20has%20a%20damping%20coefficient%20%24b%24.%3Cbr%3E%0A%20%20%20%20The%20gravitational%20force%20acts%20downwards%20and%20it%20is%20negative%20(see%20figure).%3Cbr%3E%0A%20%20%20%20The%20system%20has%20one%20degree%20of%20freedom%20and%20we%20need%20only%20one%20generalized%20coordinate%20(%24y%24)%20to%20describe%20the%20system's%20configuration.%0A%0A%20%20%20%20There%20are%20two%20non-conservative%20forces%20acting%20at%20the%20direction%20of%20the%20generalized%20coordinate%3A%20the%20external%20force%20F%20and%20the%20force%20of%20the%20damper.%20By%20calculating%20the%20work%20done%20by%20each%20of%20these%20forces%2C%20the%20total%20generalized%20force%20is%3A%20%24Q_%7BNC%7D%20%3D%20F_0%20%5Ccos(%5Comega%20t)%20-%20b%5Cdot%20y%24.%0A%0A%20%20%20%20Let's%20use%20the%20Lagrangian%20mechanics%20to%20derive%20the%20equations%20of%20motion%20for%20the%20system.%0A%0A%20%20%20%20The%20kinetic%20energy%20of%20the%20system%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20T%20%3D%20%5Cfrac%7B1%7D%7B2%7D%20m%20%5Cdot%20y%5E2%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20potential%20energy%20of%20the%20system%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20V%20%3D%20%5Cfrac%7B1%7D%7B2%7D%20k%20(y-%5Cell_0)%5E2%20%2B%20m%20g%20y%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20Lagrangian%20function%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BL%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7D%20m%20%5Cdot%20y%5E2%20-%20%5Cfrac%7B1%7D%7B2%7D%20k%20(y-%5Cell_0)%5E2%20-%20m%20g%20y%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20derivatives%20of%20the%20Lagrangian%20w.r.t.%20%24y%24%20and%20%24t%24%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20y%7D%20%26%3D%26%20-k(y-%5Cell_0)%20-%20mg%20%5C%5C%0A%20%20%20%20%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7By%7D%7D%20%26%3D%26%20m%20%5Cdot%7By%7D%20%5C%5C%0A%20%20%20%20%5Cdfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7By%7D%7D%7D%20%5Cright)%20%26%3D%26%20m%5Cddot%7By%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Substituting%20all%20these%20terms%20in%20the%20Euler-Lagrange%20equation%2C%20results%20in%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20m%5Cddot%7By%7D%20%2B%20b%5Cdot%7By%7D%20%2B%20k(y-%5Cell_0)%20%2B%20mg%20%3D%20F_0%20%5Ccos(%5Comega%20t)%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%23%20Numerical%20solution%20of%20the%20equation%20of%20motion%20for%20mass-spring-damper%20system%0A%0A%20%20%20%20Let's%20solve%20numerically%20the%20differential%20equation%20for%20the%20mass-spring-damper%20system%20with%20gravity%20using%20the%20function%20for%20the%20Euler's%20method%20we%20implemented%20before.%20%20We%20just%20have%20to%20write%20a%20new%20function%20for%20calculating%20the%20derivative%20of%20velocity%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(euler_method%2C%20np%2C%20plot)%3A%0A%20%20%20%20def%20_dvdt(t%2C%20y)%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Returns%20dvdt%20at%20%60t%60%20given%20state%20%60y%60.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20m%20%3D%201%0A%20%20%20%20%20%20%20%20k%20%3D%20100%0A%20%20%20%20%20%20%20%20l0%20%3D%201.0%0A%20%20%20%20%20%20%20%20b%20%3D%201.0%0A%20%20%20%20%20%20%20%20F0%20%3D%202.0%0A%20%20%20%20%20%20%20%20f%20%3D%201%0A%20%20%20%20%20%20%20%20g%20%3D%2010%0A%20%20%20%20%20%20%20%20F%20%3D%20F0%20*%20np.cos(2%20*%20np.pi%20*%20f%20*%20t)%0A%20%20%20%20%20%20%20%20return%20(F%20-%20b%20*%20y%5B1%5D%20-%20k%20*%20(y%5B0%5D%20-%20l0)%20-%20m%20*%20g)%20%2F%20m%0A%20%20%20%20(T_9%2C%20_y0%2C%20_h)%20%3D%20(10%2C%20%5B1.1%2C%200%5D%2C%200.01)%0A%20%20%20%20(t_6%2C%20y_3)%20%3D%20euler_method(T_9%2C%20_y0%2C%20_h%2C%20method%3D2%2C%20dvdt%3D_dvdt)%0A%20%20%20%20_labels%20%3D%20%5B'Trajectory%20of%20mass-spring-damper%20system%20(Euler%20method)'%2C%20'Position%20(m)'%2C%20'Velocity%20(m%2Fs)'%5D%0A%20%20%20%20plot(t_6%2C%20y_3%2C%20_labels)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20Here%20is%20the%20solution%20for%20this%20problem%20using%20the%20integration%20method%20explicit%20Runge-Kutta%2C%20a%20method%20with%20smaller%20errors%20in%20the%20integration%20and%20faster%20(for%20large%20amount%20of%20data)%20because%20the%20integration%20method%20in%20the%20Scipy%20function%20is%20implemented%20in%20Fortran%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20plot)%3A%0A%20%20%20%20from%20scipy.integrate%20import%20solve_ivp%0A%0A%20%20%20%20def%20dvdt2(t%2C%20y)%3A%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20Returns%20dvdt%20at%20%60t%60%20given%20state%20%60y%60.%0A%20%20%20%20%20%20%20%20%22%22%22%0A%20%20%20%20%20%20%20%20m%20%3D%201%0A%20%20%20%20%20%20%20%20k%20%3D%20100%0A%20%20%20%20%20%20%20%20l0%20%3D%201.0%0A%20%20%20%20%20%20%20%20b%20%3D%201.0%0A%20%20%20%20%20%20%20%20F0%20%3D%202.0%0A%20%20%20%20%20%20%20%20f%20%3D%201%0A%20%20%20%20%20%20%20%20g%20%3D%2010%0A%20%20%20%20%20%20%20%20F%20%3D%20F0%20*%20np.cos(2%20*%20np.pi%20*%20f%20*%20t)%0A%20%20%20%20%20%20%20%20return%20(y%5B1%5D%2C%20(F%20-%20b%20*%20y%5B1%5D%20-%20k%20*%20(y%5B0%5D%20-%20l0)%20-%20m%20*%20g)%20%2F%20m)%0A%20%20%20%20T_10%20%3D%2010.0%0A%20%20%20%20freq%20%3D%20100%0A%20%20%20%20y02%20%3D%20%5B1.1%2C%200.0%5D%0A%20%20%20%20t_7%20%3D%20np.linspace(0%2C%20T_10%2C%20int(T_10%20*%20freq)%2C%20endpoint%3DFalse)%0A%20%20%20%20s%20%3D%20solve_ivp(fun%3Ddvdt2%2C%20t_span%3D(t_7%5B0%5D%2C%20t_7%5B-1%5D)%2C%20y0%3Dy02%2C%20method%3D'RK45'%2C%20t_eval%3Dt_7)%0A%20%20%20%20_labels%20%3D%20%5B'Trajectory%20of%20mass-spring-damper%20system%20(Runge-Kutta%20method)'%2C%20'Position%20(m)'%2C%20'Velocity%20(m%2Fs)'%5D%0A%20%20%20%20plot(s.t%2C%20s.y%2C%20_labels)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%204%20%E2%80%94%20Add%20dissipation%20correctly.**%20A%20viscous%20damper%20exerts%20%24-b%5Cdot%20x%24%20on%20the%20horizontal%20spring%E2%80%93mass%20system.%20Where%20does%20this%20enter%20Euler%E2%80%93Lagrange%E2%80%99s%20equation%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%204%0A%0A%20%20%20%20As%20generalized%20nonconservative%20force%20%24Q%3D-b%5Cdot%20x%24%3A%20%24m%5Cddot%20x%2Bkx%3D-b%5Cdot%20x%24.%20Equivalently%20use%20the%20Rayleigh%20function%20%24%5Cmathcal%20R%3Db%5Cdot%20x%5E2%2F2%24.%20Putting%20%24b%5Cdot%20x%24%20into%20ordinary%20position%20potential%20energy%20would%20be%20incorrect.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Forces%20of%20constraint%0A%0A%20%20%20%20The%20fact%20the%20Lagrangian%20formalism%20uses%20generalized%20coordinates%20means%20that%20in%20a%20system%20with%20constraints%20we%20typically%20have%20fewer%20coordinates%20(in%20turn%2C%20fewer%20equations%20of%20motion)%20and%20we%20don't%20need%20to%20worry%20about%20forces%20of%20constraint%20that%20we%20would%20have%20to%20consider%20in%20the%20Newtonian%20formalism.%3Cbr%3E%0A%20%20%20%20However%2C%20when%20we%20do%20want%20to%20determine%20a%20force%20of%20constraint%2C%20using%20Lagrangian%20formalism%20in%20fact%20will%20be%20disadvantageous!%20Let's%20see%20now%20one%20way%20of%20determining%20a%20force%20of%20constraint%20using%20Lagrangian%20formalism.%20The%20trick%20is%20to%20postpone%20the%20consideration%20that%20there%20is%20a%20constraint%20in%20the%20system%3B%20this%20will%20increase%20the%20number%20of%20generalized%20coordinates%20but%20will%20allow%20the%20determination%20of%20a%20force%20of%20constraint.%0A%20%20%20%20Let's%20exemplify%20this%20approach%20determining%20the%20tension%20at%20the%20rod%20in%20the%20simple%20pendulum%20under%20the%20influence%20of%20gravity%20we%20saw%20earlier.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Example%3A%20Force%20of%20constraint%20in%20a%20simple%20pendulum%20under%20the%20influence%20of%20gravity%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fsimplependulum_lagrange.png%3Fraw%3D1%22%20width%3D%22220%22%20alt%3D%22simple%20pendulum%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2050px%2010px%2050px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20Consider%20a%20pendulum%20with%20a%20massless%20rod%20of%20length%20%24d%24%20and%20a%20mass%20%24m%24%20at%20the%20extremity%20swinging%20in%20a%20plane%20forming%20the%20angle%20%24%5Ctheta%24%20with%20vertical%20and%20%24g%3D10%20m%2Fs%5E2%24.%0A%0A%20%20%20%20Although%20the%20pendulum%20moves%20at%20the%20plane%2C%20it%20only%20has%20one%20degree%20of%20freedom%2C%20which%20can%20be%20described%20by%20the%20angle%20%24%5Ctheta%24%2C%20the%20generalized%20coordinate.%20But%20because%20we%20want%20to%20determine%20the%20force%20of%20constraint%20tension%20at%20the%20rod%2C%20let's%20also%20consider%20for%20now%20the%20variable%20%24r%24%20for%20the%20'varying'%20length%20of%20the%20rod%20(instead%20of%20the%20constant%20%24d%24).%0A%0A%20%20%20%20In%20this%20case%2C%20the%20kinetic%20energy%20of%20the%20system%20will%20be%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20T%20%3D%20%5Cfrac%7B1%7D%7B2%7Dmr%5E2%5Cdot%5Ctheta%5E2%20%2B%20%5Cfrac%7B1%7D%7B2%7Dm%5Cdot%20r%5E2%0A%20%20%20%20%24%24%0A%0A%20%20%20%20And%20for%20the%20potential%20energy%20we%20will%20also%20have%20to%20consider%20the%20constraining%20potential%2C%20%24V_r(r(t))%24%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20V%20%3D%20-mgr%5Ccos%5Ctheta%20%2B%20V_r(r(t))%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20Lagrangian%20function%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathcal%7BL%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7Dm(%5Cdot%20r%5E2(t)%20%2B%20r%5E2(t)%5C%2C%5Cdot%5Ctheta%5E2(t))%20%2B%20mgr(t)%5Ccos%5Ctheta(t)%20-%20V_r(r(t))%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20derivatives%20w.r.t.%20%24%5Ctheta%24%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Ctheta%7D%20%26%3D%26%20-mgr%5Csin%5Ctheta%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7B%5Ctheta%7D%7D%20%26%3D%26%20mr%5E2%5Cdot%7B%5Ctheta%7D%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7B%5Ctheta%7D%7D%7D%20%5Cright)%20%26%3D%26%202mr%5Cdot%7Br%7D%5Cdot%7B%5Ctheta%7D%20%2B%20mr%5E2%5Cddot%7B%5Ctheta%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20derivatives%20w.r.t.%20%24r%24%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20r%7D%20%26%3D%26%20mr%20%5Cdot%5Ctheta%5E2%20%2B%20mg%5Ccos%5Ctheta%20-%20%5Cdot%7BV%7D_r(r)%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Br%7D%7D%20%26%3D%26%20m%5Cdot%20r%20%5C%5C%0A%20%20%20%20%26%5Cdfrac%7B%5Cmathrm%20d%20%7D%7B%5Cmathrm%20d%20t%7D%5Cleft(%20%7B%5Cdfrac%7B%5Cpartial%20%5Cmathcal%7BL%7D%7D%7B%5Cpartial%20%5Cdot%7Br%7D%7D%7D%20%5Cright)%20%26%3D%26%20m%5Cddot%7Br%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20Euler-Lagrange's%20equations%20(the%20equations%20of%20motion)%20are%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20%262mr%5Cdot%7Br%7D%5Cdot%7B%5Ctheta%7D%20%2B%20mr%5E2%5Cddot%7B%5Ctheta%7D%20%2B%20mgr%5Csin%5Ctheta%20%26%3D%26%200%20%5C%5C%0A%20%20%20%20%26m%5Cddot%7Br%7D%20-%20mr%20%5Cdot%5Ctheta%5E2%20-%20mg%5Ccos%5Ctheta%20%2B%20%5Cdot%7BV%7D_r(r)%20%26%3D%26%200%20%5C%5C%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Now%2C%20we%20will%20apply%20the%20constraint%20condition%2C%20%24r(t)%3Dd%24.%20This%20means%20that%20%24%5Cdot%7Br%7D%3D%5Cddot%7Br%7D%3D0%24.%0A%0A%20%20%20%20With%20this%20constraint%20applied%2C%20the%20first%20Euler-Lagrange%20equation%20is%20the%20equation%20for%20the%20simple%20pendulum%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20md%5E2%5Cddot%7B%5Ctheta%7D%20%2B%20mgd%5Csin%5Ctheta%20%3D%200%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20second%20equation%20yields%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20-%5Cdfrac%7B%5Cmathrm%20d%20V_r%7D%7B%5Cmathrm%20d%20r%7D%5Cbigg%7B%5Crvert%7D_%7Br%3Dd%7D%20%3D%20-%20md%20%5Cdot%5Ctheta%5E2%20-%20mg%5Ccos%5Ctheta%0A%20%20%20%20%24%24%0A%0A%20%20%20%20But%20the%20tension%20force%2C%20%24F_T%24%2C%20is%20by%20definition%20equal%20to%20the%20gradient%20of%20the%20constraining%20potential%2C%20so%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20F_T%20%3D%20-%20md%20%5Cdot%5Ctheta%5E2%20-%20mg%5Ccos%5Ctheta%0A%20%20%20%20%24%24%0A%0A%20%20%20%20As%20expected%2C%20the%20tension%20at%20the%20rod%20is%20proportional%20to%20the%20centripetal%20and%20the%20gravitational%20forces.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20**Exercise%205%20%E2%80%94%20Recover%20a%20constraint%20force.**%20A%20point%20mass%20on%20a%20pendulum%20of%20length%20%24%5Cell%24%20has%20speed%20%24v%24%20at%20the%20lowest%20point.%20What%20tension%20is%20required%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%205%0A%0A%20%20%20%20The%20inward%20radial%20balance%20is%20%24T-mg%3Dmv%5E2%2F%5Cell%24%2C%20so%20%24T%3Dmg%2Bmv%5E2%2F%5Cell%24.%20Eliminating%20tension%20from%20the%20angle%20equation%20does%20not%20mean%20the%20tension%20is%20zero%3B%20it%20can%20be%20recovered%20after%20the%20motion%20is%20known.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Lagrangian%20formalism%20applied%20to%20non-mechanical%20systems%0A%0A%20%20%20%20%23%23%23%20Example%3A%20Lagrangian%20formalism%20for%20RLC%20eletrical%20circuits%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F6%2F65%2FMobility_analogy_resonator_vertical.svg%22%20width%3D%22150%22%20alt%3D%22RLC%20analogy%22%20style%3D%22float%3Aright%3Bmargin%3A%2010px%2010px%2010px%2010px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20It's%20possible%20to%20solve%20a%20RLC%20(Resistance-Inductance-Capacitance)%20electrical%20circuit%20using%20the%20Lagrangian%20formalism%20as%20an%20analogy%20with%20a%20mass-spring-damper%20system.%0A%0A%20%20%20%20In%20such%20analogy%2C%20the%20electrical%20charge%20is%20equivalent%20to%20position%2C%20current%20to%20velocity%2C%20inductance%20to%20mass%2C%20inverse%20of%20the%20capacitance%20to%20spring%20constant%2C%20resistance%20to%20damper%20constant%20(a%20dissipative%20element)%2C%20and%20a%20generator%20would%20be%20analog%20to%20an%20external%20force%20actuating%20on%20the%20system.%20See%20the%20%5BWikipedia%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FMechanical%25E2%2580%2593electrical_analogies)%20and%20%5Bthis%20paper%5D(https%3A%2F%2Farxiv.org%2Fpdf%2F1711.10245.pdf)%20for%20more%20details%20on%20this%20analogy.%0A%0A%20%20%20%20Let's%20see%20how%20to%20deduce%20the%20equivalent%20of%20equation%20of%20motion%20for%20a%20RLC%20series%20circuit%20(the%20Kirchhoff%E2%80%99s%20Voltage%20Law%20(KVL)%20equation).%0A%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2Ff%2Ffb%2FRLC_series_circuit_v1.svg%22%20width%3D%22140%22%20alt%3D%22RLC%20circuit%22%20style%3D%22float%3Aright%3Bmargin%3A%200px%2010px%200px%2010px%3B%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20*Image%20credits%3A%20mechanical%2Felectrical%20analogy%20by%20%5BSpinningspark%5D(https%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FFile%3AMobility_analogy_resonator_vertical.svg)%3B%20RLC%20circuit%20by%20%5BV4711%5D(https%3A%2F%2Fcommons.wikimedia.org%2Fwiki%2FFile%3ARLC_series_circuit_v1.svg).%20Both%20images%20are%20licensed%20under%20%5BCC%20BY-SA%203.0%5D(https%3A%2F%2Fcreativecommons.org%2Flicenses%2Fby-sa%2F3.0%2F).*%0A%0A%20%20%20%20For%20a%20series%20RLC%20circuit%2C%20consider%20the%20following%20notation%3A%3Cbr%3E%0A%20%20%20%20%24q%24%3A%20charge%3Cbr%3E%0A%20%20%20%20%24%5Cdot%7Bq%7D%24%3A%20current%20admitted%20through%20the%20circuit%3Cbr%3E%0A%20%20%20%20%24R%24%3A%20effective%20resistance%20of%20the%20combined%20load%2C%20source%2C%20and%20components%3Cbr%3E%0A%20%20%20%20%24C%24%3A%20capacitance%20of%20the%20capacitor%20component%3Cbr%3E%0A%20%20%20%20%24L%24%3A%20inductance%20of%20the%20inductor%20component%3Cbr%3E%0A%20%20%20%20%24u%24%3A%20voltage%20source%20powering%20the%20circuit%3Cbr%3E%0A%20%20%20%20%24P%24%3A%20power%20dissipated%20by%20the%20resistance%0A%0A%20%20%20%20So%2C%20the%20equivalents%20of%20kinetic%20and%20potential%20energies%20are%3A%3Cbr%3E%0A%20%20%20%20%24T%20%3D%20%5Cfrac%7B1%7D%7B2%7DL%5Cdot%7Bq%7D%5E2%24%3Cbr%3E%0A%20%20%20%20%24V%20%3D%20%5Cfrac%7B1%7D%7B2C%7Dq%5E2%24%3Cbr%3E%0A%20%20%20%20With%20a%20dissipative%20element%3A%3Cbr%3E%0A%20%20%20%20%24P%20%3D%20%5Cfrac%7B1%7D%7B2%7DR%5Cdot%7Bq%7D%5E2%24%3Cbr%3E%0A%20%20%20%20And%20the%20Lagrangian%20function%20is%3A%3Cbr%3E%0A%20%20%20%20%24%5Cmathcal%7BL%7D%20%3D%20%5Cfrac%7B1%7D%7B2%7DL%5Cdot%7Bq%7D%5E2%20-%20%5Cfrac%7B1%7D%7B2C%7Dq%5E2%24%0A%0A%20%20%20%20Calculating%20the%20derivatives%20and%20substituting%20them%20in%20the%20Euler-Lagrange%20equation%2C%20we%20will%20have%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20L%20%5Cddot%7Bq%7D%20%2B%20R%5Cdot%7Bq%7D%20%2B%20%5Cfrac%7Bq%7D%7BC%7D%20%3D%20u(t)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Replacing%20%24%5Cdot%7Bq%7D%24%20by%20%24i%24%20and%20considering%20%24v_c%20%3D%20q%2FC%24%20for%20a%20capacitor%2C%20we%20have%20the%20familar%20KVL%20equation%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20L%20%5Cfrac%7B%5Cmathrm%20d%20i%7D%7B%5Cmathrm%20d%20t%7D%20%2B%20v_c%20%2B%20Ri%20%3D%20u(t)%0A%20%20%20%20%24%24%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Considerations%20on%20the%20Lagrangian%20mechanics%0A%0A%20%20%20%20The%20Lagrangian%20mechanics%20does%20not%20constitute%20a%20new%20theory%20in%20classical%20mechanics%3B%20the%20results%20using%20Lagrangian%20or%20Newtonian%20mechanics%20must%20be%20the%20same%20for%20any%20mechanical%20system%2C%20only%20the%20method%20used%20to%20obtain%20the%20results%20is%20different.%0A%0A%20%20%20%20We%20are%20accustomed%20to%20think%20of%20mechanical%20systems%20in%20terms%20of%20vector%20quantities%20such%20as%20force%2C%20velocity%2C%20angular%20momentum%2C%20torque%2C%20etc.%2C%20but%20in%20the%20Lagrangian%20formalism%20the%20equations%20of%20motion%20are%20obtained%20entirely%20in%20terms%20of%20the%20kinetic%20and%20potential%20energies%20(scalar%20operations)%20in%20the%20configuration%20space.%20Another%20important%20aspect%20of%20the%20force%20vs.%20energy%20analogy%20is%20that%20in%20situations%20where%20it%20is%20not%20possible%20to%20make%20explicit%20all%20the%20forces%20acting%20on%20the%20body%2C%20it%20is%20still%20possible%20to%20obtain%20expressions%20for%20the%20kinetic%20and%20potential%20energies.%0A%0A%20%20%20%20In%20fact%2C%20the%20concept%20of%20force%20does%20not%20enter%20into%20Lagrangian%20mechanics.%20This%20is%20an%20important%20property%20of%20the%20method.%20Since%20energy%20is%20a%20scalar%20quantity%2C%20the%20Lagrangian%20function%20for%20a%20system%20is%20invariant%20for%20coordinate%20transformations.%20Therefore%2C%20it%20is%20possible%20to%20move%20from%20a%20certain%20configuration%20space%20(in%20which%20the%20equations%20of%20motion%20can%20be%20somewhat%20complicated)%20to%20a%20space%20that%20can%20be%20chosen%20to%20allow%20maximum%20simplification%20of%20the%20problem.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_()%3A%0A%20%20%20%20import%20marimo%20as%20mo%0A%0A%20%20%20%20return%20(mo%2C)%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Checkpoint%20questions%0A%0A%20%20%20%201.%20Why%20choose%20independent%20generalized%20coordinates%3F%0A%20%20%20%202.%20When%20does%20a%20conservative%20force%20belong%20in%20V%20rather%20than%20Q%3F%0A%20%20%20%203.%20What%20changes%20when%20a%20constraint%20moves%20with%20time%3F%0A%20%20%20%204.%20Can%20action%20stationarity%20be%20assumed%20to%20be%20a%20global%20minimum%3F%0A%20%20%20%205.%20How%20would%20you%20validate%20a%20symbolic%20equation%20before%20integrating%20it%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Checkpoint%20answers%0A%0A%20%20%20%201.%20They%20incorporate%20geometric%20constraints%20and%20avoid%20redundant%20coordinates.%0A%20%20%20%202.%20When%20it%20derives%20from%20that%20potential%3B%20do%20not%20count%20it%20again%20in%20Q.%0A%20%20%20%203.%20The%20coordinate%20map%20and%20energy%20can%20depend%20explicitly%20on%20time%2C%20and%20moving%20constraints%20can%20do%20work.%0A%20%20%20%204.%20No.%0A%20%20%20%205.%20Check%20dimensions%2C%20simple%20limits%2C%20restoring%20signs%2C%20and%20consistency%20with%20Newton%E2%80%93Euler%20or%20energy%20balance.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Problems%0A%0A%20%20%20%201.%20Derive%20the%20Euler-Lagrange%20equation%20(the%20equation%20of%20motion)%20for%20a%20mass-spring%20system%20where%20the%20spring%20is%20attached%20to%20the%20ceiling%20and%20the%20mass%20in%20hanging%20in%20the%20vertical%20(see%20solution%20for%20a%20system%20with%20two%20masses%20at%20https%3A%2F%2Fyoutu.be%2FdZjjzzWykio).%3Cbr%3E%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fspringgravity.png%3Fraw%3D1%22%20width%3D%22200%22%20alt%3D%22mass-spring%20with%20gravity%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%202.%20Derive%20the%20Euler-Lagrange%20equation%20for%20an%20inverted%20pendulum%20in%20the%20vertical.%3Cbr%3E%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Finvpendulum2.png%3Fraw%3D1%22%20width%3D%22200%22%20alt%3D%22inverted%20pendulum%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%203.%20Derive%20the%20Euler-Lagrange%20equation%20for%20the%20following%20system%20(see%20solution%20at%20https%3A%2F%2Fyoutu.be%2F8FSjEsUVNx8)%3A%3Cbr%3E%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fmassessprings_lagrange.png%3Fraw%3D1%22%20width%3D%22280%22%20alt%3D%22two%20masses%20and%20two%20springs%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%204.%20Derive%20the%20Euler-Lagrange%20equation%20for%20a%20spring%20pendulum%2C%20a%20simple%20pendulum%20where%20a%20mass%20%24m%24%20is%20attached%20to%20a%20massless%20spring%20with%20spring%20constant%20%24k%24%20and%20length%20at%20rest%20%24d_0%24%20%20(see%20solution%20at%20https%3A%2F%2Fyoutu.be%2FiULa9A00JpA).%3Cbr%3E%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fpendulumspring.png%3Fraw%3D1%22%20width%3D%22200%22%20alt%3D%22mass-spring%20pendulum%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%205.%20Derive%20the%20Euler-Lagrange%20equation%20for%20the%20system%20shown%20below%20(see%20solution%20for%20one%20mass%20spring%20system%20at%20https%3A%2F%2Fyoutu.be%2FeY0I8QK-ITE).%3Cbr%3E%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fpendulumramp.png%3Fraw%3D1%22%20width%3D%22250%22%20alt%3D%22pendulum%20on%20a%20ramp%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%206.%20Derive%20the%20Euler-Lagrange%20equation%20for%20the%20following%20Atwood%20machine%20(consider%20that%20%24m_1%20%3E%20m_2%24%2C%20i.e.%2C%20the%20pulley%20will%20rotate%20counter-clockwise%2C%20and%20that%20moving%20down%20is%20in%20the%20positive%20direction)%20(see%20solution%20at%20https%3A%2F%2Fyoutu.be%2FlVg8I23Khz4)%3A%3Cbr%3E%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fatwood_machine.png%3Fraw%3D1%22%20width%3D%22125%22%20alt%3D%22Atwood%20machine%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%207.%20Derive%20the%20Euler-Lagrange%20equation%20for%20the%20system%20below%20(see%20solution%20at%20https%3A%2F%2Fyoutu.be%2Fgsi_0cVZ5-s)%3A%3Cbr%3E%0A%20%20%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fcart_pendulum_spring.png%3Fraw%3D1%22%20width%3D%22250%22%20alt%3D%22cart_pendulum_spring%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%208.%20Consider%20a%20person%20hanging%20by%20their%20hands%20from%20a%20bar%20and%20this%20person%20oscillates%20freely%2C%20behaving%20like%20a%20rigid%20pendulum%20under%20the%20action%20of%20gravity.%20The%20person's%20mass%20is%20%24m%24%2C%20the%20distance%20from%20their%20center%20of%20gravity%20to%20the%20bar%20is%20%24r%24%2C%20their%20rotational%20inertia%20is%20%24I%24%2C%20a%20line%20that%20passes%20through%20the%20bar%20and%20the%20person's%20body%20forms%20an%20angle%20%24%5Ctheta%24%20with%20the%20vertical%20and%20the%20magnitude%20of%20the%20acceleration%20of%20gravity%20is%20%24g%24.%3Cbr%3E%0A%20%20%20%20%20%20a.%20Derive%20the%20equation%20of%20motion%20for%20the%20person's%20body%20using%20the%20Lagrangian%20formalism.%3Cbr%3E%0A%20%20%20%20%20%20b.%20If%20%24m%3D100%20kg%24%2C%20%24r%3D1%20m%24%20and%20%24g%3D10%20m%2Fs%5E2%24%20and%20the%20person%20takes%20%241%20s%24%20to%20perform%20a%20complete%20oscillation%2C%20calculate%20an%20estimate%20for%20the%20rotational%20inertia.%3Cbr%3E%0A%20%20%20%20%20%20Tip%3A%20Use%20the%20approximation%20that%20for%20small%20angles%20%24%5Csin%5Ctheta%20%5Capprox%20%5Ctheta%24%20and%20solve%20the%20differential%20equation.%0A%0A%20%20%20%209.%20Consider%20a%20mass-spring%20system%20under%20the%20action%20of%20gravity%20where%20the%20spring%20is%20attached%20to%20the%20ceiling%20and%20the%20mass%20in%20hanging%20in%20the%20vertical.%20The%20spring's%20proportionality%20constant%20is%20%24k%20%3D%202%20N%2Fm%24%20and%20its%20resting%20length%20is%20%24%5Cell_0%3D1%20m%24.%20The%20mass%20attached%20to%20the%20spring%20is%20%242%20kg%24.%20Use%20%24g%20%3D%2010m%2Fs%5E2%24.%3Cbr%3E%0A%20%20%20%20%20%20a.%20Derive%20the%20differential%20equation%20that%20describes%20the%20movement%20of%20mass.%3Cbr%3E%0A%20%20%20%20%20%20b.%20Calculate%20the%20position%20of%20the%20mass%20over%20time%20considering%20that%20the%20spring%20is%20initially%202%20m%20long%20and%20at%20rest.%3Cbr%3E%0A%20%20%20%20%20%20c.%20Write%20a%20pseudocode%20to%20calculate%20the%20position%20of%20the%20mass%20by%20numerical%20calculation%20using%20Euler's%20method%20to%20solve%20the%20differential%20equation.%0A%0A%20%20%20%2010.%20A%20widely%20used%20approach%20to%20study%20the%20interaction%20between%20the%20human%20body%20and%20the%20ground%20in%20locomotion%20is%20to%20model%20this%20interaction%20as%20a%20mass-spring-damper%20system%20with%20different%20quantities%20of%20these%20components.%20In%20an%20experiment%20to%20study%20this%20interaction%20during%20running%2C%20the%20vertical%20ground%20reaction%20force%20(GRF)%20was%20measured%20during%20the%20stance%20phase%20of%20a%20runner%20with%20a%20mass%20equal%20to%20%24100%20kg%24%20and%20the%20magnitude%20of%20GRF%20versus%20time%20is%20shown%20in%20the%20figure.%20Use%20%24g%3D10%24%20m%2Fs%C2%B2%20for%20this%20problem.%20%20%3Cfigure%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2FGRFv.png%3Fraw%3D1%22%20width%3D%22350%22%20alt%3D%22GRFv%22%2F%3E%3C%2Ffigure%3E%3Cbr%3E%0A%20%20%20%20%20%20a.%20Draw%20a%20free-body%20diagram%20for%20the%20runner's%20center%20of%20gravity.%3Cbr%3E%0A%20%20%20%20%20%20b.%20The%20maximum%20height%20of%20the%20runner%20in%20the%20aerial%20phase%20after%20the%20support%20phase%20shown%20in%20the%20graph%20above%2C%20knowing%20that%20the%20initial%20height%20and%20vertical%20speed%20(at%20%24t%3D0%20s%24)%20of%20the%20runner%20(from%20his%20center%20of%20gravity)%20were%20%24y_0%20%3D%201%20m%24%20and%20%24v_0%20%3D%20%E2%80%932%20%20m%2Fs%24.%3Cbr%3E%0A%20%20%20%20%20%20c.%20Draw%20the%20free-body%20diagram%20for%20a%20mechanical%20model%20of%20the%20runner%20as%20a%20system%20consisting%20of%20a%20mass%20and%20spring%20and%20interaction%20with%20the%20ground.%3Cbr%3E%0A%20%20%20%20%20%20d.%20Derive%20the%20equation%20of%20motion%20for%20this%20model%20obtained%20in%20item%20c.%3Cbr%3E%0A%20%20%20%20%20%20e.%20Write%20a%20pseudocode%20to%20calculate%20the%20vertical%20trajectory%20from%20the%20differential%20equation%20obtained%20in%20item%20d%20by%20numerical%20calculation%20using%20Euler's%20method.%0A%0A%20%20%20%2011.%20Write%20computer%20programs%20(in%20Python!)%20to%20solve%20numerically%20the%20equations%20of%20motion%20from%20the%20problems%20above.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Final%20answers%20to%20original%20Problems%0A%0A%20%20%20%201.%20With%20downward%20extension%20%24x%24%20from%20the%20spring%E2%80%99s%20natural%20length%3A%20%24m%5Cddot%20x%2Bkx%3Dmg%24.%0A%0A%20%20%20%202.%20With%20angle%20from%20upright%20and%20pivot%20inertia%20%24I_O%24%3A%20%24I_O%5Cddot%5Ctheta-mgr%5Csin%5Ctheta%3D0%24%3B%20for%20a%20point%20pendulum%2C%20%24r%3D%5Cell%24%20and%20%24I_O%3Dm%5Cell%5E2%24.%0A%0A%20%20%20%203.%20With%20rightward%20displacements%20from%20unstretched%20positions%3A%20%24m_1%5Cddot%20x_1%2B(k_1%2Bk_2)x_1-k_2x_2%3D0%24%20and%20%24m_2%5Cddot%20x_2%2Bk_2(x_2-x_1)%3D0%24.%0A%0A%20%20%20%204.%20With%20spring%20length%20%24r%24%20and%20angle%20from%20downward%20vertical%3A%20%24m%5Cddot%20r-mr%5Cdot%5Ctheta%5E2%2Bk(r-d_0)-mg%5Ccos%5Ctheta%3D0%24%20and%20%24mr%5E2%5Cddot%5Ctheta%2B2mr%5Cdot%20r%5Cdot%5Ctheta%2Bmgr%5Csin%5Ctheta%3D0%24.%0A%0A%20%20%20%205.%20Label%20the%20upper%20mass%20%24m_1%24%2C%20lower%20mass%20%24m_2%24%2C%20ceiling%20spring%20%24k_1%24%20and%20intermass%20spring%20%24k_2%24%3B%20let%20downhill%20extensions%20be%20%24x_1%2Cx_2%24.%20Then%20%24m_1%5Cddot%20x_1%2B(k_1%2Bk_2)x_1-k_2x_2%3Dm_1g%5Csin%5Cbeta%24%20and%20%24m_2%5Cddot%20x_2%2Bk_2(x_2-x_1)%3Dm_2g%5Csin%5Cbeta%24%2C%20where%20%24%5Cbeta%24%20is%20ramp%20angle.%20The%20springs%E2%80%99%20rest%20lengths%20are%20absorbed%20into%20the%20reference%20positions.%0A%0A%20%20%20%206.%20For%20a%20massless%20frictionless%20pulley%2C%20%24%5Cddot%20x%3D(m_1-m_2)g%2F(m_1%2Bm_2)%24%2C%20with%20%24m_1%24%20downward%20positive.%20If%20pulley%20inertia%20is%20%24I_p%24%20and%20radius%20%24R%24%2C%20the%20denominator%20is%20%24m_1%2Bm_2%2BI_p%2FR%5E2%24.%0A%0A%20%20%20%207.%20For%20cart%20position%20%24x%24%20and%20uniform%20rod%20angle%20%24%5Ctheta%24%20from%20downward%20vertical%3A%20%24(m_1%2Bm_2)%5Cddot%20x%2B(m_2%5Cell%2F2)(%5Cddot%5Ctheta%5Ccos%5Ctheta-%5Cdot%5Ctheta%5E2%5Csin%5Ctheta)%2Bkx%3D0%24%20and%20%24(m_2%5Cell%5E2%2F3)%5Cddot%5Ctheta%2B(m_2%5Cell%2F2)%5Cddot%20x%5Ccos%5Ctheta%2B(m_2g%5Cell%2F2)%5Csin%5Ctheta%3D0%24.%0A%0A%20%20%20%208.%20(a)%20%24I_O%5Cddot%5Ctheta%2Bmgr%5Csin%5Ctheta%3D0%24.%20(b)%20The%20formal%20small-angle%20period%20estimate%20is%20%24I_O%3Dmgr(T%2F2%5Cpi)%5E2%3D25.3303%24%20kg%20m%C2%B2.%20**No%20rigid%20body%20with%20the%20supplied%20%24m%3D100%24%20kg%20and%20%24r%3D1%24%20m%20can%20have%20that%20pivot%20inertia**%2C%20because%20%24I_O%5Cge%20mr%5E2%3D100%24%20kg%20m%C2%B2.%20The%20given%201%20s%20period%20is%20physically%20inconsistent%3B%20the%20minimum%20possible%20small-angle%20period%20is%20about%201.987%20s.%0A%0A%20%20%20%209.%20With%20downward%20total%20spring%20length%20%24y%24%3A%20%24%5Cddot%20y%2By%3D11%24%20(SI%20units)%2C%20%24y(t)%3D11-9%5Ccos%20t%24%20m.%20Forward-Euler%20updates%20are%20%24y_%7Bn%2B1%7D%3Dy_n%2Bv_n%5CDelta%20t%24%2C%20%24v_%7Bn%2B1%7D%3Dv_n%2B(11-y_n)%5CDelta%20t%24%2C%20initialized%20at%20%24(y_0%2Cv_0)%3D(2%2C0)%24.%0A%0A%20%20%20%2010.%20For%20%24g%3D10%24%20m%2Fs%C2%B2%20and%20the%20triangular%20GRF%20in%20the%20figure%3A%20FBD%20has%20GRF%20up%20and%20%24mg%24%20down%3B%20takeoff%20velocity%20is%202%20m%2Fs%2C%20takeoff%20height%20is%201%20m%20and%20apex%20height%20is%201.2%20m.%20In%20a%20unilateral%20spring%20model%20with%20upward%20coordinate%20y%20and%20natural%20leg%20length%20%24L_0%24%2C%20%24m%5Cddot%20y%3Dk%5Cmax(L_0-y%2C0)-mg%24%20during%20contact%20and%20%24%5Cddot%20y%3D-g%24%20in%20flight.%20Explicit-Euler%20updates%20are%20%24y_%7Bn%2B1%7D%3Dy_n%2Bv_n%5CDelta%20t%24%20and%20%24v_%7Bn%2B1%7D%3Dv_n%2Ba(y_n)%5CDelta%20t%24%2C%20with%20contact%20switching%20at%20the%20chosen%20leg-length%20boundary.%0A%0A%20%20%20%2011.%20Numerical%20programs%20should%20converge%20to%20the%20stated%20equations%20and%20available%20analytical%20trajectories%20as%20step%20size%20decreases.%20Parameter%20values%20and%20initial%20conditions%20must%20be%20specified%20for%20cases%20that%20provide%20only%20symbolic%20models.%0A%20%20%20%20%2F%2F%2F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20Go%20deeper%0A%0A%20%20%20%20-%20%5BThe%20Principle%20of%20Least%20Action%5D(https%3A%2F%2Fwww.feynmanlectures.caltech.edu%2FII_19.html)%0A%20%20%20%20-%20Vandiver%20JK%20(MIT%20OpenCourseWare)%20%5BAn%20Introduction%20to%20Lagrangian%20Mechanics%5D(https%3A%2F%2Focw.mit.edu%2Fcourses%2Fmechanical-engineering%2F2-003sc-engineering-dynamics-fall-2011%2Flagrange-equations%2FMIT2_003SCF11_Lagrange.pdf)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20-%20iLectureOnline%3A%20%5BLectures%20in%20Lagrangian%20Mechanics%5D(http%3A%2F%2Fwww.ilectureonline.com%2Flectures%2Fsubject%2FPHYSICS%2F34%2F245)%0A%20%20%20%20-%20MIT%20OpenCourseWare%3A%20%5BIntroduction%20to%20Lagrange%20With%20Examples%5D(https%3A%2F%2Fyoutu.be%2Fzhk9xLjrmi4)%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%23%20Additional%20verified%20lecture%0A%0A%20%20%20%20%5BMIT%20OpenCourseWare%5D(https%3A%2F%2Focw.mit.edu%2Fcourses%2F2-003sc-engineering-dynamics-fall-2011%2Fpages%2Flagrange-equations%2F)%20%E2%80%94%20Lagrange%20equations%3A%20follow%20the%20energy-to-equation%20method%20in%20the%20lecture%20and%20worked%20examples.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_(mo)%3A%0A%20%20%20%20mo.md(r%22%22%22%0A%20%20%20%20%23%23%20References%0A%0A%20%20%20%20-%20Hamilton%20WR%20(1834)%20%5BOn%20a%20General%20Method%20in%20Dynamics%5D(https%3A%2F%2Fwww.maths.tcd.ie%2Fpub%2FHistMath%2FPeople%2FHamilton%2FDynamics%2F%23GenMethod).%20Philosophical%20Transactions%20of%20the%20Royal%20Society%2C%20part%20II%2C%20247-308.%0A%0A%20%20%20%20-%20Ruina%20A%2C%20Rudra%20P%20(2019)%20%5BIntroduction%20to%20Statics%20and%20Dynamics%5D(https%3A%2F%2Fruina.tam.cornell.edu%2FBook%2Findex.html).%20Oxford%20University%20Press.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
6b04d8a6dd3845be9dd711fcc030f46f