%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%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%20The%20minimum%20jerk%20hypothesis%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%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%22Whatever%20its%20physiological%20underpinnings%2C%20the%20real%20strength%20of%20the%20minimum-jerk%20criterion%20function%2C%20or%20indeed%20any%20other%20criterion%20function%2C%20is%20its%20use%20as%20an%20organizing%20principle.%20The%20use%20of%20variational%20principles%20is%20common%20in%20physics%20and%20engineering.%20They%20are%20not%20presented%20as%20the%20cause%20of%20the%20behavior%20they%20describe%20but%20rather%20as%20a%20distillation%20of%20its%20essence.%22%3C%2Fi%3E%20%26nbsp%3B%20%3Cb%3EHogan%3C%2Fb%3E%20(1984)%3C%2Fdiv%3E%3C%2Fcenter%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%20How%20to%20use%20this%20guide%0A%0A%20%20%20%20Watch%20a%20hand%20reach%20for%20a%20cup.%20It%20starts%20and%20stops%20smoothly%2C%20but%20what%20does%20%E2%80%9Csmooth%E2%80%9D%20mean%20mathematically%3F%20Here%20we%20minimize%20squared%20jerk%2C%20the%20third%20derivative%20of%20position%2C%20under%20specified%20endpoint%20conditions.%20You%20will%20derive%20the%20polynomial%20symbolically%20and%20inspect%20its%20derivatives%20numerically.%0A%0A%20%20%20%20You%20need%20differentiation%2C%20integrals%20and%20simultaneous%20equations.%20Use%20the%20Exercises%20to%20check%20the%20boundary%20conditions%20and%20time%20scaling%20before%20opening%20their%20worked%20solutions.%20The%20independent%20Problems%20ask%20what%20the%20model%20predicts%20and%20what%20evidence%20would%20distinguish%20it%20from%20other%20models.%0A%0A%20%20%20%20**Opening%20challenge.**%20If%20the%20same%20reach%20takes%20half%20as%20long%2C%20predict%20the%20changes%20in%20peak%20velocity%2C%20acceleration%20and%20jerk.%20Would%20a%20faster%20reach%20have%20the%20same%20minimum-jerk%20cost%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%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%20%23%20'%25matplotlib%20inline'%20command%20supported%20automatically%20in%20marimo%0A%20%20%20%20import%20matplotlib.pyplot%20as%20plt%0A%20%20%20%20import%20seaborn%20as%20sns%0A%20%20%20%20from%20IPython.display%20import%20display%2C%20Math%0A%20%20%20%20from%20sympy%20import%20symbols%2C%20Matrix%2C%20latex%2C%20Eq%2C%20collect%2C%20solve%2C%20diff%2C%20simplify%2C%20init_printing%0A%20%20%20%20from%20sympy.core%20import%20S%0A%20%20%20%20from%20sympy.utilities.lambdify%20import%20lambdify%0A%20%20%20%20init_printing()%0A%20%20%20%20sns.set_context('notebook'%2C%20rc%3D%7B%22lines.linewidth%22%3A%202%7D)%0A%20%20%20%20return%20(%0A%20%20%20%20%20%20%20%20Eq%2C%0A%20%20%20%20%20%20%20%20S%2C%0A%20%20%20%20%20%20%20%20collect%2C%0A%20%20%20%20%20%20%20%20diff%2C%0A%20%20%20%20%20%20%20%20display%2C%0A%20%20%20%20%20%20%20%20lambdify%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%20solve%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%20Development%0A%0A%20%20%20%20Hogan%20and%20Flash%20(1984%2C%201985)%2C%20based%20on%20observations%20of%20voluntary%20movements%20in%20primates%2C%20suggested%20that%20movements%20are%20performed%20(organized)%20with%20the%20smoothest%20trajectory%20possible.%20In%20this%20organizing%20principle%2C%20the%20endpoint%20trajectory%20is%20such%20that%20the%20mean%20squared-jerk%20across%20time%20of%20this%20movement%20is%20minimum.%0A%0A%20%20%20%20Jerk%20is%20the%20derivative%20of%20acceleration%20and%20the%20observation%20of%20the%20minimum-jerk%20trajectory%20is%20for%20the%20endpoint%20in%20the%20extracorporal%20coordinates%20(not%20for%20joint%20angles)%20and%20according%20to%20Flash%20and%20Hogan%20(1985)%2C%20the%20minimum-jerk%20trajectory%20of%20a%20planar%20movement%20is%20such%20that%20minimizes%20the%20following%20objective%20function%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Brcl%7D%0A%20%20%20%20C%20%3D%20%5Cfrac%7B1%7D%7B2%7D%20%5Cdisplaystyle%5Cint%5Climits_%7Bt_%7Bi%7D%7D%5E%7Bt_%7Bf%7D%7D%5C%3B%5Cleft%5B%5Cleft(%5Cdfrac%7Bd%5E%7B3%7Dx%7D%7Bdt%5E%7B3%7D%7D%5Cright)%5E2%2B%5Cleft(%5Cdfrac%7Bd%5E%7B3%7Dy%7D%7Bdt%5E%7B3%7D%7D%5Cright)%5E2%5Cright%5D%5C%3B%5Cmathrm%7Bd%7Dt%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Hogan%20(1984)%20found%20that%20the%20solution%20for%20this%20objective%20function%20is%20a%20fifth-order%20polynomial%20trajectory%20(see%20Shadmehr%20and%20Wise%20(2004)%20for%20a%20simpler%20proof)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Barray%7D%7Bl%20l%7D%0A%20%20%20%20x(t)%20%3D%20a_0%2Ba_1t%2Ba_2t%5E2%2Ba_3t%5E3%2Ba_4t%5E4%2Ba_5t%5E5%20%5C%5C%0A%20%20%20%20y(t)%20%3D%20b_0%2Bb_1t%2Bb_2t%5E2%2Bb_3t%5E3%2Bb_4t%5E4%2Bb_5t%5E5%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20With%20the%20following%20boundary%20conditions%20for%20%24x(t)%24%20and%20%24y(t)%24%3A%20initial%20and%20final%20positions%20are%20%24(x_i%2Cy_i)%24%20and%20%24(x_f%2Cy_f)%24%20and%20initial%20and%20final%20velocities%20and%20accelerations%20are%20zero.%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.**%20How%20many%20coefficients%20and%20endpoint%20constraints%20appear%20in%20one%20coordinate%3F%20Why%20is%20a%20cubic%20generally%20insufficient%3F%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%20There%20are%20six%20coefficients%2C%20fixed%20by%20position%2C%20velocity%20and%20acceleration%20at%20two%20endpoints.%20A%20cubic%20has%20only%20four%20coefficients%2C%20so%20it%20cannot%20generally%20satisfy%20six%20independent%20constraints.%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%20Finding%20the%20minimum%20jerk%20trajectory%0A%0A%20%20%20%20Let's%20employ%20%5BSympy%5D(http%3A%2F%2Fsympy.org%2Fen%2Findex.html)%20to%20find%20the%20solution%20for%20the%20minimum%20jerk%20trajectory%20using%20symbolic%20algebra.%3Cbr%3E%0A%20%20%20%20The%20equation%20for%20minimum%20jerk%20trajectory%20for%20x%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eq%2C%20S%2C%20display%2C%20symbols)%3A%0A%20%20%20%20%23%20symbolic%20variables%0A%20%20%20%20x%2C%20xi%2C%20xf%2C%20y%2C%20yi%2C%20yf%2C%20d%2C%20t%20%3D%20symbols('x%2C%20x_i%2C%20x_f%2C%20y%2C%20y_i%2C%20y_f%2C%20d%2C%20t')%0A%20%20%20%20a0%2C%20a1%2C%20a2%2C%20a3%2C%20a4%2C%20a5%20%3D%20symbols('a_0%3A6')%0A%20%20%20%20x%20%3D%20a0%20%2B%20a1*t%20%2B%20a2*t**2%20%2B%20a3*t**3%20%2B%20a4*t**4%20%2B%20a5*t**5%0A%20%20%20%20display(Eq(S('x(t)')%2C%20x))%0A%20%20%20%20return%20a0%2C%20a1%2C%20a2%2C%20a3%2C%20a4%2C%20a5%2C%20d%2C%20t%2C%20x%2C%20xf%2C%20xi%2C%20yf%2C%20yi%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%20Without%20loss%20of%20generality%2C%20consider%20%24t_i%3D0%24%20and%20let's%20use%20%24d%24%20for%20movement%20duration%20(%24d%3Dt_f%24).%3Cbr%3E%0A%20%20%20%20The%20system%20of%20equations%20with%20the%20boundary%20conditions%20for%20%24x%24%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eq%2C%20d%2C%20diff%2C%20display%2C%20t%2C%20x%2C%20xf%2C%20xi)%3A%0A%20%20%20%20%23%20define%20the%20system%20of%20equations%0A%20%20%20%20s%20%3D%20%5BEq(x.subs(t%2C%200)%2C%20xi)%2C%0A%20%20%20%20%20%20%20%20%20Eq(diff(x%2C%20t%2C%201).subs(t%2C%200)%2C%20%200)%2C%0A%20%20%20%20%20%20%20%20%20Eq(diff(x%2C%20t%2C%202).subs(t%2C%200)%2C%20%200)%2C%0A%20%20%20%20%20%20%20%20%20Eq(x.subs(t%2C%20d)%2C%20xf)%2C%0A%20%20%20%20%20%20%20%20%20Eq(diff(x%2C%20t%2C%201).subs(t%2C%20d)%2C%20%200)%2C%0A%20%20%20%20%20%20%20%20%20Eq(diff(x%2C%20t%2C%202).subs(t%2C%20d)%2C%20%200)%5D%0A%20%20%20%20%5Bdisplay(si)%20for%20si%20in%20s%5D%3B%0A%20%20%20%20return%20(s%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%20Which%20gives%20the%20following%20solution%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(a0%2C%20a1%2C%20a2%2C%20a3%2C%20a4%2C%20a5%2C%20display%2C%20s%2C%20solve)%3A%0A%20%20%20%20%23%20algebraically%20solve%20the%20system%20of%20equations%0A%20%20%20%20sol%20%3D%20solve(s%2C%20%5Ba0%2C%20a1%2C%20a2%2C%20a3%2C%20a4%2C%20a5%5D)%0A%20%20%20%20display(sol)%0A%20%20%20%20return%20(sol%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%20Substituting%20this%20solution%20in%20the%20fifth%20order%20polynomial%20trajectory%20equation%2C%20we%20have%20the%20actual%20displacement%20trajectories%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eq%2C%20S%2C%20collect%2C%20display%2C%20simplify%2C%20sol%2C%20x%2C%20xf%2C%20xi%2C%20yf%2C%20yi)%3A%0A%20%20%20%20%23%20substitute%20the%20equation%20parameters%20by%20the%20solution%0A%20%20%20%20x2%20%3D%20x.subs(sol)%0A%20%20%20%20x2%20%3D%20collect(simplify(x2%2C%20ratio%3D1)%2C%20xf-xi)%0A%20%20%20%20display(Eq(S('x(t)')%2C%20x2))%0A%20%20%20%20y2%20%3D%20x2.subs(%5B(xi%2C%20yi)%2C%20(xf%2C%20yf)%5D)%0A%20%20%20%20display(Eq(S('y(t)')%2C%20y2))%0A%20%20%20%20return%20(x2%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**Exercise%202.**%20For%20%24f(s)%3D10s%5E3-15s%5E4%2B6s%5E5%24%2C%20verify%20both%20endpoint%20positions%20and%20the%20endpoint%20velocities%20and%20accelerations.%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%20%24f(0)%3D0%24%20and%20%24f(1)%3D1%24.%20%24f%5Cprime(s)%3D30s%5E2(1-s)%5E2%24%20vanishes%20at%20both%20endpoints.%20Its%20derivative%2C%20%2460s-180s%5E2%2B120s%5E3%24%2C%20also%20vanishes%20at%200%20and%201.%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%20And%20for%20the%20velocity%2C%20acceleration%2C%20and%20jerk%20trajectories%20in%20x%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eq%2C%20S%2C%20display%2C%20t%2C%20x2)%3A%0A%20%20%20%20%23%20symbolic%20differentiation%0A%20%20%20%20vx%20%3D%20x2.diff(t%2C%201)%0A%20%20%20%20display(Eq(S('v_x(t)')%2C%20vx))%0A%20%20%20%20ax%20%3D%20x2.diff(t%2C%202)%0A%20%20%20%20display(Eq(S('a_x(t)')%2C%20ax))%0A%20%20%20%20jx%20%3D%20x2.diff(t%2C%203)%0A%20%20%20%20display(Eq(S('j_x(t)')%2C%20jx))%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%20Let's%20plot%20the%20minimum%20jerk%20trajectory%20for%20x%20and%20its%20velocity%2C%20acceleration%2C%20and%20jerk%20considering%20%24x_i%3D0%2Cx_f%3D1%2Cd%3D1%24%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(d%2C%20diff%2C%20lambdify%2C%20np%2C%20plt%2C%20t%2C%20x2%2C%20xf%2C%20xi)%3A%0A%20%20%20%20x3%20%3D%20x2.subs(%5B(xi%2C%200)%2C%20(xf%2C%201)%2C%20(d%2C%201)%5D)%0A%20%20%20%20xfu%20%3D%20lambdify(t%2C%20diff(x3%2C%20t%2C%200)%2C%20'numpy')%0A%20%20%20%20vfu%20%3D%20lambdify(t%2C%20diff(x3%2C%20t%2C%201)%2C%20'numpy')%0A%20%20%20%20afu%20%3D%20lambdify(t%2C%20diff(x3%2C%20t%2C%202)%2C%20'numpy')%0A%20%20%20%20jfu%20%3D%20lambdify(t%2C%20diff(x3%2C%20t%2C%203)%2C%20'numpy')%0A%20%20%20%20_ts%20%3D%20np.arange(0%2C%201.01%2C%200.01)%0A%20%20%20%20(_fig%2C%20_axs)%20%3D%20plt.subplots(1%2C%204%2C%20figsize%3D(10%2C%204)%2C%20sharex%3DTrue)%0A%20%20%20%20_axs%5B0%5D.plot(_ts%2C%20xfu(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B0%5D.set_title('Displacement%20%5B%24%5C%5Cmathrm%7Bm%7D%24%5D')%0A%20%20%20%20_axs%5B1%5D.plot(_ts%2C%20vfu(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B1%5D.set_title('Velocity%20%5B%24%5C%5Cmathrm%7Bm%2Fs%7D%24%5D')%0A%20%20%20%20_axs%5B2%5D.plot(_ts%2C%20afu(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B2%5D.set_title('Acceleration%20%5B%24%5C%5Cmathrm%7Bm%2Fs%5E2%7D%24%5D')%0A%20%20%20%20_axs%5B3%5D.plot(_ts%2C%20jfu(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B3%5D.set_title('Jerk%20%5B%24%5C%5Cmathrm%7Bm%2Fs%5E3%7D%24%5D')%0A%20%20%20%20for%20_axi%20in%20_axs%3A%0A%20%20%20%20%20%20%20%20_axi.set_xlabel('Time%20%5Bs%5D'%2C%20fontsize%3D12)%0A%20%20%20%20%20%20%20%20_axi.grid(True)%0A%20%20%20%20_fig.suptitle('Minimum%20jerk%20trajectory%20kinematics'%2C%20fontsize%3D16)%0A%20%20%20%20_fig.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%20Note%20that%20for%20the%20minimum%20jerk%20trajectory%2C%20initial%20and%20final%20values%20of%20both%20velocity%20and%20acceleration%20are%20zero%2C%20but%20not%20for%20the%20jerk.%0A%0A%20%20%20%20Read%20more%20about%20the%20minimum%20jerk%20trajectory%20hypothesis%20in%20the%20%5BShadmehr%20and%20Wise's%20book%20companion%20site%5D(https%3A%2F%2Fstorage.googleapis.com%2Fwzukusers%2Fuser-31382847%2Fdocuments%2F5a7253343814f4Iv6Hnt%2Fminimumjerk.pdf)%20and%20in%20%5BPaul%20Gribble's%20website%5D(https%3A%2F%2Fgribblelab.org%2Fteaching%2Fcompneuro2012%2F4_Computational_Motor_Control_Kinematics.html%23orgheadline12).%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%20The%20angular%20trajectory%20of%20a%20minimum%20jerk%20trajectory%0A%0A%20%20%20%20Let's%20calculate%20the%20resulting%20angular%20trajectory%20given%20a%20minimum%20jerk%20linear%20trajectory%2C%20supposing%20it%20is%20from%20a%20circular%20motion%20of%20an%20elbow%20flexion.%20The%20length%20of%20the%20forearm%20is%200.5%20m%2C%20the%20movement%20duration%20is%201%20s%2C%20the%20elbow%20starts%20flexed%20at%2090%24%5Eo%24%20and%20the%20flexes%20to%20180%24%5Eo%24.%0A%0A%20%20%20%20First%2C%20the%20linear%20trajectories%20for%20this%20circular%20motion%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eq%2C%20S%2C%20d%2C%20diff%2C%20display%2C%20lambdify%2C%20t%2C%20x2%2C%20xf%2C%20xi)%3A%0A%20%20%20%20x3_1%20%3D%20x2.subs(%5B(xi%2C%200.5)%2C%20(xf%2C%200)%2C%20(d%2C%201)%5D)%0A%20%20%20%20y3%20%3D%20x2.subs(%5B(xi%2C%200)%2C%20(xf%2C%200.5)%2C%20(d%2C%201)%5D)%0A%20%20%20%20display(Eq(S('y(t)')%2C%20x3_1))%0A%20%20%20%20display(Eq(S('x(t)')%2C%20y3))%0A%20%20%20%20xfux%20%3D%20lambdify(t%2C%20diff(x3_1%2C%20t%2C%200)%2C%20'numpy')%0A%20%20%20%20vfux%20%3D%20lambdify(t%2C%20diff(x3_1%2C%20t%2C%201)%2C%20'numpy')%0A%20%20%20%20afux%20%3D%20lambdify(t%2C%20diff(x3_1%2C%20t%2C%202)%2C%20'numpy')%0A%20%20%20%20jfux%20%3D%20lambdify(t%2C%20diff(x3_1%2C%20t%2C%203)%2C%20'numpy')%0A%20%20%20%20xfuy%20%3D%20lambdify(t%2C%20diff(y3%2C%20t%2C%200)%2C%20'numpy')%0A%20%20%20%20vfuy%20%3D%20lambdify(t%2C%20diff(y3%2C%20t%2C%201)%2C%20'numpy')%0A%20%20%20%20afuy%20%3D%20lambdify(t%2C%20diff(y3%2C%20t%2C%202)%2C%20'numpy')%0A%20%20%20%20jfuy%20%3D%20lambdify(t%2C%20diff(y3%2C%20t%2C%203)%2C%20'numpy')%0A%20%20%20%20return%20afux%2C%20afuy%2C%20jfux%2C%20jfuy%2C%20vfux%2C%20vfuy%2C%20x3_1%2C%20xfux%2C%20xfuy%2C%20y3%0A%0A%0A%40app.cell%0Adef%20_(afux%2C%20afuy%2C%20jfux%2C%20jfuy%2C%20np%2C%20plt%2C%20vfux%2C%20vfuy%2C%20xfux%2C%20xfuy)%3A%0A%20%20%20%20_ts%20%3D%20np.arange(0%2C%201.01%2C%200.01)%0A%20%20%20%20(_fig%2C%20_axs)%20%3D%20plt.subplots(1%2C%204%2C%20figsize%3D(10%2C%204)%2C%20sharex%3DTrue)%0A%20%20%20%20_axs%5B0%5D.plot(_ts%2C%20xfux(_ts)%2C%20'b'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B0%5D.plot(_ts%2C%20xfuy(_ts)%2C%20'r'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B0%5D.set_title('Displacement%20%5B%24%5C%5Cmathrm%7Bm%7D%24%5D')%0A%20%20%20%20_axs%5B1%5D.plot(_ts%2C%20vfux(_ts)%2C%20'b'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B1%5D.plot(_ts%2C%20vfuy(_ts)%2C%20'r'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B1%5D.set_title('Velocity%20%5B%24%5C%5Cmathrm%7Bm%2Fs%7D%24%5D')%0A%20%20%20%20_axs%5B2%5D.plot(_ts%2C%20afux(_ts)%2C%20'b'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B2%5D.plot(_ts%2C%20afuy(_ts)%2C%20'r'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B2%5D.set_title('Acceleration%20%5B%24%5C%5Cmathrm%7Bm%2Fs%5E2%7D%24%5D')%0A%20%20%20%20_axs%5B3%5D.plot(_ts%2C%20jfux(_ts)%2C%20'b'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B3%5D.plot(_ts%2C%20jfuy(_ts)%2C%20'r'%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B3%5D.set_title('Jerk%20%5B%24%5C%5Cmathrm%7Bm%2Fs%5E3%7D%24%5D')%0A%20%20%20%20for%20_axi%20in%20_axs%3A%0A%20%20%20%20%20%20%20%20_axi.set_xlabel('Time%20%5Bs%5D'%2C%20fontsize%3D12)%0A%20%20%20%20%20%20%20%20_axi.grid(True)%0A%20%20%20%20_fig.suptitle('Minimum%20jerk%20trajectory%20kinematics'%2C%20fontsize%3D16)%0A%20%20%20%20_fig.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%20Now%2C%20the%20angular%20trajectories%20for%20this%20circular%20motion%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(Eq%2C%20S%2C%20diff%2C%20display%2C%20lambdify%2C%20t%2C%20x3_1%2C%20y3)%3A%0A%20%20%20%20from%20sympy%20import%20atan2%2C%20pi%0A%20%20%20%20ang%20%3D%20atan2(y3%2C%20x3_1)%20*%20180%20%2F%20pi%0A%20%20%20%20display(Eq(S('angle(t)')%2C%20ang))%0A%20%20%20%20xang%20%3D%20lambdify(t%2C%20diff(ang%2C%20t%2C%200)%2C%20'numpy')%0A%20%20%20%20vang%20%3D%20lambdify(t%2C%20diff(ang%2C%20t%2C%201)%2C%20'numpy')%0A%20%20%20%20aang%20%3D%20lambdify(t%2C%20diff(ang%2C%20t%2C%202)%2C%20'numpy')%0A%20%20%20%20jang%20%3D%20lambdify(t%2C%20diff(ang%2C%20t%2C%203)%2C%20'numpy')%0A%20%20%20%20return%20aang%2C%20jang%2C%20vang%2C%20xang%0A%0A%0A%40app.cell%0Adef%20_(aang%2C%20jang%2C%20np%2C%20plt%2C%20vang%2C%20xang)%3A%0A%20%20%20%20_ts%20%3D%20np.arange(0%2C%201.01%2C%200.01)%0A%20%20%20%20(_fig%2C%20_axs)%20%3D%20plt.subplots(1%2C%204%2C%20figsize%3D(10%2C%204)%2C%20sharex%3DTrue)%0A%20%20%20%20_axs%5B0%5D.plot(_ts%2C%20xang(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B0%5D.set_title('Displacement%20%5B%24%5C%5Cmathrm%7B%5Eo%7D%24%5D')%0A%20%20%20%20_axs%5B1%5D.plot(_ts%2C%20vang(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B1%5D.set_title('Velocity%20%5B%24%5C%5Cmathrm%7B%5Eo%2Fs%7D%24%5D')%0A%20%20%20%20_axs%5B2%5D.plot(_ts%2C%20aang(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B2%5D.set_title('Acceleration%20%5B%24%5C%5Cmathrm%7B%5Eo%2Fs%5E2%7D%24%5D')%0A%20%20%20%20_axs%5B3%5D.plot(_ts%2C%20jang(_ts)%2C%20linewidth%3D3)%0A%20%20%20%20_axs%5B3%5D.set_title('Jerk%20%5B%24%5C%5Cmathrm%7B%5Eo%2Fs%5E3%7D%24%5D')%0A%20%20%20%20for%20_axi%20in%20_axs%3A%0A%20%20%20%20%20%20%20%20_axi.set_xlabel('Time%20%5Bs%5D'%2C%20fontsize%3D14)%0A%20%20%20%20%20%20%20%20_axi.grid(True)%0A%20%20%20%20_fig.suptitle('Minimum%20jerk%20trajectory%20angular%20kinematics'%2C%20fontsize%3D16)%0A%20%20%20%20_fig.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**Exercise%203.**%20Keep%20displacement%20fixed%20and%20halve%20duration.%20How%20do%20peak%20speed%2C%20acceleration%2C%20jerk%20and%20the%20integral%20of%20squared%20jerk%20change%3F%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%20Each%20time%20derivative%20brings%20a%20factor%20%241%2FT%24%3A%20the%20peaks%20multiply%20by%202%2C%204%20and%208.%20Squaring%20jerk%20contributes%20%24T%5E%7B-6%7D%24%20and%20integration%20contributes%20%24T%24%2C%20so%20the%20cost%20multiplies%20by%20%242%5E5%3D32%24.%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%20Checkpoint%20questions%0A%0A%20%20%20%201.%20Does%20minimizing%20jerk%20identify%20the%20neural%20mechanism%3F%0A%20%20%20%202.%20Where%20is%20peak%20speed%20for%20the%20symmetric%20reach%3F%0A%20%20%20%203.%20Why%20do%20the%20three%20spatial%20coordinates%20share%20the%20same%20normalized%20time%20profile%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Checkpoint%20answers%0A%0A%20%20%20%201.%20No%3B%20it%20is%20a%20trajectory-level%20organizing%20hypothesis.%202.%20At%20half%20the%20movement%20duration.%203.%20The%20same%20endpoint%20constraints%20and%20separable%20squared-jerk%20objective%20give%20the%20same%20normalized%20polynomial%20in%20each%20coordinate.%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.%20What%20is%20your%20opinion%20on%20the%20the%20minimum%20jerk%20hypothesis%3F%20Do%20you%20think%20humans%20control%20movement%20based%20on%20this%20principle%3F%20(Think%20about%20what%20biomechanical%20and%20neurophysiological%20properties%20are%20not%20considered%20on%20this%20hypothesis.)%0A%20%20%20%202.%20Calculate%20and%20plot%20the%20position%2C%20velocity%2C%20acceleration%2C%20and%20jerk%20trajectories%20for%20different%20movement%20speeds%20(for%20example%2C%20consider%20always%20a%20displacement%20of%201%20m%20and%20movement%20durations%20of%200.5%2C%201%2C%20and%202%20s).%0A%20%20%20%203.%20For%20the%20data%20in%20the%20previous%20item%2C%20calculate%20the%20ratio%20peak%20speed%20to%20average%20speed.%20Shadmehr%20and%20%20Wise%20(2004)%20argue%20that%20psychophysical%20experiments%20show%20that%20reaching%20movements%20with%20the%20hand%20have%20this%20ratio%20equals%20to%201.75.%20Compare%20with%20the%20calculated%20values.%0A%20%20%20%204.%20Can%20you%20propose%20alternative%20hypotheses%20for%20the%20control%20of%20movement%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.%20Minimum%20jerk%20describes%20many%20smooth%2C%20unconstrained%20reaches%2C%20but%20is%20not%20a%20complete%20neural%20or%20biomechanical%20mechanism%3A%20forces%2C%20muscle%20activation%2C%20noise%2C%20feedback%2C%20obstacles%20and%20joint%20limits%20are%20absent.%0A%20%20%20%202.%20For%20displacement%20%24D%3D1%24%20m%2C%20duration%20%24T%24%20and%20%24s%3Dt%2FT%24%3A%20%24x%3D10s%5E3-15s%5E4%2B6s%5E5%24%2C%20%24v%3D(30s%5E2-60s%5E3%2B30s%5E4)%2FT%24%2C%20%24a%3D(60s-180s%5E2%2B120s%5E3)%2FT%5E2%24%2C%20%24j%3D(60-360s%2B360s%5E2)%2FT%5E3%24.%20For%20%24T%3D0.5%2C1%2C2%24%20s%2C%20peak%20speeds%20are%203.75%2C%201.875%20and%200.9375%20m%2Fs%3B%20the%20profiles%20have%20identical%20normalized%20shape.%0A%20%20%20%203.%20The%20peak%2Fmean-speed%20ratio%20is%20%2415%2F8%3D1.875%24%20for%20all%20three%20durations.%20It%20is%20about%207.14%25%20larger%20than%20the%20reported%20value%201.75%3B%20the%20model%20does%20not%20predict%20that%20empirical%20ratio%20exactly.%0A%20%20%20%204.%20Alternatives%20include%20minimum%20torque%20change%2C%20minimum%20metabolic%20or%20mechanical%20cost%2C%20minimum%20variance%20under%20signal-dependent%20noise%2C%20and%20optimal%20feedback%20control.%20Distinguishing%20them%20requires%20predictions%20for%20perturbations%20or%20altered%20task%20constraints%2C%20not%20a%20smooth%20trajectory%20alone.%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%20Read%20%5BKinematicChain%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fkinematic_chain.py)%20for%20the%20difference%20between%20endpoint%20and%20joint%20trajectories.%0A%0A%20%20%20%20%23%23%23%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20%5BMIT%20Classical%20Mechanics%5D(https%3A%2F%2Focw.mit.edu%2Fcourses%2F8-01sc-classical-mechanics-fall-2016%2F)%20has%20short%20lessons%20on%20kinematics%2C%20circular%20motion%20and%20Newton%E2%80%99s%20laws.%20Choose%20the%20lesson%20that%20matches%20the%20measurement%20or%20balance%20equation%20used%20here.%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-%20Flash%20T%2C%20Hogan%20N%20(1985)%20%5BThe%20coordination%20of%20arm%20movements%3A%20an%20experimentally%20confirmed%20mathematical%20model%5D(https%3A%2F%2Fdoi.org%2F10.1523%2FJNEUROSCI.05-07-01688.1985).%20Journal%20of%20Neuroscience%2C%205%2C%201688-1703.%0A%0A%20%20%20%20-%20Hogan%20N%20(1984)%20%5BAn%20organizing%20principle%20for%20a%20class%20of%20voluntary%20movements%5D(https%3A%2F%2Fdoi.org%2F10.1523%2FJNEUROSCI.04-11-02745.1984).%20Journal%20of%20Neuroscience%2C%204%2C%202745-2754.%0A%0A%20%20%20%20-%20Shadmehr%20R%2C%20Wise%20S%20(2004)%20%5BThe%20Computational%20Neurobiology%20of%20Reaching%20and%20Pointing%3A%20A%20Foundation%20for%20Motor%20Learning%5D(https%3A%2F%2Fbooks.google.com.br%2Fbooks%3Fid%3DfKeImql1s_sC%26pg%3DPP1%26ots%3DWuEHfPo6G4%26dq%3Dshadmehr%26sig%3DUjsmHL92SidKEKzgvpe5Qu_9pIs%26redir_esc%3Dy%23v%3Donepage%26q%3Dshadmehr%26f%3Dfalse).%20A%20Bradford%20Book.%20%5BSupplementary%20documents%5D(https%3A%2F%2Fwww.shadmehrlab.org%2Fpublications).%0A%0A%20%20%20%20-%20Zatsiorsky%20VM%20(1998)%20%5BKinematics%20of%20Human%20Motion%5D(https%3A%2F%2Fbooks.google.com.br%2Fbooks%2Fabout%2FKinematics_of_Human_Motion.html%3Fid%3DPql_xXdbrMcC%26redir_esc%3Dy).%20Champaign%2C%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
34d7f2a501b0a721f41d90b0c2034853