%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%22seaborn%3E%3D0.13%22%2C%20%22urllib3%3E%3D2.2%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%20Inverse%20dynamics%20(2D)%20for%20gait%20analysis%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%20A%20force%20plate%20measures%20force%20at%20the%20ground%2C%20not%20at%20the%20knee.%20How%20can%20we%20estimate%20what%20the%20knee%20must%20transmit%3F%20We%20will%20work%20upward%20from%20the%20foot%20using%20Newton%E2%80%93Euler%20equations%2C%20then%20compare%20the%20calculated%20joint%20forces%20and%20moments%20with%20the%20known%20values%20of%20the%20supplied%20simulated%20gait.%0A%0A%20%20%20%20Read%20each%20free-body%20diagram%20before%20running%20its%20calculation.%20You%20need%20planar%20vectors%2C%20differentiation%20and%20moments%20of%20force.%20The%20Exercises%20cover%20balance%2C%20signs%2C%20filtering%20and%20interpretation%3B%20their%20worked%20solutions%20are%20collapsed.%20The%20original%20Problems%20ask%20you%20to%20carry%20the%20method%20to%20experimental%20data%20and%20another%20task.%0A%0A%20%20%20%20**Opening%20challenge.**%20At%20an%20instant%20when%20a%20stationary%201%20kg%20foot%20has%20a%20600%20N%20upward%20ground%20reaction%20force%2C%20what%20vertical%20force%20must%20the%20shank%20exert%20on%20it%3F%20Does%20that%20number%20equal%20a%20bone-on-bone%20contact%20force%3F%0A%0A%20%20%20%20The%20examples%20use%20repository%20data%20and%20helper%20code.%20A%20standalone%20copy%20retrieves%20those%20assets%20over%20the%20network.%20NumPy%2C%20SciPy%2C%20Matplotlib%2C%20Seaborn%20and%20IPython%20are%20declared%20in%20the%20file%3B%20network%20or%20parsing%20errors%20remain%20visible.%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%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell(hide_code%3DTrue)%0Adef%20_()%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20from%20notebook_resources%20import%20repo_file%0A%20%20%20%20except%20ModuleNotFoundError%20as%20_error%3A%0A%20%20%20%20%20%20%20%20if%20_error.name%20!%3D%20%22notebook_resources%22%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20raise%0A%20%20%20%20%20%20%20%20raise%20ModuleNotFoundError(%0A%20%20%20%20%20%20%20%20%20%20%20%20%22This%20notebook%20needs%20notebook_resources.py.%20Download%20it%20from%3A%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22https%3A%2F%2Fraw.githubusercontent.com%2FBMClab%2FBMC%2Fmaster%2Ffunctions%2Fnotebook_resources.py%5Cn%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%22Save%20it%20in%20the%20same%20folder%20as%20this%20notebook%2C%20then%20rerun%20this%20cell.%22%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20name%3D%22notebook_resources%22%2C%0A%20%20%20%20%20%20%20%20)%20from%20None%0A%20%20%20%20return%20(repo_file%2C)%0A%0A%0A%40app.cell%0Adef%20_(repo_file)%3A%0A%20%20%20%20%23%20import%20the%20necessary%20libraries%0A%20%20%20%20import%20numpy%20as%20np%0A%20%20%20%20from%20numpy%20import%20cross%0A%20%20%20%20from%20IPython.display%20import%20IFrame%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%20import%20sys%0A%20%20%20%20sys.path.insert(0%2C%20str(repo_file('functions%2Finvdyn2d.py').parent))%20%20%23%20add%20to%20pythonpath%0A%20%20%20%20return%20IFrame%2C%20np%2C%20plt%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%20Forward%20and%20inverse%20dynamics%0A%0A%20%20%20%20With%20respect%20to%20the%20equations%20of%20motion%20to%20determine%20the%20dynamics%20of%20a%20system%2C%20there%20are%20two%20general%20approaches%3A%20forward%20(or%20direct)%20and%20inverse%20dynamics.%20For%20example%2C%20consider%20the%20solution%20of%20Newton's%20second%20law%20for%20a%20particle.%20If%20we%20know%20the%20force(s)%20and%20want%20to%20find%20the%20trajectory%2C%20this%20is%20**forward%20dynamics**.%20If%20instead%2C%20we%20know%20the%20trajectory%20and%20want%20to%20find%20the%20force(s)%2C%20this%20is%20**inverse%20dynamics**%3A%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-1%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fdynamics.png%3Fraw%3D1%22%20alt%3D%22Forward%20and%20inverse%20dynamics.%22%20width%3D220%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20%3Cspan%20id%3D%22figure-caption-1%22%20class%3D%22figure-caption%22%20style%3D%22display%3Ablock%3Btext-align%3Acenter%3Bfont-style%3Aitalic%22%3EFigure.%20The%20equation%20of%20motion%20and%20the%20forward%20and%20inverse%20dynamics%20approaches.%3C%2Fspan%3E%0A%0A%20%20%20%20In%20Biomechanics%2C%20in%20a%20typical%20movement%20analysis%20of%20the%20human%20body%20using%20inverse%20dynamics%2C%20we%20would%20measure%20the%20positions%20of%20the%20segments%20and%20measure%20the%20external%20forces%2C%20calculate%20the%20segments'%20linear%20and%20angular%20acceleration%2C%20and%20find%20the%20internal%20net%20force%20and%20moment%20of%20force%20at%20the%20joint%20using%20the%20equations%20of%20motion.%20In%20addition%2C%20we%20could%20estimate%20the%20muscle%20forces%20(if%20we%20solve%20the%20redundancy%20problem%20of%20having%20more%20muscles%20than%20joints).%3Cbr%3E%0A%20%20%20%20Using%20forward%20dynamics%2C%20the%20muscle%20forces%20would%20be%20the%20inputs%20and%20the%20trajectories%20of%20the%20segments%20would%20be%20the%20outputs.%20The%20figure%20below%20compares%20the%20forward%20and%20inverse%20dynamics%20approaches.%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-2%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2FInvDirDyn.png%3Fraw%3D1%22%20alt%3D%22Direct%20and%20inverse%20dynamics.%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20%3Cspan%20id%3D%22figure-caption-2%22%20class%3D%22figure-caption%22%20style%3D%22display%3Ablock%3Btext-align%3Acenter%3Bfont-style%3Aitalic%22%3EFigure.%20Inverse%20dynamics%20and%20Forward%20(or%20Direct)%20dynamics%20approaches%20for%20movement%20analysis%20(adapted%20from%20Zajac%20and%20Gordon%2C%201989).%3C%2Fspan%3E%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%20Estimation%20of%20joint%20force%20and%20moments%20of%20force%20by%20inverse%20dynamics%0A%0A%20%20%20%20Let's%20estimate%20the%20joint%20force%20and%20moments%20of%20force%20at%20the%20lower%20limb%20during%20locomotion%20using%20the%20inverse%20dynamics%20approach.%3Cbr%3E%0A%20%20%20%20We%20will%20model%20the%20lower%20limbs%20at%20the%20right%20side%20as%20composed%20by%20three%20rigid%20bodies%20(foot%2C%20leg%2C%20and%20thigh)%20articulated%20by%20three%20hinge%20joints%20(ankle%2C%20knee%2C%20and%20hip)%20and%20perform%20a%20two-dimensional%20analysis.%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%20Free%20body%20diagrams%0A%0A%20%20%20%20The%20%5Bfree%20body%20diagrams%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Ffree_body_diagram.py)%20of%20the%20lower%20limbs%20are%3A%3Cbr%3E%0A%20%20%20%20%3Cbr%3E%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-3%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Ffbdgaitb.png%3Fraw%3D1%22%20width%3D640%20alt%3D%22FBD%20lowerlimb%22%2F%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20%3Cspan%20id%3D%22figure-caption-3%22%20class%3D%22figure-caption%22%20style%3D%22display%3Ablock%3Btext-align%3Acenter%3Bfont-style%3Aitalic%22%3EFigure.%20Free%20body%20diagrams%20of%20the%20lower%20limbs%20for%20a%20gait%20analysis.%20%3Cb%3EGRF%3C%2Fb%3E%20is%20the%20resultant%20ground%20reaction%20force%20applied%20on%20the%20foot%20at%20the%20center%20of%20pressure%2C%20%3Cb%3ECOP%3C%2Fb%3E%2C%20position.%3C%2Fspan%3E%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.**%20Answer%20the%20opening%20challenge%20using%20upward-positive%20forces.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Worked%20solution%20%E2%80%94%20Exercise%201%0A%0A%20%20%20%20%24F_%7Bshank%7D%2B600-9.81%3D0%24%2C%20so%20%24F_%7Bshank%7D%3D-590.19%24%20N%3A%20downward%20on%20the%20foot.%20Muscle%20and%20other%20internal%20forces%20are%20combined%20in%20this%20net%20joint%20force%2C%20so%20it%20is%20not%20the%20contact%20force%20between%20bones.%0A%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%20Equations%20of%20motion%0A%0A%20%20%20%20The%20equilibrium%20equations%20for%20the%20forces%20and%20moments%20of%20force%20around%20the%20center%20of%20mass%20are%3A%0A%0A%20%20%20%20For%20body%201%20(foot)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_1%20%2B%20m_1%5Cmathbf%7Bg%7D%20%2B%20%5Cmathbf%7BGRF%7D%20%3D%20m_1%5Cmathbf%7Ba%7D_1%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_1%20%2B%20%5Cmathbf%7Br%7D_%7Bcmp1%7D%5Ctimes%5Cmathbf%7BF%7D_1%20%2B%20%5Cmathbf%7Br%7D_%7BcmCOP%7D%5Ctimes%5Cmathbf%7BGRF%7D%20%3D%20I_1%5Cmathbf%7B%5Calpha%7D_1%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20body%202%20(leg)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_2%20%2B%20m_2%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BF%7D_1%20%3D%20m_2%5Cmathbf%7Ba%7D_2%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_2%20%2B%20%5Cmathbf%7Br%7D_%7Bcmp2%7D%5Ctimes%5Cmathbf%7BF%7D_2%20%2B%20%5Cmathbf%7Br%7D_%7Bcmd2%7D%5Ctimes-%5Cmathbf%7BF%7D_%7B1%7D%20-%20%5Cmathbf%7BM%7D_1%20%3D%20I_2%5Cmathbf%7B%5Calpha%7D_2%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20body%203%20(thigh)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_3%20%2B%20m_3%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BF%7D_2%20%3D%20m_3%5Cmathbf%7Ba%7D_3%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_3%20%2B%20%5Cmathbf%7Br%7D_%7Bcmp3%7D%5Ctimes%5Cmathbf%7BF%7D_3%20%2B%20%5Cmathbf%7Br%7D_%7Bcmd3%7D%5Ctimes-%5Cmathbf%7BF%7D_%7B2%7D%20-%20%5Cmathbf%7BM%7D_2%20%3D%20I_3%5Cmathbf%7B%5Calpha%7D_3%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Where%20%24p%24%20and%20%24d%24%20stands%20for%20proximal%20and%20distal%20joints%20(with%20respect%20to%20the%20fixed%20extremity)%2C%20%24%5Cmathbf%7Br%7D_%7Bcmji%7D%24%20is%20the%20position%20vector%20from%20the%20center%20of%20mass%20of%20body%20%24i%24%20to%20the%20joint%20%24j%24%2C%20%24COP%24%20is%20the%20center%20of%20pressure%2C%20the%20position%20of%20application%20of%20the%20resultant%20ground%20reaction%20force%20(GRF)%2C%20%24%5Cmathbf%7B%5Calpha%7D%24%20is%20the%20angular%20acceleration%2C%20and%20%24g%24%20is%20the%20acceleration%20of%20gravity%0A%0A%20%20%20%20Note%20that%20the%20pattern%20of%20the%20equations%20is%20the%20same%20for%20the%20three%20segments%3A%20distal%20and%20proximal%20forces%20and%20moments%20of%20force%20and%20the%20weight%20force%20are%20present%20in%20all%20segments.%3Cbr%3E%0A%20%20%20%20The%20only%20exception%20is%20with%20the%20foot%20in%20contact%20with%20the%20ground.%20As%20the%20ground%20only%20pushes%20the%20foot%2C%20it%20can%20not%20generate%20a%20moment%20of%20force%20over%20the%20foot.%20Because%20of%20that%20we%20model%20the%20interaction%20foot-ground%20as%20a%20resultant%20ground%20reaction%20force%20(GRF)%20applied%20on%20the%20foot%20at%20the%20COP%20position.%0A%0A%20%20%20%20Both%20GRF%20and%20COP%20quantities%20are%20measured%20with%20a%20force%20platform%20and%20are%20assumed%20as%20known%20quantities.%3Cbr%3E%0A%20%20%20%20Because%20of%20that%20the%20system%20of%20equations%20above%20is%20only%20solvable%20if%20we%20start%20by%20the%20body%201%2C%20from%20bottom%20to%20top.%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%20system%20of%20equations%20above%20is%20simple%20and%20straightforward%20to%20solve%2C%20it%20is%20just%20a%20matter%20of%20being%20systematic.%3Cbr%3E%0A%20%20%20%20We%20start%20by%20segment%201%2C%20find%20%24%5Cmathbf%7BF%7D_1%24%20and%20%24%5Cmathbf%7BM%7D_1%24%2C%20substitute%20these%20values%20on%20the%20equations%20for%20segment%202%2C%20find%20%24%5Cmathbf%7BF%7D_2%24%20and%20%24%5Cmathbf%7BM%7D_2%24%2C%20substitute%20them%20in%20the%20equations%20for%20segment%203%20and%20find%20%24%5Cmathbf%7BF%7D_3%24%20and%20%24%5Cmathbf%7BM%7D_3%5C%3A%24%3A%0A%0A%20%20%20%20For%20body%201%20(foot)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_1%20%26%3D%26%20m_1%5Cmathbf%7Ba%7D_1%20-%20m_1%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_1%20%26%3D%26%20I_1%5Cmathbf%7B%5Calpha%7D_1%20-%20%5Cmathbf%7Br%7D_%7Bcmp1%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20-%20m_1%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%20-%20%5Cmathbf%7Br%7D_%7BcmCOP%7D%5Ctimes%5Cmathbf%7BGRF%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20body%202%20(leg)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_2%20%26%3D%26%20m_1%5Cmathbf%7Ba%7D_1%20%2B%20m_2%5Cmathbf%7Ba%7D_2%20-%20(m_1%2Bm_2)%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_2%20%26%3D%26%20I_1%5Cmathbf%7B%5Calpha%7D_1%20%2B%20I_2%5Cmathbf%7B%5Calpha%7D_2%20-%20%5Cmathbf%7Br%7D_%7Bcmp2%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20%2B%20m_2%5Cmathbf%7Ba%7D_2%20-%20(m_1%2Bm_2)%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%5C%2C%20%2B%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7Bcgd2%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20-%20m_1%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%20-%20%5Cmathbf%7Br%7D_%7Bcmp1%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20-%20m_1%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%5C%2C%20-%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7BcmCOP%7D%5Ctimes%5Cmathbf%7BGRF%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20body%203%20(thigh)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_3%20%26%3D%26%20m_1%5Cmathbf%7Ba%7D_1%20%2B%20m_2%5Cmathbf%7Ba%7D_2%20%2B%20m_3%5Cmathbf%7Ba%7D_3%20-%20(m_1%2Bm_2%2Bm_3)%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_3%20%26%3D%26%20I_1%5Cmathbf%7B%5Calpha%7D_1%20%2B%20I_2%5Cmathbf%7B%5Calpha%7D_2%20%2B%20I_3%5Cmathbf%7B%5Calpha%7D_3%5C%2C%20-%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7Bcmp3%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20%2B%20m_2%5Cmathbf%7Ba%7D_2%20%2B%20m_3%5Cmathbf%7Ba%7D_3%5C%2C%20-%20(m_1%2Bm_2%2Bm_3)%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%5C%2C%20%2B%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7Bcmd3%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20%2B%20m_2%5Cmathbf%7Ba%7D_2%20-%20(m_1%2Bm_2)%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%5C%2C%20-%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7Bcmp2%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20%2B%20m_2%5Cmathbf%7Ba%7D_2%20-%20(m_1%2Bm_2)%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%5C%2C%20%2B%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7Bcmd2%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20-%20m_1%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%5C%2C%20-%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7Bcmp1%7D%5Ctimes%5Cbig(m_1%5Cmathbf%7Ba%7D_1%20-%20m_1%5Cmathbf%7Bg%7D%20-%20%5Cmathbf%7BGRF%7D%5Cbig)%5C%2C%20-%20%5C%5C%0A%20%20%20%20%26%5Cphantom%7B%3D%7D%26%20%5Cmathbf%7Br%7D_%7BcmCOP%7D%5Ctimes%5Cmathbf%7BGRF%7D%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%23%23%23%20The%20recursive%20approach%20for%20inverse%20dynamics%20of%20multi-body%20systems%0A%0A%20%20%20%20The%20calculation%20above%20is%20tedious%2C%20error%20prone%2C%20useless%2C%20and%20probably%20it's%20wrong.%0A%0A%20%20%20%20To%20make%20some%20use%20of%20it%2C%20we%20can%20clearly%20see%20that%20forces%20act%20on%20far%20segments%2C%20which%20are%20not%20directly%20in%20contact%20with%20these%20forces.%20In%20fact%2C%20this%20is%20true%20for%20all%20stuff%20happening%20on%20a%20segment%3A%20note%20that%20%24%5Cmathbf%7BF%7D_1%24%20and%20%24%5Cmathbf%7BM%7D_1%24%20are%20present%20in%20the%20expression%20for%20%24%5Cmathbf%7BF%7D_3%24%20and%20%24%5Cmathbf%7BM%7D_3%24%20and%20that%20the%20acceleration%20of%20segment%201%20matters%20for%20the%20calculations%20of%20segment%203.%0A%0A%20%20%20%20Instead%2C%20we%20can%20use%20the%20power%20of%20computer%20programming%20(like%20this%20one%20right%20now!)%20and%20solve%20these%20equations%20recursively%20hence%20they%20have%20the%20same%20pattern.%20Let's%20do%20that.%0A%0A%20%20%20%20For%20body%201%20(foot)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_1%20%3D%20m_1%5Cmathbf%7Ba%7D_1%20-%20m_1%5Cmathbf%7Bg%7D%20-%20%20%5Cmathbf%7BGRF%7D%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_1%20%3D%20I_1%5Cmathbf%7B%5Calpha%7D_1%20-%20%5Cmathbf%7Br%7D_%7Bcmp1%7D%5Ctimes%5Cmathbf%7BF%7D_1%20-%20%5Cmathbf%7Br%7D_%7BcmCOP%7D%5Ctimes%5Cmathbf%7BGRF%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20body%202%20(leg)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_2%20%20%3D%20m_2%5Cmathbf%7Ba%7D_2%20-%20%20m_2%5Cmathbf%7Bg%7D%20%2B%20%5Cmathbf%7BF%7D_1%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_2%20%3D%20I_2%5Cmathbf%7B%5Calpha%7D_2%20-%20%5Cmathbf%7Br%7D_%7Bcmp2%7D%5Ctimes%5Cmathbf%7BF%7D_2%20%2B%5Cmathbf%7Br%7D_%7Bcmd2%7D%5Ctimes%5Cmathbf%7BF%7D_%7B1%7D%20%2B%20%5Cmathbf%7BM%7D_1%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20For%20body%203%20(thigh)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20%5Cmathbf%7BF%7D_3%20%20%3D%20m_3%5Cmathbf%7Ba%7D_3%20-%20m_3%5Cmathbf%7Bg%7D%20%2B%20%5Cmathbf%7BF%7D_2%5C%5C%0A%20%20%20%20%5Cmathbf%7BM%7D_3%20%20%3D%20I_3%5Cmathbf%7B%5Calpha%7D_3%20-%20%5Cmathbf%7Br%7D_%7Bcmp3%7D%5Ctimes%5Cmathbf%7BF%7D_3%20%2B%20%5Cmathbf%7Br%7D_%7Bcmd3%7D%5Ctimes%5Cmathbf%7BF%7D_%7B2%7D%20%2B%20%5Cmathbf%7BM%7D_2%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%23%23%23%20Python%20function%20%60invdyn2d.py%60%0A%0A%20%20%20%20We%20could%20write%20a%20function%20that%20it%20would%20have%20as%20inputs%20the%20body-segment%20parameters%2C%20the%20kinematic%20data%2C%20and%20the%20distal%20joint%20force%20and%20moment%20of%20force%20and%20output%20the%20proximal%20joint%20force%20and%20moment%20of%20force.%3Cbr%3E%0A%20%20%20%20Then%2C%20we%20would%20call%20this%20function%20for%20each%20segment%2C%20starting%20with%20the%20segment%20that%20has%20a%20free%20extremity%20or%20that%20has%20the%20force%20and%20moment%20of%20force%20measured%20by%20some%20instrument%20(i%2Ce%2C%20use%20a%20force%20plate%20for%20the%20foot-ground%20interface).%3Cbr%3E%0A%20%20%20%20This%20function%20would%20be%20called%20in%20the%20following%20manner%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20%20%20%20%20Fp%2C%20Mp%20%3D%20invdyn2d(rcm%2C%20rd%2C%20rp%2C%20acm%2C%20alfa%2C%20mass%2C%20Icm%2C%20Fd%2C%20Md)%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20So%2C%20here%20is%20such%20function%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(mo%2C%20repo_file)%3A%0A%20%20%20%20mo.ui.code_editor(repo_file(%22functions%2Finvdyn2d.py%22).read_text()%2C%20language%3D%22python%22%2C%20disabled%3DTrue)%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%20inverse%20dynamics%20calculations%20are%20implemented%20in%20only%20two%20lines%20of%20code%20at%20the%20end%2C%20the%20first%20part%20of%20the%20code%20is%20the%20help%20on%20how%20to%20use%20the%20function.%20The%20help%20is%20long%20because%20it's%20supposed%20to%20be%20helpful%20%3A)%2C%20see%20the%20%5Bstyle%20guide%20for%20NumPy%2FSciPy%20documentation%5D(https%3A%2F%2Fnumpydoc.readthedocs.io%2Fen%2Flatest%2Fformat.html%23docstring-standard).%0A%0A%20%20%20%20The%20real%20problem%20is%20to%20measure%20or%20estimate%20the%20experimental%20variables%3A%20the%20body-segment%20parameters%2C%20the%20ground%20reaction%20forces%2C%20and%20the%20kinematics%20of%20each%20segment.%20For%20such%2C%20it%20is%20necessary%20some%20expensive%20equipments%2C%20but%20they%20are%20typical%20in%20a%20biomechanics%20laboratory%2C%20such%20the%20the%20%5BBMClab%5D(https%3A%2F%2Fbmclab.pesquisa.ufabc.edu.br).%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%20Experimental%20data%0A%0A%20%20%20%20Let's%20work%20with%20some%20data%20of%20kinematic%20position%20of%20the%20segments%20and%20ground%20reaction%20forces%20in%20order%20to%20compute%20the%20joint%20forces%20and%20moments%20of%20force.%3Cbr%3E%0A%20%20%20%20The%20data%20we%20will%20work%20are%20in%20fact%20from%20a%20computer%20simulation%20of%20running%20created%20by%20Ton%20van%20den%20Bogert.%20The%20nice%20thing%20about%20these%20data%20is%20that%20as%20a%20simulation%2C%20the%20true%20joint%20forces%20and%20moments%20of%20force%20are%20known%20and%20we%20will%20be%20able%20to%20compare%20our%20estimation%20with%20these%20true%20values.%3Cbr%3E%0A%20%20%20%20All%20the%20data%20can%20be%20downloaded%20from%20a%20page%20at%20the%20%5BISB%20website%5D(http%3A%2F%2Fisbweb.org%2Fdata%2Finvdyn%2Findex.html)%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(IFrame)%3A%0A%20%20%20%20IFrame('https%3A%2F%2Fisbweb.org%2Fdata%2Finvdyn%2Findex.html'%2C%20width%3D'100%25'%2C%20height%3D400)%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%20Load%20data%20file%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20repo_file)%3A%0A%20%20%20%20%23%20load%20file%20with%20ground%20reaction%20force%20data%0A%20%20%20%20grf%20%3D%20np.loadtxt(repo_file('data%2Fall.frc'))%20%23%20%5BFx%2C%20Fy%2C%20COPx%5D%0A%20%20%20%20%23%20load%20file%20with%20kinematic%20data%0A%20%20%20%20kin%20%3D%20np.loadtxt(repo_file('data%2Fall.kin'))%20%23%20%5BHip(x%2Cy)%2C%20knee(x%2Cy)%2C%20ankle(x%2Cy)%2C%20toe(x%2Cy)%5D%0A%20%20%20%20freq%20%3D%2010000%0A%20%20%20%20time%20%3D%20np.linspace(0%2C%20grf.shape%5B0%5D%2Ffreq%2C%20grf.shape%5B0%5D)%0A%20%20%20%20return%20freq%2C%20grf%2C%20kin%2C%20time%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%20Data%20filtering%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(freq%2C%20grf%2C%20kin%2C%20np)%3A%0A%20%20%20%20%23%20this%20is%20simulated%20data%20with%20no%20noise%2C%20filtering%20doesn't%20matter%0A%20%20%20%20if%20False%3A%0A%20%20%20%20%20%20%20%20%23%20filter%20data%0A%20%20%20%20%20%20%20%20from%20scipy.signal%20import%20butter%2C%20filtfilt%0A%20%20%20%20%20%20%20%20%23%20Butterworth%20filter%0A%20%20%20%20%20%20%20%20b%2C%20a%20%3D%20butter(2%2C%20(10%2F(freq%2F2)))%0A%20%20%20%20%20%20%20%20for%20col%20in%20np.arange(grf.shape%5B1%5D-1)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20grf%5B%3A%2C%20col%5D%20%20%3D%20filtfilt(b%2C%20a%2C%20grf%5B%3A%2C%20col%5D)%0A%20%20%20%20%20%20%20%20b%2C%20a%20%3D%20butter(2%2C%20(10%2F(freq%2F2)))%0A%20%20%20%20%20%20%20%20for%20col%20in%20np.arange(kin.shape%5B1%5D)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20kin%5B%3A%2C%20col%5D%20%3D%20filtfilt(b%2C%20a%2C%20kin%5B%3A%2C%20col%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**Exercise%202.**%20Why%20filter%20marker%20positions%20before%20differentiating%20twice%3F%20Would%20identical%20filtering%20of%20positions%20and%20forces%20automatically%20remove%20all%20inverse-dynamics%20errors%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Worked%20solution%20%E2%80%94%20Exercise%202%0A%0A%20%20%20%20Differentiation%20amplifies%20high-frequency%20position%20noise%2C%20especially%20in%20acceleration.%20Consistent%20filtering%20helps%20avoid%20mismatched%20frequency%20content%2C%20but%20does%20not%20correct%20marker%20placement%2C%20segment%20parameters%2C%20synchronization%20or%20out-of-plane%20motion.%0A%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%20Data%20selection%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(freq%2C%20grf%2C%20kin%2C%20time)%3A%0A%20%20%20%20time_1%20%3D%20time%5B3001%20-%20int(freq%20%2F%2040)%3A-int(freq%20%2F%2020)%5D%0A%20%20%20%20grf_1%20%3D%20grf%5B3001%20-%20int(freq%20%2F%2040)%3A-int(freq%20%2F%2020)%2C%20%3A%5D%0A%20%20%20%20kin_1%20%3D%20kin%5B3001%20-%20int(freq%20%2F%2040)%3A-int(freq%20%2F%2020)%2C%20%3A%5D%0A%20%20%20%20return%20grf_1%2C%20kin_1%2C%20time_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%20%23%23%23%20Plot%20file%20data%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(grf_1%2C%20kin_1%2C%20plt%2C%20time_1)%3A%0A%20%20%20%20(_hfig%2C%20hax)%20%3D%20plt.subplots(2%2C%202%2C%20sharex%3DTrue%2C%20squeeze%3DTrue%2C%20figsize%3D(9%2C%205))%0A%20%20%20%20hax%5B0%2C%200%5D.plot(time_1%2C%20grf_1%5B%3A%2C%20%5B0%2C%201%5D%5D%2C%20linewidth%3D2)%0A%20%20%20%20hax%5B0%2C%200%5D.legend(('Fx'%2C%20'Fy')%2C%20frameon%3DFalse)%0A%20%20%20%20hax%5B0%2C%200%5D.set_ylabel('Force%20%5BN%5D')%0A%20%20%20%20hax%5B0%2C%201%5D.plot(time_1%2C%20grf_1%5B%3A%2C%202%5D%2C%20linewidth%3D2)%0A%20%20%20%20hax%5B0%2C%201%5D.legend(%5B'COPx'%5D%2C%20frameon%3DFalse)%0A%20%20%20%20hax%5B0%2C%201%5D.set_ylabel('Amplitude%20%5Bm%5D')%0A%20%20%20%20hax%5B1%2C%200%5D.plot(time_1%2C%20kin_1%5B%3A%2C%200%3A%3A2%5D%2C%20linewidth%3D2)%0A%20%20%20%20hax%5B1%2C%200%5D.legend(('Hip%20x'%2C%20'Knee%20x'%2C%20'Ankle%20x'%2C%20'Toe%20x')%2C%20frameon%3DFalse)%0A%20%20%20%20hax%5B1%2C%200%5D.set_ylabel('Amplitude%20%5Bm%5D')%0A%20%20%20%20hax%5B1%2C%201%5D.plot(time_1%2C%20kin_1%5B%3A%2C%201%3A%3A2%5D%2C%20linewidth%3D2)%0A%20%20%20%20hax%5B1%2C%201%5D.legend(('Hip%20y'%2C%20'Knee%20y'%2C%20'Ankle%20y'%2C%20'Toe%20y')%2C%20frameon%3DFalse)%0A%20%20%20%20hax%5B1%2C%201%5D.set_ylabel('Amplitude%20%5Bm%5D')%0A%20%20%20%20(hax%5B1%2C%200%5D.set_xlabel('Time%20%5Bs%5D')%2C%20hax%5B1%2C%201%5D.set_xlabel('Time%20%5Bs%5D'))%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20plt.show()%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%20Body-segment%20parameters%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%20body-segment%20parameters%20%5Bthigh%2C%20shank%2C%20foot%5D%0A%20%20%20%20mass%20%3D%20%5B6.85%2C%202.86%2C%201.00%5D%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23%20mass%20%5Bkg%5D%0A%20%20%20%20Icm%20%20%3D%20%5B0.145361267%2C%200.042996389%2C%200.0200%5D%20%23%20rotational%20inertia%20%5Bkgm2%5D%0A%20%20%20%20cmpr%20%3D%20%5B0.4323725%2C%200.4334975%2C%200.0%5D%20%20%20%20%20%20%20%20%23%20CM%20%5Bm%5D%20wrt.%20prox.%20joint%20%5Bfrac.%20segment%20len%5D%0A%20%20%20%20return%20Icm%2C%20cmpr%2C%20mass%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%20Kinematic%20calculations%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(cmpr%2C%20freq%2C%20kin_1%2C%20np)%3A%0A%20%20%20%20rcm%20%3D%20np.hstack((kin_1%5B%3A%2C%20%5B0%2C%201%5D%5D%20%2B%20cmpr%5B0%5D%20*%20(kin_1%5B%3A%2C%20%5B2%2C%203%5D%5D%20-%20kin_1%5B%3A%2C%20%5B0%2C%201%5D%5D)%2C%20kin_1%5B%3A%2C%20%5B2%2C%203%5D%5D%20%2B%20cmpr%5B1%5D%20*%20(kin_1%5B%3A%2C%20%5B4%2C%205%5D%5D%20-%20kin_1%5B%3A%2C%20%5B2%2C%203%5D%5D)%2C%20kin_1%5B%3A%2C%20%5B4%2C%205%5D%5D%20%2B%20cmpr%5B2%5D%20*%20(kin_1%5B%3A%2C%20%5B6%2C%207%5D%5D%20-%20kin_1%5B%3A%2C%20%5B4%2C%205%5D%5D)))%0A%20%20%20%20acm%20%3D%20np.diff(rcm%2C%20n%3D2%2C%20axis%3D0)%20*%20freq%20*%20freq%0A%20%20%20%20acm%20%3D%20np.vstack((acm%2C%20acm%5B-1%2C%20%3A%5D%2C%20acm%5B-1%2C%20%3A%5D))%0A%20%20%20%20ang%20%3D%20np.vstack((np.arctan2(kin_1%5B%3A%2C%201%5D%20-%20kin_1%5B%3A%2C%203%5D%2C%20kin_1%5B%3A%2C%200%5D%20-%20kin_1%5B%3A%2C%202%5D)%2C%20np.arctan2(kin_1%5B%3A%2C%203%5D%20-%20kin_1%5B%3A%2C%205%5D%2C%20kin_1%5B%3A%2C%202%5D%20-%20kin_1%5B%3A%2C%204%5D)%2C%20np.arctan2(kin_1%5B%3A%2C%205%5D%20-%20kin_1%5B%3A%2C%207%5D%2C%20kin_1%5B%3A%2C%204%5D%20-%20kin_1%5B%3A%2C%206%5D))).T%0A%20%20%20%20angj%20%3D%20np.vstack((-(ang%5B%3A%2C%200%5D%20-%20ang%5B%3A%2C%201%5D)%2C%20np.unwrap(ang%5B%3A%2C%201%5D%20-%20ang%5B%3A%2C%202%5D%20%2B%20np.pi%20%2F%202))).T%20*%20180%20%2F%20np.pi%0A%20%20%20%20aang%20%3D%20np.diff(ang%2C%20n%3D2%2C%20axis%3D0)%20*%20freq%20*%20freq%0A%20%20%20%20aang%20%3D%20np.vstack((aang%2C%20aang%5B-1%2C%20%3A%5D%2C%20aang%5B-1%2C%20%3A%5D))%0A%20%20%20%20return%20aang%2C%20acm%2C%20angj%2C%20rcm%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%20Plot%20joint%20angles%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(angj%2C%20plt%2C%20time_1)%3A%0A%20%20%20%20(_hfig%2C%20(hax1%2C%20hax2))%20%3D%20plt.subplots(2%2C%201%2C%20sharex%3DTrue%2C%20squeeze%3DTrue%2C%20figsize%3D(10%2C%205))%0A%20%20%20%20hax1.plot(time_1%2C%20angj%5B%3A%2C%200%5D%2C%20linewidth%3D2%2C%20label%3D'Knee')%0A%20%20%20%20(hax1.legend(frameon%3DFalse%2C%20loc%3D'upper%20left')%2C%20hax1.grid())%0A%20%20%20%20hax2.plot(time_1%2C%20angj%5B%3A%2C%201%5D%2C%20linewidth%3D2%2C%20label%3D'Ankle')%0A%20%20%20%20(hax2.legend(frameon%3DFalse%2C%20loc%3D'upper%20left')%2C%20hax2.grid())%0A%20%20%20%20hax1.set_ylabel('Joint%20angle%24%5B%5Eo%5D%24')%0A%20%20%20%20hax2.set_ylabel('Joint%20angle%24%5B%5Eo%5D%24')%0A%20%20%20%20hax2.set_xlabel('Time%20%5Bs%5D')%0A%20%20%20%20plt.tight_layout()%0A%20%20%20%20plt.show()%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%20Inverse%20dynamics%20calculations%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Icm%2C%20aang%2C%20acm%2C%20grf_1%2C%20kin_1%2C%20mass%2C%20np%2C%20rcm)%3A%0A%20%20%20%20from%20invdyn2d%20import%20invdyn2d%0A%20%20%20%20(Fa%2C%20Ma)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(4%2C%205)%5D%2C%20grf_1%5B%3A%2C%20(2%2C%202)%5D%20*%20%5B1%2C%200%5D%2C%20kin_1%5B%3A%2C%20(4%2C%205)%5D%2C%20acm%5B%3A%2C%20(4%2C%205)%5D%2C%20aang%5B%3A%2C%202%5D%2C%20mass%5B2%5D%2C%20Icm%5B2%5D%2C%20grf_1%5B%3A%2C%20(0%2C%201)%5D%2C%200)%0A%20%20%20%20(Fk%2C%20Mk)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(2%2C%203)%5D%2C%20kin_1%5B%3A%2C%20(4%2C%205)%5D%2C%20kin_1%5B%3A%2C%20(2%2C%203)%5D%2C%20acm%5B%3A%2C%20(2%2C%203)%5D%2C%20aang%5B%3A%2C%201%5D%2C%20mass%5B1%5D%2C%20Icm%5B1%5D%2C%20-Fa%2C%20-Ma)%0A%20%20%20%20(Fh%2C%20Mh)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(0%2C%201)%5D%2C%20kin_1%5B%3A%2C%20(2%2C%203)%5D%2C%20kin_1%5B%3A%2C%20(0%2C%201)%5D%2C%20acm%5B%3A%2C%20(0%2C%201)%5D%2C%20aang%5B%3A%2C%200%5D%2C%20mass%5B0%5D%2C%20Icm%5B0%5D%2C%20-Fk%2C%20-Mk)%0A%20%20%20%20Fam%20%3D%20np.sqrt(np.sum(np.abs(Fa)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20Fkm%20%3D%20np.sqrt(np.sum(np.abs(Fk)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20Fhm%20%3D%20np.sqrt(np.sum(np.abs(Fh)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20return%20Fam%2C%20Fhm%2C%20Fkm%2C%20Ma%2C%20Mh%2C%20Mk%2C%20invdyn2d%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%20Load%20files%20with%20true%20joint%20forces%20and%20moments%20of%20force%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(freq%2C%20np%2C%20repo_file)%3A%0A%20%20%20%20%23%20load%20file%20with%20true%20joint%20forces%20and%20moments%20of%20force%0A%20%20%20%20forces%20%20%3D%20np.loadtxt(repo_file('data%2Fall.fmg'))%20%23%20%5BHip%2C%20knee%2C%20ankle%5D%0A%20%20%20%20moments%20%3D%20np.loadtxt(repo_file('data%2Fall.mom'))%20%23%20%5BHip%2C%20knee%2C%20ankle%5D%0A%20%20%20%20%23heel%20strike%20occurs%20at%20sample%203001%0A%20%20%20%20forces%20%20%3D%20forces%5B3001-int(freq%2F40)%3A-int(freq%2F20)%2C%20%3A%5D%0A%20%20%20%20moments%20%3D%20moments%5B3001-int(freq%2F40)%3A-int(freq%2F20)%2C%20%3A%5D%0A%20%20%20%20return%20forces%2C%20moments%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%20Plot%20calculated%20variables%20and%20their%20true%20values%0A%0A%20%20%20%20Let's%20plot%20these%20data%20but%20because%20later%20we%20will%20need%20to%20plot%20similar%20plots%2C%20let's%20create%20a%20function%20for%20the%20plot%20to%20avoid%20repetition%20of%20code%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Fam%2C%20Fhm%2C%20Fkm%2C%20Ma%2C%20Mh%2C%20Mk%2C%20forces%2C%20moments%2C%20plt%2C%20time_1)%3A%0A%20%20%20%20def%20plotdata(time%2C%20Fh%2C%20Fk%2C%20Fa%2C%20Mh%2C%20Mk%2C%20Ma%2C%20forces%2C%20moments%2C%20stitle)%3A%0A%20%20%20%20%20%20%20%20(_hfig%2C%20hax)%20%3D%20plt.subplots(3%2C%202%2C%20sharex%3DTrue%2C%20squeeze%3DTrue%2C%20figsize%3D(11%2C%206))%0A%20%20%20%20%20%20%20%20(hax%5B0%2C%200%5D.plot(time%2C%20Fh%2C%20label%3D'invdyn')%2C%20hax%5B0%2C%200%5D.set_title('Hip'))%0A%20%20%20%20%20%20%20%20(hax%5B1%2C%200%5D.plot(time%2C%20Fk)%2C%20hax%5B1%2C%200%5D.set_title('Knee'))%0A%20%20%20%20%20%20%20%20(hax%5B2%2C%200%5D.plot(time%2C%20Fa)%2C%20hax%5B2%2C%200%5D.set_title('Ankle'))%0A%20%20%20%20%20%20%20%20hax%5B1%2C%200%5D.set_ylabel('Joint%20force%20%5BN%5D')%0A%20%20%20%20%20%20%20%20hax%5B2%2C%200%5D.set_xlabel('Time%20%5Bs%5D')%0A%20%20%20%20%20%20%20%20(hax%5B0%2C%201%5D.plot(time%2C%20Mh)%2C%20hax%5B0%2C%201%5D.set_title('Hip'))%0A%20%20%20%20%20%20%20%20(hax%5B1%2C%201%5D.plot(time%2C%20Mk)%2C%20hax%5B1%2C%201%5D.set_title('Knee'))%0A%20%20%20%20%20%20%20%20(hax%5B2%2C%201%5D.plot(time%2C%20Ma)%2C%20hax%5B2%2C%201%5D.set_title('Ankle'))%0A%20%20%20%20%20%20%20%20hax%5B1%2C%201%5D.set_ylabel('Moment%20of%20Force%20%5BNm%5D')%0A%20%20%20%20%20%20%20%20hax%5B2%2C%201%5D.set_xlabel('Time%20%5Bs%5D')%0A%20%20%20%20%20%20%20%20hax%5B0%2C%200%5D.plot(time%2C%20forces%5B%3A%2C%200%5D%2C%20'r--'%2C%20label%3D'True')%0A%20%20%20%20%20%20%20%20hax%5B0%2C%200%5D.legend(frameon%3DFalse)%0A%20%20%20%20%20%20%20%20hax%5B1%2C%200%5D.plot(time%2C%20forces%5B%3A%2C%201%5D%2C%20'r--')%0A%20%20%20%20%20%20%20%20hax%5B2%2C%200%5D.plot(time%2C%20forces%5B%3A%2C%202%5D%2C%20'r--')%0A%20%20%20%20%20%20%20%20hax%5B0%2C%201%5D.plot(time%2C%20moments%5B%3A%2C%200%5D%2C%20'r--')%0A%20%20%20%20%20%20%20%20hax%5B1%2C%201%5D.plot(time%2C%20moments%5B%3A%2C%201%5D%2C%20'r--')%0A%20%20%20%20%20%20%20%20hax%5B2%2C%201%5D.plot(time%2C%20moments%5B%3A%2C%202%5D%2C%20'r--')%0A%20%20%20%20%20%20%20%20plt.suptitle(stitle%2C%20fontsize%3D16)%0A%20%20%20%20%20%20%20%20for%20x%20in%20hax.flat%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20x.locator_params(nbins%3D5)%0A%20%20%20%20%20%20%20%20%20%20%20%20x.grid()%0A%20%20%20%20%20%20%20%20plt.show()%0A%20%20%20%20plotdata(time_1%2C%20Fhm%2C%20Fkm%2C%20Fam%2C%20Mh%2C%20Mk%2C%20Ma%2C%20forces%2C%20moments%2C%20'Inverse%20dynamics%3A%20estimated%20versus%20true%20values')%0A%20%20%20%20return%20(plotdata%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%20results%20are%20very%20similar%3B%20only%20a%20small%20part%20of%20the%20moments%20of%20force%20is%20different%20because%20of%20some%20noise.%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.**%20A%202%20kg%20segment%20has%20upward%20centre-of-mass%20acceleration%203%20m%2Fs%C2%B2%20and%20no%20distal%20force.%20Find%20its%20proximal%20vertical%20force.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Worked%20solution%20%E2%80%94%20Exercise%203%0A%0A%20%20%20%20%24F_%7Bprox%7D-mg%3Dma_y%24%20gives%20%24F_%7Bprox%7D%3D2(9.81%2B3)%3D25.62%24%20N%20upward.%20Quasi-static%20balance%20would%20give%2019.62%20N%2C%20missing%206%20N%20of%20inertial%20force.%0A%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%20Contribution%20of%20each%20term%20to%20the%20joint%20force%20and%20moment%20of%20force%0A%0A%20%20%20%20Let's%20see%20what%20happens%20with%20the%20joint%20forces%20and%20moments%20of%20force%20when%20we%20neglect%20the%20contribution%20of%20some%20terms%20in%20the%20inverse%20dynamics%20analysis%20of%20these%20data.%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%20Quasi-static%20analysis%0A%20%20%20%20Consider%20the%20case%20where%20the%20segment%20acceleration%20is%20neglected%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%20Icm%2C%0A%20%20%20%20aang%2C%0A%20%20%20%20acm%2C%0A%20%20%20%20forces%2C%0A%20%20%20%20grf_1%2C%0A%20%20%20%20invdyn2d%2C%0A%20%20%20%20kin_1%2C%0A%20%20%20%20mass%2C%0A%20%20%20%20moments%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plotdata%2C%0A%20%20%20%20rcm%2C%0A%20%20%20%20time_1%2C%0A)%3A%0A%20%20%20%20(Fast%2C%20Mast)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(4%2C%205)%5D%2C%20grf_1%5B%3A%2C%20(2%2C%202)%5D%20*%20%5B1%2C%200%5D%2C%20kin_1%5B%3A%2C%20(4%2C%205)%5D%2C%20acm%5B%3A%2C%20(4%2C%205)%5D%20*%200%2C%20aang%5B%3A%2C%202%5D%20*%200%2C%20mass%5B2%5D%2C%20Icm%5B2%5D%2C%20grf_1%5B%3A%2C%20(0%2C%201)%5D%2C%200)%0A%20%20%20%20(Fkst%2C%20Mkst)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(2%2C%203)%5D%2C%20kin_1%5B%3A%2C%20(4%2C%205)%5D%2C%20kin_1%5B%3A%2C%20(2%2C%203)%5D%2C%20acm%5B%3A%2C%20(2%2C%203)%5D%20*%200%2C%20aang%5B%3A%2C%201%5D%20*%200%2C%20mass%5B1%5D%2C%20Icm%5B1%5D%2C%20-Fast%2C%20-Mast)%0A%20%20%20%20(Fhst%2C%20Mhst)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(0%2C%201)%5D%2C%20kin_1%5B%3A%2C%20(2%2C%203)%5D%2C%20kin_1%5B%3A%2C%20(0%2C%201)%5D%2C%20acm%5B%3A%2C%20(0%2C%201)%5D%20*%200%2C%20aang%5B%3A%2C%200%5D%20*%200%2C%20mass%5B0%5D%2C%20Icm%5B0%5D%2C%20-Fkst%2C%20-Mkst)%0A%20%20%20%20Fastm%20%3D%20np.sqrt(np.sum(np.abs(Fast)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20Fkstm%20%3D%20np.sqrt(np.sum(np.abs(Fkst)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20Fhstm%20%3D%20np.sqrt(np.sum(np.abs(Fhst)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20plotdata(time_1%2C%20Fhstm%2C%20Fkstm%2C%20Fastm%2C%20Mhst%2C%20Mkst%2C%20Mast%2C%20forces%2C%20moments%2C%20'Inverse%20dynamics%3A%20quasis-static%20approach%20versus%20true%20values')%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%20This%20is%20not%20a%20pure%20static%20analysis%20because%20part%20of%20the%20ground%20reaction%20forces%20still%20reflects%20the%20body%20accelerations%20(were%20the%20body%20completely%20static%2C%20the%20ground%20reaction%20force%20should%20be%20equal%20to%20the%20body%20weight%20in%20magnitude).%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%20Neglecting%20the%20acceleration%20and%20mass%20(weight)%20of%20the%20segments%0A%0A%20%20%20%20Consider%20the%20case%20where%20besides%20the%20acceleration%2C%20the%20body-segment%20parameters%20are%20also%20neglected.%3Cbr%3E%0A%20%20%20%20This%20means%20that%20the%20joint%20loads%20are%20due%20only%20to%20the%20ground%20reaction%20forces%20(which%20implicitly%20include%20contributions%20due%20to%20the%20acceleration%20and%20the%20body-segment%20weights).%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(%0A%20%20%20%20aang%2C%0A%20%20%20%20acm%2C%0A%20%20%20%20forces%2C%0A%20%20%20%20grf_1%2C%0A%20%20%20%20invdyn2d%2C%0A%20%20%20%20kin_1%2C%0A%20%20%20%20moments%2C%0A%20%20%20%20np%2C%0A%20%20%20%20plotdata%2C%0A%20%20%20%20rcm%2C%0A%20%20%20%20time_1%2C%0A)%3A%0A%20%20%20%20(Fagrf%2C%20Magrf)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(4%2C%205)%5D%2C%20grf_1%5B%3A%2C%20(2%2C%202)%5D%20*%20%5B1%2C%200%5D%2C%20kin_1%5B%3A%2C%20(4%2C%205)%5D%2C%20acm%5B%3A%2C%20(4%2C%205)%5D%20*%200%2C%20aang%5B%3A%2C%202%5D%20*%200%2C%200%2C%200%2C%20grf_1%5B%3A%2C%20(0%2C%201)%5D%2C%200)%0A%20%20%20%20(Fkgrf%2C%20Mkgrf)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(2%2C%203)%5D%2C%20kin_1%5B%3A%2C%20(4%2C%205)%5D%2C%20kin_1%5B%3A%2C%20(2%2C%203)%5D%2C%20acm%5B%3A%2C%20(2%2C%203)%5D%20*%200%2C%20aang%5B%3A%2C%201%5D%20*%200%2C%200%2C%200%2C%20-Fagrf%2C%20-Magrf)%0A%20%20%20%20(Fhgrf%2C%20Mhgrf)%20%3D%20invdyn2d(rcm%5B%3A%2C%20(0%2C%201)%5D%2C%20kin_1%5B%3A%2C%20(2%2C%203)%5D%2C%20kin_1%5B%3A%2C%20(0%2C%201)%5D%2C%20acm%5B%3A%2C%20(0%2C%201)%5D%20*%200%2C%20aang%5B%3A%2C%200%5D%20*%200%2C%200%2C%200%2C%20-Fkgrf%2C%20-Mkgrf)%0A%20%20%20%20Fagrfm%20%3D%20np.sqrt(np.sum(np.abs(Fagrf)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20Fkgrfm%20%3D%20np.sqrt(np.sum(np.abs(Fkgrf)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20Fhgrfm%20%3D%20np.sqrt(np.sum(np.abs(Fhgrf)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20plotdata(time_1%2C%20Fhgrfm%2C%20Fkgrfm%2C%20Fagrfm%2C%20Mhgrf%2C%20Mkgrf%2C%20Magrf%2C%20forces%2C%20moments%2C%20'Inverse%20dynamics%3A%20ground-reaction-force%20approach%20versus%20true%20values')%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%20Neglecting%20all%20the%20accelerations%20and%20the%20weight%20of%20the%20segments%20means%20that%20the%20only%20external%20force%20that%20actuates%20on%20the%20system%20is%20the%20ground%20reaction%20force%2C%20which%20although%20is%20only%20actuating%20at%20the%20foot-ground%20interface%20it%20will%20be%20transmitted%20to%20the%20other%20segments%20through%20the%20joint%20forces.%20%20Because%20of%20that%2C%20the%20joint%20forces%20on%20the%20ankle%2C%20knee%2C%20and%20hip%20will%20simply%20be%20minus%20the%20ground%20reaction%20force.%20Note%20that%20the%20forces%20shown%20above%20for%20the%20three%20joints%20are%20the%20same%20and%20equal%20to%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20%5Csqrt%7BGRF_x%5E2%2BGRF_y%5E2%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20These%20simplifications%20also%20mean%20that%20the%20moments%20of%20force%20could%20have%20been%20simply%20calculated%20as%20the%20cross%20product%20between%20the%20vector%20position%20of%20the%20the%20COP%20in%20relation%20to%20the%20joint%20and%20the%20GRF%20vector%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%7D%0A%20%20%20%20%5Cmathbf%7BM_%7Ba%7D%7D%20%3D%20-%5Cmathbf%7Bcross%7D(%5Cmathbf%7BCOP%7D-%5Cmathbf%7Br_%7Ba%7D%7D%2C%5C%2C%5Cmathbf%7BGRF%7D)%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM_%7Bk%7D%7D%20%3D%20-%5Cmathbf%7Bcross%7D(%5Cmathbf%7BCOP%7D-%5Cmathbf%7Br_%7Bk%7D%7D%2C%5C%2C%5Cmathbf%7BGRF%7D)%20%5C%5C%0A%20%20%20%20%5Cmathbf%7BM_%7Bh%7D%7D%20%3D%20-%5Cmathbf%7Bcross%7D(%5Cmathbf%7BCOP%7D-%5Cmathbf%7Br_%7Bh%7D%7D%2C%5C%2C%5Cmathbf%7BGRF%7D)%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Where%20%24%5Cmathbf%7Br_%7Bi%7D%7D%5C%3B%24%20is%20the%20position%20vector%20of%20joint%20%24i%24.%0A%0A%20%20%20%20Let's%20calculate%20the%20variables%20in%20this%20way%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(forces%2C%20grf_1%2C%20kin_1%2C%20moments%2C%20np%2C%20plotdata%2C%20time_1)%3A%0A%20%20%20%20Fhgrfm2%20%3D%20Fkgrfm2%20%3D%20Fagrfm2%20%3D%20np.sqrt(np.sum(np.abs(-grf_1%5B%3A%2C%20(0%2C%201)%5D)%20**%202%2C%20axis%3D-1))%0A%20%20%20%20%23%20cross%20product%20of%202D%20vectors%20(its%20z%20component)%3B%20np.cross%20no%20longer%20accepts%202D%20vectors%0A%20%20%20%20_cross%20%3D%20lambda%20a%2C%20b%3A%20a%5B%3A%2C%200%5D%20*%20b%5B%3A%2C%201%5D%20-%20a%5B%3A%2C%201%5D%20*%20b%5B%3A%2C%200%5D%0A%20%20%20%20Magrf2%20%3D%20-_cross(grf_1%5B%3A%2C%20(2%2C%202)%5D%20*%20%5B1%2C%200%5D%20-%20kin_1%5B%3A%2C%20(4%2C%205)%5D%2C%20grf_1%5B%3A%2C%20(0%2C%201)%5D)%0A%20%20%20%20Mkgrf2%20%3D%20-_cross(grf_1%5B%3A%2C%20(2%2C%202)%5D%20*%20%5B1%2C%200%5D%20-%20kin_1%5B%3A%2C%20(2%2C%203)%5D%2C%20grf_1%5B%3A%2C%20(0%2C%201)%5D)%0A%20%20%20%20Mhgrf2%20%3D%20-_cross(grf_1%5B%3A%2C%20(2%2C%202)%5D%20*%20%5B1%2C%200%5D%20-%20kin_1%5B%3A%2C%20(0%2C%201)%5D%2C%20grf_1%5B%3A%2C%20(0%2C%201)%5D)%0A%20%20%20%20plotdata(time_1%2C%20Fhgrfm2%2C%20Fkgrfm2%2C%20Fagrfm2%2C%20Mhgrf2%2C%20Mkgrf2%2C%20Magrf2%2C%20forces%2C%20moments%2C%20'Inverse%20dynamics%3A%20ground-reaction-force%20approach%20versus%20true%20values%20II')%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%20WARNING%3A%20the%20calculated%20resultant%20joint%20force%20is%20not%20the%20actual%20joint%20reaction%20force!%0A%0A%20%20%20%20In%20the%20Newton-Euler%20equations%20based%20on%20the%20free%20body%20diagrams%20we%20represented%20the%20consequences%20of%20all%20possible%20muscle%20forces%20on%20a%20joint%20as%20a%20net%20muscle%20torque%20and%20all%20forces%20acting%20on%20a%20joint%20as%20a%20resultant%20joint%20reaction%20force.%20That%20is%2C%20all%20forces%20between%20segments%20were%20represented%20as%20a%20resultant%20force%20that%20doesn't%20generate%20torque%20and%20a%20moment%20of%20force%20that%20only%20generates%20torque.%3Cbr%3E%0A%20%20%20%20This%20is%20an%20important%20principle%20in%20mechanics%20of%20rigid%20bodies%20as%20we%20saw%20before.%3Cbr%3E%0A%20%20%20%20However%2C%20this%20principle%20creates%20the%20unrealistic%20notion%20that%20the%20sum%20of%20forces%20is%20applied%20directly%20on%20the%20joint%20(which%20has%20no%20further%20implication%20for%20a%20rigid%20body)%2C%20but%20it%20is%20inaccurate%20for%20the%20understanding%20of%20the%20local%20effects%20on%20the%20joint.%20So%2C%20if%20we%20are%20trying%20to%20understand%20the%20stress%20on%20the%20joint%20or%20mechanisms%20of%20joint%20injury%2C%20the%20forces%20acting%20on%20the%20joint%20and%20on%20the%20rest%20of%20the%20segment%20must%20be%20considered%20individually.%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%20Conclusion%0A%0A%20%20%20%20For%20these%20data%20set%20of%20'running'%20(remember%20this%20is%20simulated%20data)%2C%20in%20the%20estimation%20of%20the%20forces%20and%20moments%20of%20force%20at%20the%20hip%2C%20knee%2C%20and%20ankle%20joints%20in%20a%20two-dimensional%20analysis%2C%20to%20not%20consider%20the%20segment%20acceleration%20and%2For%20the%20mass%20of%20the%20segments%20had%20no%20effect%20on%20the%20ankle%20variables%2C%20a%20small%20effect%20on%20the%20knee%2C%20and%20a%20large%20effect%20on%20the%20hip.%3Cbr%3E%0A%20%20%20%20This%20is%20not%20surprising%3B%20during%20the%20support%20phase%2C%20ankle%20and%20knee%20have%20small%20movements%20and%20the%20mass%20of%20the%20segments%20only%20start%20to%20have%20a%20significant%20contribution%20for%20more%20proximal%20and%20heavy%20segments%20such%20as%20the%20thigh.%0A%0A%20%20%20%20Don't%20get%20disappointed%20thinking%20that%20all%20this%20work%20for%20drawing%20the%20complete%20FBDs%20and%20their%20correspondent%20equations%20was%20a%20waste%20of%20time.%3Cbr%3E%0A%20%20%20%20Nowadays%2C%20the%20state%20of%20the%20art%20and%20the%20demand%20for%20higher%20accuracy%20in%20biomechanics%20is%20such%20that%20such%20simplifications%20are%20usually%20not%20accepted.%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%20Checkpoint%20questions%0A%0A%20%20%20%201.%20What%20measurements%20distinguish%20inverse%20from%20forward%20dynamics%3F%0A%20%20%20%202.%20Why%20start%20the%20recursion%20with%20the%20foot%3F%0A%20%20%20%203.%20Can%20the%20net%20knee%20moment%20determine%20each%20muscle%20force%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Checkpoint%20answers%0A%0A%20%20%20%201.%20Inverse%20dynamics%20uses%20measured%20motion%20and%20external%20forces%20to%20estimate%20net%20joint%20forces%20and%20moments.%202.%20Its%20external%20ground%20interaction%20is%20measured%2C%20supplying%20the%20distal%20boundary.%203.%20No%3B%20multiple%20muscles%20and%20passive%20structures%20can%20produce%20the%20same%20resultant%20moment.%0A%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.%20Search%20the%20Internet%20for%20actual%20experimental%20data%20from%20a%20gait%20analysis%20of%20a%20runner%20and%20compare%20with%20the%20simulated%20data%20used%20in%20this%20notebook.%0A%20%20%20%202.%20Collect%20or%20search%20for%20some%20experimental%20data%20from%20a%20movement%20analysis%20and%20perform%20inverse%20dynamics%20to%20determine%20joint%20forces%20and%20torques.%0A%20%20%20%203.%20Imagine%20that%20you%20have%20to%20perform%20a%20similar%20analysis%20but%20of%20the%20upper%20limb%20during%20throwing%20a%20ball.%20What%20would%20have%20to%20change%20in%20the%20approach%20described%20in%20this%20notebook%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%20Final%20answers%20to%20the%20problems%0A%0A%20%20%20%201.%20There%20is%20no%20unique%20numerical%20answer%20for%20a%20dataset%20chosen%20by%20the%20learner.%20A%20valid%20comparison%20reports%20speed%2C%20cycle%20events%2C%20joint-angle%20conventions%2C%20force%20normalization%2C%20filtering%20and%20uncertainty%3B%20running%20includes%20flight%20and%20generally%20different%20loading%20and%20timing%20from%20the%20supplied%20walking%20simulation.%0A%20%20%20%202.%20A%20valid%20result%20consists%20of%20synchronized%20kinematics%20and%20external%20forces%2C%20segment%20parameters%2C%20signed%20proximal%20forces%2Fmoments%2C%20and%20residual%20or%20validation%20checks.%20Numerical%20outputs%20depend%20on%20the%20selected%20measurements.%20A%20motion-only%20dataset%20does%20not%20identify%20net%20joint%20forces%20without%20external-force%20information%20or%20additional%20assumptions.%0A%20%20%20%203.%20Replace%20lower-limb%20segments%20and%20inertial%20parameters%20with%20upper-limb%20ones%2C%20include%20the%20ball%E2%80%99s%20interaction%20and%20release%20boundary%2C%20measure%20external%20loads%2C%20and%20usually%20use%203D%20rotational%20dynamics.%20A%20planar%20gait%20model%20is%20inadequate%20when%20the%20throwing%20motion%20leaves%20its%20measurement%20plane.%0A%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%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%20Go%20deeper%0A%0A%20%20%20%20-%20%5BGait%20Analysis%20on%20Wikipedia%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGait_analysis)%0A%20%20%20%20-%20%5BGait%20analysis%3A%20clinical%20facts%5D(https%3A%2F%2Fpubmed.ncbi.nlm.nih.gov%2F27618499)%0A%20%20%20%20-%20%5BGait%20Analysis%20Methods%3A%20An%20Overview%20of%20Wearable%20and%20Non-Wearable%20Systems%2C%20Highlighting%20Clinical%20Applications%5D(https%3A%2F%2Fwww.ncbi.nlm.nih.gov%2Fpmc%2Farticles%2FPMC3958266%2F)%0A%20%20%20%20-%20%5BAvalia%C3%A7%C3%A3o%20Biomec%C3%A2nica%20da%20Corrida%20no%20BMClab%20(in%20Portuguese)%5D(https%3A%2F%2Fbmclab.pesquisa.ufabc.edu.br%2Fservicos%2Frba-2%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%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20-%20Understanding%20%26%20Analyzing%20Gait%20For%20The%20Clinician%20-%20series%3A%20%5BIntroduction%5D(https%3A%2F%2Fyoutu.be%2Fx1JoaGgyKX0)%2C%20%5BPatient%20Assessment%5D(https%3A%2F%2Fyoutu.be%2FZ0QNkLshQUk)%2C%20%5BIntro%20To%20Computer-Based%203-D%20Analysis%5D(https%3A%2F%2Fyoutu.be%2Fg0OcCLTQM_Y)%2C%20%5BBasic%20Musculoskeletal%20Biomechanics%5D(https%3A%2F%2Fyoutu.be%2FKsdrmyxOyxM)%2C%20%5BThe%20Gait%20Cycle%5D(https%3A%2F%2Fyoutu.be%2F96nLX6sm9Yw)%0A%20%20%20%20-%20%5BHow%20to%20benefit%20from%20a%20Gait%20Analysis%20%7C%20Runners%20Need%5D(https%3A%2F%2Fyoutu.be%2FrxkX7qGtIEI)%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-%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%0A%20%20%20%20-%20Winter%20DA%20(2009)%20%5BBiomechanics%20and%20motor%20control%20of%20human%20movement%5D(https%3A%2F%2Fbooks.google.com.br%2Fbooks%3Fid%3D_bFHL08IWfwC).%204%20ed.%20Hoboken%2C%20EUA%3A%20Wiley.%0A%0A%20%20%20%20-%20Zajac%20FE%2C%20Gordon%20ME%20(1989)%20%5BDetermining%20muscle's%20force%20and%20action%20in%20multi-articular%20movement%5D(https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Frefs%2Fzajac89.pdf).%20Exercise%20and%20Sport%20Sciences%20Reviews%2C%2017%2C%20187-230.%0A%0A%20%20%20%20-%20Zatsiorsky%20VM%20(2002)%20%5BKinetics%20of%20human%20motion%5D(https%3A%2F%2Fbooks.google.com.br%2Fbooks%3Fid%3Dwp3zt7oF8a0C%26lpg%3DPA571%26ots%3DKjc17DAl19%26dq%3DZATSIORSKY%252C%2520Vladimir%2520M.%2520Kinetics%2520of%2520human%2520motion%26hl%3Dpt-BR%26pg%3DPP1%23v%3Donepage%26q%26f%3Dfalse).%20Champaign%2C%20IL%3A%20Human%20Kinetics.%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
84a6930fd368f22e0d767f3697f696b0