%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%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(width%3D%22medium%22)%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%20Scalar%20and%20vector%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%20motion%20capture%20system%20hands%20you%20three%20numbers%20per%20marker%20per%20frame.%20A%20force%20plate%20hands%20you%20three%20more.%20Almost%20everything%20you%20will%20ever%20compute%20in%20biomechanics%20starts%20from%20triples%20like%20those%2C%20and%20almost%20every%20mistake%20you%20will%20make%20with%20them%20comes%20from%20forgetting%20that%20a%20triple%20of%20numbers%20is%20not%20automatically%20a%20vector%2C%20and%20that%20a%20vector%20is%20not%20automatically%20something%20you%20are%20allowed%20to%20multiply.%0A%0A%20%20%20%20This%20notebook%20is%20a%20tour%20of%20the%20small%20set%20of%20operations%20that%20*are*%20allowed%20%E2%80%94%20magnitude%2C%20addition%2C%20dot%20product%2C%20cross%20product%20%E2%80%94%20and%20of%20what%20each%20of%20them%20means%20physically.%20It%20ends%20by%20building%20a%20coordinate%20system%20out%20of%20three%20measured%20points%2C%20which%20is%20the%20operation%20that%20all%20three-dimensional%20motion%20analysis%20rests%20on.%0A%0A%20%20%20%20Read%20it%20in%20order%20and%20run%20each%20cell%20as%20you%20reach%20it.%20Where%20you%20find%20a%20**Challenge**%20or%20a%20set%20of%20**Guiding%20questions**%2C%20stop%20and%20answer%20on%20a%20scratchpad%20before%20moving%20on.%20Python%20is%20used%20throughout%20as%20a%20calculator%20you%20can%20argue%20with%3A%20when%20a%20result%20surprises%20you%2C%20that%20is%20the%20notebook%20working.%0A%0A%20%20%20%20For%20a%20review%20of%20scalars%20and%20vectors%2C%20see%20chapter%201%20of%20%5BRuina%20and%20Pratap's%20book%5D(https%3A%2F%2Fruina.tam.cornell.edu%2FBook%2Findex.html).%20For%20symbolic%20rather%20than%20numerical%20work%20with%20the%20same%20objects%2C%20see%20%5BSympy%5D(http%3A%2F%2Fsympy.org).%0A%0A%20%20%20%20**Challenge%200.**%20Before%20you%20begin%2C%20write%20down%20three%20physical%20quantities%20you%20have%20measured%20or%20would%20like%20to%20measure.%20For%20each%2C%20say%20whether%20one%20number%20is%20enough%20to%20describe%20it.%20Keep%20the%20list%20nearby%3B%20the%20checkpoint%20questions%20ask%20you%20to%20come%20back%20to%20it.%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%20Three%20numbers%20from%20a%20laboratory%0A%0A%20%20%20%20Suppose%20a%20motion%20capture%20system%20reports%20the%20velocity%20of%20a%20jumper's%20center%20of%20mass%20at%20the%20instant%20of%20take-off%20as%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bv%7D%7D%20%3D%20(8.0%2C%5C%3B%203.5%2C%5C%3B%200.2)%5C%3B%5Cmathrm%7Bm%2Fs%7D%2C%0A%20%20%20%20%24%24%0A%0A%20%20%20%20where%20%24%5Cmathbf%7Bx%7D%24%20is%20the%20direction%20of%20the%20run-up%2C%20%24%5Cmathbf%7By%7D%24%20is%20vertical%2C%20and%20%24%5Cmathbf%7Bz%7D%24%20is%20medio-lateral.%0A%0A%20%20%20%20Three%20questions%20you%20might%20reasonably%20ask%20of%20those%20numbers%3A%0A%0A%20%20%20%20-%20How%20fast%20was%20the%20jumper%20going%3F%20That%20is%20one%20number%2C%20and%20it%20is%20*not*%208.0%2C%20nor%2011.7.%0A%20%20%20%20-%20At%20what%20angle%20did%20they%20leave%20the%20ground%3F%20That%20is%20also%20one%20number%2C%20and%20there%20is%20more%20than%20one%20defensible%20way%20to%20compute%20it.%0A%20%20%20%20-%20Is%20the%200.2%20in%20the%20third%20slot%20noise%2C%20or%20is%20the%20jumper%20drifting%20sideways%3F%0A%0A%20%20%20%20None%20of%20the%20three%20can%20be%20answered%20by%20looking%20at%20the%20components%20one%20at%20a%20time.%20By%20the%20end%20of%20this%20notebook%20all%20three%20will%20be%20one%20line%20of%20Python%20each%20%E2%80%94%20and%20you%20will%20know%20which%20of%20the%20two%20angles%20in%20the%20second%20question%20you%20actually%20wanted.%0A%0A%20%20%20%20**Guiding%20questions%200.**%0A%0A%20%20%20%201.%20Guess%20the%20magnitude%20of%20that%20velocity%20before%20computing%20it.%20Is%20it%20closer%20to%208%2C%20to%209%2C%20or%20to%2012%20m%2Fs%3F%0A%20%20%20%202.%20The%20third%20component%20is%20small.%20Under%20what%20circumstance%20would%20a%20small%20number%20in%20that%20slot%20be%20the%20most%20interesting%20thing%20in%20the%20measurement%3F%0A%20%20%20%203.%20If%20you%20rotated%20the%20laboratory's%20coordinate%20system%20by%2030%20degrees%20about%20the%20vertical%2C%20which%20of%20the%20three%20numbers%20would%20change%3F%20Which%20of%20the%20answers%20to%20the%20three%20questions%20above%20would%20change%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%20NumPy%20does%20all%20the%20work%20in%20this%20notebook.%20The%20%60math%60%20module%20appears%20once%2C%20to%20make%20a%20point%20about%20the%20difference%20between%20the%20two.%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%20math%0A%20%20%20%20import%20numpy%20as%20np%0A%0A%20%20%20%20return%20math%2C%20np%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%20Scalar%0A%0A%20%20%20%20%3E%20A%20**scalar**%20is%20a%20quantity%20described%20by%20a%20single%20value%20(and%20units%20where%20applicable)%20that%20is%20unchanged%20by%20a%20rotation%20of%20spatial%20axes.%0A%0A%20%20%20%20Time%2C%20mass%2C%20and%20energy%20are%20examples%20of%20scalars.%20So%20are%20temperature%2C%20distance%20travelled%2C%20and%20the%20reading%20on%20a%20bathroom%20scale.%0A%0A%20%20%20%20%23%23%23%20Scalar%20operations%20in%20Python%0A%0A%20%20%20%20Simple%20arithmetic%20operations%20with%20scalars%20are%20indeed%20simple%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(math)%3A%0A%20%20%20%20a%20%3D%202%0A%20%20%20%20b%20%3D%203%0A%0A%20%20%20%20print(%22a%20%3D%22%2C%20a%2C%20%22%2C%20b%20%3D%22%2C%20b)%0A%20%20%20%20print(%22a%20%2B%20b%20%3D%22%2C%20a%20%2B%20b)%0A%20%20%20%20print(%22a%20-%20b%20%3D%22%2C%20a%20-%20b)%0A%20%20%20%20print(%22a%20*%20b%20%3D%22%2C%20a%20*%20b)%0A%20%20%20%20print(%22a%20%2F%20b%20%3D%22%2C%20a%20%2F%20b)%0A%20%20%20%20print(%22a%20**%20b%20%3D%22%2C%20a**b)%0A%20%20%20%20print(%22sqrt(b)%20%3D%22%2C%20math.sqrt(b))%0A%20%20%20%20return%20(a%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%20If%20you%20have%20a%20set%20of%20numbers%2C%20or%20an%20array%2C%20it%20is%20probably%20better%20to%20use%20NumPy%3B%20it%20will%20be%20faster%20for%20large%20data%20sets%20and%2C%20combined%20with%20SciPy%2C%20has%20many%20more%20mathematical%20functions.%0A%0A%20%20%20%20Note%20the%20last%20line%20below%3A%20%60math.sqrt%60%20would%20raise%20an%20error%20on%20an%20array%2C%20while%20%60numpy.sqrt%60%20takes%20the%20square%20root%20of%20every%20element%20at%20once.%20Use%20NumPy's%20functions%20on%20NumPy's%20arrays.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(a%2C%20np)%3A%0A%20%20%20%20b_array%20%3D%20np.array(%5B3%2C%204%2C%205%2C%206%2C%207%2C%208%5D)%0A%0A%20%20%20%20print(%22a%20%3D%22%2C%20a%2C%20%22%2C%20b%20%3D%22%2C%20b_array)%0A%20%20%20%20print(%22a%20%2B%20b%20%3D%22%2C%20a%20%2B%20b_array)%0A%20%20%20%20print(%22a%20-%20b%20%3D%22%2C%20a%20-%20b_array)%0A%20%20%20%20print(%22a%20*%20b%20%3D%22%2C%20a%20*%20b_array)%0A%20%20%20%20print(%22a%20%2F%20b%20%3D%22%2C%20a%20%2F%20b_array)%0A%20%20%20%20print(%22a%20**%20b%20%3D%22%2C%20a**b_array)%0A%20%20%20%20print(%22np.sqrt(b)%20%3D%22%2C%20np.sqrt(b_array))%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%20NumPy%20performed%20the%20arithmetic%20operation%20between%20the%20single%20number%20in%20%60a%60%20and%20every%20number%20of%20the%20array%20%60b%60.%20This%20is%20called%20**broadcasting**%2C%20and%20it%20is%20the%20reason%20NumPy%20code%20so%20rarely%20contains%20a%20loop.%0A%0A%20%20%20%20Even%20with%20two%20arrays%20%E2%80%94%20provided%20their%20shapes%20are%20compatible%20%E2%80%94%20NumPy%20handles%20it%20for%20you%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20c_array%20%3D%20np.array(%5B1%2C%202%2C%203%5D)%0A%20%20%20%20d_array%20%3D%20np.array(%5B4%2C%205%2C%206%5D)%0A%0A%20%20%20%20print(%22c%20%3D%22%2C%20c_array%2C%20%22%2C%20d%20%3D%22%2C%20d_array)%0A%20%20%20%20print(%22c%20%2B%20d%20%3D%22%2C%20c_array%20%2B%20d_array)%0A%20%20%20%20print(%22c%20-%20d%20%3D%22%2C%20c_array%20-%20d_array)%0A%20%20%20%20print(%22c%20*%20d%20%3D%22%2C%20c_array%20*%20d_array)%0A%20%20%20%20print(%22c%20%2F%20d%20%3D%22%2C%20c_array%20%2F%20d_array)%0A%20%20%20%20print(%22c%20**%20d%20%3D%22%2C%20c_array**d_array)%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%20Every%20one%20of%20those%20six%20lines%20ran%20without%20complaint.%20Hold%20that%20thought%20for%20two%20cells%3B%20three%20of%20them%20are%20about%20to%20become%20nonsense.%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%20Vector%0A%0A%20%20%20%20%3E%20A%20**vector**%20is%20a%20quantity%20with%20magnitude%20(or%20length)%20and%20direction%2C%20expressed%20numerically%20as%20an%20ordered%20list%20of%20values%20according%20to%20a%20coordinate%20reference%20system.%0A%0A%20%20%20%20Position%2C%20force%2C%20and%20torque%20are%20physical%20quantities%20defined%20by%20vectors.%20So%20is%20the%20take-off%20velocity%20we%20started%20with.%0A%0A%20%20%20%20For%20instance%2C%20consider%20the%20position%20of%20a%20point%20in%20space%20represented%20by%20a%20vector%3A%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-1%22%3E%3Ccenter%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fvector3D.png%3Fraw%3D1%22%20width%3D300%20alt%3D%22position%20vector%22%2F%3E%3C%2Fcenter%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.%20Position%20of%20a%20point%20represented%20by%20a%20vector%20in%20a%20Cartesian%20coordinate%20system.%3C%2Fspan%3E%0A%0A%20%20%20%20The%20position%20of%20the%20point%20(the%20vector)%20above%20can%20be%20represented%20as%20a%20tuple%20of%20values%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20(x%2C%5C%3A%20y%2C%5C%3A%20z)%20%5C%3B%20%5CRightarrow%20%5C%3B%20(1%2C%203%2C%202)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20or%20in%20matrix%20form%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cbegin%7Bbmatrix%7D%20x%20%5C%5C%20y%20%5C%5C%20z%20%5Cend%7Bbmatrix%7D%20%5C%3B%5C%3B%20%5CRightarrow%20%5C%3B%5C%3B%20%5Cbegin%7Bbmatrix%7D%201%20%5C%5C%203%20%5C%5C%202%20%5Cend%7Bbmatrix%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20We%20can%20use%20a%20NumPy%20array%20to%20represent%20the%20components%20of%20a%20vector.%20For%20the%20vector%20above%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20p%20%3D%20np.array(%5B1%2C%203%2C%202%5D)%0A%0A%20%20%20%20print(%22p%20%3D%22%2C%20p)%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%20exactly%20the%20same%20kind%20of%20object%20as%20the%20arrays%20in%20the%20scalar%20section%2C%20so%20all%20the%20operations%20we%20performed%20there%20will%20run%20and%20produce%20numbers.%20But%20we%20are%20now%20dealing%20with%20vectors%2C%20and%20some%20of%20those%20operations%20no%20longer%20*mean*%20anything.%20**For%20vectors%20there%20is%20no%20multiplication%2C%20division%2C%20power%2C%20or%20square%20root%20in%20the%20element-by-element%20way%20we%20just%20computed%20them.**%20NumPy%20will%20not%20stop%20you%3B%20mechanics%20will.%0A%0A%20%20%20%20There%20are%20two%20products%20defined%20for%20vectors%2C%20and%20neither%20of%20them%20is%20%60a%20*%20b%60.%20We%20come%20to%20both%20below.%0A%0A%20%20%20%20**Challenge%201.**%20Take%20two%20position%20vectors%2C%20%24(1%2C%203%2C%202)%24%20and%20%24(2%2C%200%2C%201)%24%2C%20and%20compute%20their%20element-wise%20product%20in%20Python.%20You%20will%20get%20three%20numbers.%20Invent%20a%20physical%20interpretation%20for%20them.%20Then%20explain%20why%20your%20interpretation%20falls%20apart%20if%20you%20rotate%20the%20coordinate%20system%20%E2%80%94%20and%20notice%20that%20this%20is%20precisely%20the%20test%20that%20the%20two%20real%20vector%20products%20pass.%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%20Versors%20and%20the%20ijk%20notation%0A%0A%20%20%20%20A%20vector%20can%20also%20be%20written%20as%20a%20sum%20of%20contributions%20along%20each%20axis%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%3D%20a_x%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20a_y%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20a_z%5Chat%7B%5Cmathbf%7Bk%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-2%22%3E%3Ccenter%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fvector3Dijk.png%3Fraw%3D1%22%20width%3D300%20alt%3D%22vector%20components%22%2F%3E%3C%2Fcenter%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.%20A%20vector%20representation%20in%20a%20Cartesian%20coordinate%20system.%20The%20versors%20%24%5Chat%7B%5Cmathbf%7Bi%7D%7D%2C%5C%2C%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%2C%5C%2C%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%5C%2C%24%20are%20usually%20represented%20in%20the%20color%20sequence%20%3Cb%3Ergb%3C%2Fb%3E%20(red%2C%20green%2C%20blue)%20for%20easier%20visualization.%3C%2Fspan%3E%0A%0A%20%20%20%20where%20%24%5Chat%7B%5Cmathbf%7Bi%7D%7D%2C%5C%2C%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%2C%5C%2C%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%5C%2C%24%20are%20unit%20vectors%2C%20each%20representing%20a%20direction%2C%20and%20%24a_x%5Chat%7B%5Cmathbf%7Bi%7D%7D%2C%5C%3A%20a_y%5Chat%7B%5Cmathbf%7Bj%7D%7D%2C%5C%3A%20a_z%5Chat%7B%5Cmathbf%7Bk%7D%7D%24%20are%20the%20vector%20components%20of%20the%20vector%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24.%0A%0A%20%20%20%20A%20**unit%20vector**%20(or%20**versor**)%20is%20a%20vector%20whose%20length%20(or%20norm)%20is%201.%20The%20unit%20vector%20of%20a%20non-zero%20vector%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20is%20the%20unit%20vector%20codirectional%20with%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Cmathbf%7B%5Chat%7Bu%7D%7D%20%3D%20%5Cfrac%7B%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7D%7B%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7C%7C%7D%20%3D%0A%20%20%20%20%5Cfrac%7Ba_x%5C%2C%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20a_y%5C%2C%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20a_z%5C%2C%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%7D%7B%5Csqrt%7Ba_x%5E2%2Ba_y%5E2%2Ba_z%5E2%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20A%20versor%20is%20how%20you%20separate%20*where%20something%20points*%20from%20*how%20much%20of%20it%20there%20is*%20%E2%80%94%20the%20direction%20of%20a%20force%20from%20its%20intensity%2C%20the%20orientation%20of%20a%20segment%20from%20its%20length.%20Nearly%20every%20three-dimensional%20calculation%20in%20biomechanics%20has%20a%20versor%20in%20it%20somewhere.%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%20Magnitude%20(length%20or%20norm)%20of%20a%20vector%0A%0A%20%20%20%20The%20magnitude%20(length)%20of%20a%20vector%20is%20often%20represented%20by%20the%20symbol%20%24%7C%7C%5C%3B%7C%7C%24%2C%20also%20known%20as%20the%20norm%20(or%20Euclidean%20norm)%20of%20a%20vector%2C%20and%20it%20is%20defined%20as%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7C%7C%20%3D%20%5Csqrt%7Ba_x%5E2%2Ba_y%5E2%2Ba_z%5E2%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20function%20%60numpy.linalg.norm%60%20calculates%20the%20norm%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20r%20%3D%20np.array(%5B1%2C%202%2C%203%5D)%0A%0A%20%20%20%20np.linalg.norm(r)%0A%20%20%20%20return%20(r%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%20Or%20we%20can%20use%20the%20definition%20and%20compute%20it%20directly%20%E2%80%94%20the%20element-wise%20product%20is%20legitimate%20here%20because%20we%20immediately%20sum%20it%2C%20which%20is%20the%20dot%20product%20in%20disguise%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20r)%3A%0A%20%20%20%20np.sqrt(np.sum(r%20*%20r))%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%20Then%20the%20versor%20for%20the%20vector%20%24%5Coverrightarrow%7B%5Cmathbf%7Br%7D%7D%20%3D%20(1%2C%202%2C%203)%24%20is%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20r)%3A%0A%20%20%20%20r_hat%20%3D%20r%20%2F%20np.linalg.norm(r)%0A%0A%20%20%20%20print(%22r_hat%20%3D%22%2C%20r_hat)%0A%20%20%20%20return%20(r_hat%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%20we%20can%20verify%20its%20magnitude%20is%20indeed%201%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20r_hat)%3A%0A%20%20%20%20np.linalg.norm(r_hat)%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%20We%20can%20now%20answer%20the%20first%20of%20the%20three%20questions%20from%20the%20top%20of%20the%20notebook.%20How%20fast%20was%20the%20jumper%20going%3F%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20v_takeoff%20%3D%20np.array(%5B8.0%2C%203.5%2C%200.2%5D)%20%20%23%20m%2Fs%0A%0A%20%20%20%20print(f%22Take-off%20velocity%3A%20%7Bv_takeoff%7D%20m%2Fs%22)%0A%20%20%20%20print(f%22Take-off%20speed%3A%20%20%20%20%7Bnp.linalg.norm(v_takeoff)%3A.2f%7D%20m%2Fs%22)%0A%20%20%20%20print(f%22Direction%3A%20%20%20%20%20%20%20%20%20%7Bv_takeoff%20%2F%20np.linalg.norm(v_takeoff)%7D%22)%0A%20%20%20%20return%20(v_takeoff%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%20speed%20is%208.73%20m%2Fs%3A%20more%20than%20the%208.0%20of%20the%20horizontal%20component%20alone%2C%20and%20far%20less%20than%20the%2011.7%20you%20would%20get%20by%20adding%20the%20three%20numbers.%20A%20norm%20is%20not%20a%20sum%2C%20and%20a%20vector%20is%20emphatically%20not%20the%20sum%20of%20its%20parts.%0A%0A%20%20%20%20Note%20also%20the%20vocabulary.%20**Speed**%20is%20the%20magnitude%20of%20the%20velocity%20%E2%80%94%20a%20scalar.%20**Velocity**%20is%20the%20vector.%20English%20uses%20the%20two%20words%20loosely%3B%20mechanics%20does%20not.%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.**%20Find%20the%20norm%20and%20unit%20vector%20of%20%24(3%2C4%2C0)%24%20m.%20Why%20can%E2%80%99t%20the%20zero%20vector%20be%20normalized%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%201%0A%20%20%20%20The%20norm%20is%20%24%5Csqrt%7B9%2B16%7D%3D5%24%20m%20and%20the%20unit%20vector%20is%20%24(0.6%2C0.8%2C0)%24.%20Dividing%20by%20the%20zero%20vector%E2%80%99s%20norm%20would%20divide%20by%20zero%3B%20it%20has%20no%20unique%20direction.%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%20Vectors%20that%20do%20not%20start%20at%20the%20origin%0A%0A%20%20%20%20A%20position%20vector%20from%20the%20coordinate%20origin%20to%20a%20point%20has%20that%20point%E2%80%99s%20coordinates%20as%20components.%20A%20displacement%20from%20another%20point%20is%20instead%20represented%20by%20the%20difference%20of%20the%20endpoint%20coordinates.%20For%20instance%2C%20consider%20the%20following%20vector%3A%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-3%22%3E%3Ccenter%3E%3Cimg%20src%3D%22https%3A%2F%2Fgithub.com%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fimages%2Fvector2.png%3Fraw%3D1%22%20width%3D260%20alt%3D%22a%20vector%20in%20space%22%2F%3E%3C%2Fcenter%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.%20A%20vector%20in%20space.%3C%2Fspan%3E%0A%0A%20%20%20%20Such%20a%20vector%20cannot%20be%20represented%20by%20%24(b_x%2C%20b_y%2C%20b_z)%24%2C%20because%20that%20would%20be%20the%20vector%20from%20the%20origin%20to%20the%20point%20B.%20The%20free%20displacement%20vector%20has%20components%20%24%5Cmathbf%7Bb%7D-%5Cmathbf%7Ba%7D%24.%20To%20specify%20its%20application%20point%20as%20well%2C%20retain%20%24%5Cmathbf%7Ba%7D%24%20(for%20example%20when%20computing%20a%20force%20moment).%20This%20distinction%20matters%20in%20mechanics.%0A%0A%20%20%20%20This%20is%20where%20a%20surprising%20number%20of%20errors%20in%20motion%20analysis%20come%20from.%20A%20marker%20trajectory%20is%20a%20position%20vector%2C%20tied%20to%20the%20origin%20of%20the%20laboratory.%20A%20segment%20%E2%80%94%20the%20forearm%2C%20say%20%E2%80%94%20is%20*not*%20a%20position%20vector%3B%20it%20is%20the%20difference%20between%20two%20of%20them.%20Writing%20%60elbow%60%20where%20you%20meant%20%60wrist%20-%20elbow%60%20produces%20code%20that%20runs%20perfectly%20and%20answers%20a%20question%20nobody%20asked.%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%20Vector%20addition%20and%20subtraction%0A%0A%20%20%20%20The%20addition%20of%20two%20vectors%20is%20another%20vector%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%2B%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%0A%20%20%20%20(a_x%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20a_y%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20a_z%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20%2B%20(b_x%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20b_y%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20b_z%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20%3D%0A%20%20%20%20(a_x%2Bb_x)%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20(a_y%2Bb_y)%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20(a_z%2Bb_z)%5Chat%7B%5Cmathbf%7Bk%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-4%22%3E%3Ccenter%3E%3Cimg%20src%3D%22https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F2%2F28%2FVector_addition.svg%22%20width%3D300%20alt%3D%22Vector%20addition%22%2F%3E%3C%2Fcenter%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20%3Cspan%20id%3D%22figure-caption-4%22%20class%3D%22figure-caption%22%20style%3D%22display%3Ablock%3Btext-align%3Acenter%3Bfont-style%3Aitalic%22%3EFigure.%20Vector%20addition%20(image%20from%20Wikipedia).%3C%2Fspan%3E%0A%0A%20%20%20%20The%20subtraction%20of%20two%20vectors%20is%20also%20another%20vector%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20-%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%0A%20%20%20%20(a_x%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20a_y%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20a_z%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20-%20(b_x%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20b_y%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20b_z%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20%3D%0A%20%20%20%20(a_x-b_x)%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20(a_y-b_y)%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20(a_z-b_z)%5Chat%7B%5Cmathbf%7Bk%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-5%22%3E%3Ccenter%3E%3Cimg%20src%3D%22https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F2%2F24%2FVector_subtraction.svg%22%20width%3D160%20alt%3D%22Vector%20subtraction%22%2F%3E%3C%2Fcenter%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20%3Cspan%20id%3D%22figure-caption-5%22%20class%3D%22figure-caption%22%20style%3D%22display%3Ablock%3Btext-align%3Acenter%3Bfont-style%3Aitalic%22%3EFigure.%20Vector%20subtraction%20(image%20from%20Wikipedia).%3C%2Fspan%3E%0A%0A%20%20%20%20Both%20of%20these%20you%20have%20already%20used%20without%20naming%20them.%20Adding%20vectors%20is%20what%20you%20do%20to%20two%20forces%20acting%20on%20the%20same%20body.%20Subtracting%20them%20is%20what%20you%20do%20to%20two%20positions%20to%20get%20a%20displacement%2C%20which%20is%20where%20the%20notebook%20%5BKinematics%20of%20a%20particle%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fkinematics_particle.py)%20begins.%0A%0A%20%20%20%20Consider%20two%202D%20arrays%20(rows%20and%20columns)%20representing%20the%20position%20of%20two%20objects%20moving%20in%20space.%20The%20columns%20represent%20the%20vector%20components%20and%20the%20rows%20the%20values%20of%20the%20position%20vector%20at%20different%20instants.%20Once%20again%2C%20it%20is%20easy%20to%20perform%20addition%20and%20subtraction%20with%20these%20vectors%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20pos_a%20%3D%20np.array(%5B%5B1%2C%202%2C%203%5D%2C%20%5B1%2C%201%2C%201%5D%5D)%0A%20%20%20%20pos_b%20%3D%20np.array(%5B%5B4%2C%205%2C%206%5D%2C%20%5B7%2C%208%2C%209%5D%5D)%0A%0A%20%20%20%20print(%22pos_a%20%3D%22%2C%20pos_a%2C%20%22%5Cnpos_b%20%3D%22%2C%20pos_b)%0A%20%20%20%20print(%22pos_a%20%2B%20pos_b%20%3D%22%2C%20pos_a%20%2B%20pos_b)%0A%20%20%20%20print(%22pos_a%20-%20pos_b%20%3D%22%2C%20pos_a%20-%20pos_b)%0A%20%20%20%20return%20pos_a%2C%20pos_b%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%20NumPy%20can%20handle%20an%20N-dimensional%20array%20with%20the%20size%20limited%20by%20the%20available%20memory%20in%20your%20computer.%20That%20%22rows%20are%20instants%2C%20columns%20are%20coordinates%22%20layout%20is%20how%20essentially%20every%20motion%20capture%20file%20you%20will%20read%20is%20organized%2C%20so%20it%20is%20worth%20getting%20comfortable%20with%20it%20now.%0A%0A%20%20%20%20We%20can%20perform%20operations%20on%20each%20vector%20%E2%80%94%20for%20example%2C%20calculate%20the%20norm%20of%20each%20one.%20First%20let's%20check%20the%20shape%20of%20the%20variable%20%60pos_a%60%2C%20using%20the%20method%20%60shape%60%20or%20the%20function%20%60numpy.shape%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20pos_a)%3A%0A%20%20%20%20print(pos_a.shape)%0A%20%20%20%20print(np.shape(pos_a))%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%20means%20the%20variable%20%60pos_a%60%20has%202%20rows%20and%203%20columns.%0A%0A%20%20%20%20We%20have%20to%20tell%20the%20function%20%60numpy.linalg.norm%60%20to%20calculate%20the%20norm%20for%20each%20vector%20%E2%80%94%20that%20is%2C%20to%20operate%20along%20the%20columns%20of%20%60pos_a%60%20%E2%80%94%20using%20the%20parameter%20%60axis%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20pos_a)%3A%0A%20%20%20%20np.linalg.norm(pos_a%2C%20axis%3D1)%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%20Two%20numbers%20out%2C%20one%20per%20instant%2C%20which%20is%20what%20we%20wanted.%20Get%20%60axis%60%20wrong%20and%20you%20get%20one%20number%20out%2C%20or%20three%2C%20and%20both%20are%20meaningless%20%E2%80%94%20but%20neither%20raises%20an%20error.%0A%0A%20%20%20%20**Challenge%202.**%20Run%20the%20cell%20above%20again%20with%20%60axis%3D0%60%20and%20with%20no%20%60axis%60%20at%20all.%20Write%20down%20what%20each%20result%20is%20the%20norm%20*of*.%20Then%20decide%20which%20of%20the%20three%20you%20would%20most%20likely%20produce%20by%20accident%20in%20real%20code%2C%20and%20how%20you%20would%20catch%20it.%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.**%20Elbow%20and%20wrist%20coordinates%20are%20%24(1%2C2%2C3)%24%20and%20%24(2%2C4%2C3)%24%20m.%20Find%20the%20forearm%20displacement%20and%20length.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%202%0A%20%20%20%20Subtract%20endpoints%3A%20%24(1%2C2%2C0)%24%20m.%20Its%20length%20is%20%24%5Csqrt5%24%20m.%20Adding%20the%20same%20origin%20shift%20to%20both%20endpoints%20leaves%20this%20difference%20unchanged.%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%20Dot%20product%0A%0A%20%20%20%20The%20**dot%20product**%20(or%20scalar%20product%2C%20or%20inner%20product)%20between%20two%20vectors%20is%20a%20mathematical%20operation%20algebraically%20defined%20as%20the%20sum%20of%20the%20products%20of%20the%20corresponding%20components%20of%20the%20two%20vectors.%20The%20result%20of%20the%20dot%20product%20is%20a%20single%20number%20%E2%80%94%20a%20scalar.%0A%0A%20%20%20%20The%20dot%20product%20between%20vectors%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20and%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ccdot%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%0A%20%20%20%20(a_x%5C%2C%5Chat%7B%5Cmathbf%7Bi%7D%7D%2Ba_y%5C%2C%5Chat%7B%5Cmathbf%7Bj%7D%7D%2Ba_z%5C%2C%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20%5Ccdot%20(b_x%5C%2C%5Chat%7B%5Cmathbf%7Bi%7D%7D%2Bb_y%5C%2C%5Chat%7B%5Cmathbf%7Bj%7D%7D%2Bb_z%5C%2C%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20%3D%0A%20%20%20%20a_x%20b_x%20%2B%20a_y%20b_y%20%2B%20a_z%20b_z%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Because%20by%20definition%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%5Ccdot%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%5Ccdot%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%5Ccdot%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%3D%201%0A%20%20%20%20%5Cquad%20%5Ctext%7Band%7D%20%5Cquad%0A%20%20%20%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%5Ccdot%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%5Ccdot%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%5Ccdot%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%3D%200%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20geometric%20equivalent%20of%20the%20dot%20product%20is%20the%20product%20of%20the%20magnitudes%20of%20the%20two%20vectors%20and%20the%20cosine%20of%20the%20angle%20between%20them%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ccdot%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%20%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7C%7C%5C%3A%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%7C%7C%5C%3A%5Ccos(%5Ctheta)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20which%20is%20also%20equivalent%20to%20stating%20that%20the%20dot%20product%20between%20two%20vectors%20is%20the%20magnitude%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20times%20the%20magnitude%20of%20the%20component%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20parallel%20to%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20(or%20the%20magnitude%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20times%20the%20magnitude%20of%20the%20component%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20parallel%20to%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24).%0A%0A%20%20%20%20That%20second%20reading%20is%20the%20one%20to%20keep.%20**The%20dot%20product%20measures%20how%20much%20of%20one%20vector%20lies%20along%20another.**%20It%20is%20zero%20exactly%20when%20the%20two%20are%20perpendicular%2C%20largest%20when%20they%20are%20parallel%2C%20and%20negative%20when%20they%20oppose%20each%20other%20%E2%80%94%20which%20is%20why%20it%20turns%20up%20in%20the%20definition%20of%20mechanical%20work%2C%20where%20only%20the%20part%20of%20the%20force%20along%20the%20displacement%20counts.%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%20dot%20product%20between%20two%20vectors%20can%20be%20visualized%20in%20this%20interactive%20animation.%20Drag%20one%20vector%20until%20the%20product%20reads%20zero%2C%20and%20note%20the%20configuration%3A%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.Html(%0A%20%20%20%20%20%20%20%20%22%22%22%3Ciframe%20src%3D%22https%3A%2F%2Fwww.geogebra.org%2Fclassic%2Fncdf2jsw%3Fembed%22%0A%20%20%20%20%20%20%20%20width%3D%22100%25%22%20height%3D%22500%22%20style%3D%22border%3Anone%22%3E%3C%2Fiframe%3E%22%22%22%0A%20%20%20%20)%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%20NumPy%20function%20for%20the%20dot%20product%20is%20%60numpy.dot%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20vec_a%20%3D%20np.array(%5B1%2C%202%2C%203%5D)%0A%20%20%20%20vec_b%20%3D%20np.array(%5B4%2C%205%2C%206%5D)%0A%0A%20%20%20%20print(%22vec_a%20%3D%22%2C%20vec_a%2C%20%22%5Cnvec_b%20%3D%22%2C%20vec_b)%0A%20%20%20%20print(%22np.dot(vec_a%2C%20vec_b)%20%3D%22%2C%20np.dot(vec_a%2C%20vec_b))%0A%20%20%20%20return%20vec_a%2C%20vec_b%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%20Or%20we%20can%20use%20the%20definition%20and%20compute%20it%20directly%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20vec_a%2C%20vec_b)%3A%0A%20%20%20%20np.sum(vec_a%20*%20vec_b)%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%20For%202D%20arrays%2C%20the%20%60numpy.dot%60%20function%20performs%20matrix%20multiplication%20rather%20than%20the%20dot%20product%3B%20so%20let's%20use%20the%20%60numpy.sum%60%20function%20with%20the%20%60axis%60%20parameter%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20pos_a%2C%20pos_b)%3A%0A%20%20%20%20np.sum(pos_a%20*%20pos_b%2C%20axis%3D1)%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%20angle%20of%20the%20jump%2C%20two%20ways%0A%0A%20%20%20%20We%20can%20now%20answer%20the%20second%20question%20from%20the%20top%20of%20the%20notebook.%20Inverting%20the%20geometric%20definition%20of%20the%20dot%20product%20gives%20the%20angle%20between%20any%20two%20vectors%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Ctheta%20%3D%20%5Carccos%5Cleft(%5Cfrac%7B%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ccdot%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%7D%0A%20%20%20%20%7B%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7C%7C%5C%3B%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%7C%7C%7D%5Cright)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20**Before%20you%20run%20the%20next%20cell**%2C%20predict%20the%20take-off%20angle%20of%20a%20jumper%20whose%20velocity%20is%20%24(8.0%2C%203.5%2C%200.2)%24%20m%2Fs.%20And%20predict%20whether%20the%20two%20ways%20of%20computing%20it%20below%20will%20agree.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20v_takeoff)%3A%0A%20%20%20%20x_axis%20%3D%20np.array(%5B1%2C%200%2C%200%5D)%0A%0A%20%20%20%20_cos%20%3D%20np.dot(v_takeoff%2C%20x_axis)%20%2F%20(%0A%20%20%20%20%20%20%20%20np.linalg.norm(v_takeoff)%20*%20np.linalg.norm(x_axis)%0A%20%20%20%20)%0A%20%20%20%20angle_3d%20%3D%20np.rad2deg(np.arccos(_cos))%0A%20%20%20%20angle_sagittal%20%3D%20np.rad2deg(np.arctan2(v_takeoff%5B1%5D%2C%20v_takeoff%5B0%5D))%0A%0A%20%20%20%20print(f%22Angle%20with%20the%20x%20axis%20(in%203D)%3A%20%20%20%20%20%20%7Bangle_3d%3A.2f%7D%C2%B0%22)%0A%20%20%20%20print(f%22Angle%20in%20the%20sagittal%20plane%20(x%2C%20y)%3A%20%7Bangle_sagittal%3A.2f%7D%C2%B0%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%20two%20disagree%2C%20slightly%2C%20and%20the%20disagreement%20is%20not%20a%20bug.%0A%0A%20%20%20%20The%20dot%20product%20with%20the%20%24%5Cmathbf%7Bx%7D%24%20axis%20gives%20the%20angle%20between%20the%20velocity%20and%20that%20axis%20*in%20space*%20%E2%80%94%20a%20single%20angle%20that%20knows%20nothing%20about%20which%20plane%20the%20deviation%20happened%20in.%20The%20sagittal-plane%20calculation%20throws%20the%20medio-lateral%20component%20away%20first%20and%20asks%20for%20the%20angle%20of%20what%20remains%2C%20which%20is%20the%20quantity%20a%20long%20jump%20analysis%20actually%20wants.%20With%20a%20%24z%24%20component%20of%20only%200.2%20m%2Fs%20the%20difference%20is%20a%20few%20hundredths%20of%20a%20degree%3B%20raise%20that%20component%20to%202%20m%2Fs%20and%20see%20what%20happens.%0A%0A%20%20%20%20This%20is%20the%20habit%20worth%20forming%3A%20an%20angle%20is%20always%20*between%20two%20specific%20things*%2C%20and%20if%20you%20cannot%20say%20which%20two%2C%20you%20cannot%20say%20what%20your%20number%20means.%0A%0A%20%20%20%20**Guiding%20questions%201.**%0A%0A%20%20%20%201.%20Under%20what%20condition%20would%20the%20two%20angles%20above%20be%20exactly%20equal%3F%0A%20%20%20%202.%20The%20dot%20product%20of%20the%20velocity%20with%20the%20vertical%20axis%20%24%5Chat%7B%5Cmathbf%7Bj%7D%7D%24%20is%203.5.%20What%20is%20the%20physical%20meaning%20of%20that%20number%3F%0A%20%20%20%203.%20A%20force%20and%20a%20displacement%20are%20perpendicular.%20How%20much%20work%20was%20done%3F%20Which%20property%20of%20the%20dot%20product%20did%20you%20just%20use%3F%0A%20%20%20%204.%20Why%20did%20we%20use%20%60arctan2%60%20rather%20than%20%60arctan%60%20in%20the%20second%20calculation%3F%20Try%20it%20with%20a%20jumper%20moving%20backwards%2C%20%24(-8.0%2C%203.5%2C%200.2)%24%2C%20and%20see.%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%20force%20%24(3%2C4%2C0)%24%20N%20acts%20on%20a%20point%20with%20velocity%20%24(2%2C0%2C0)%24%20m%2Fs.%20Find%20instantaneous%20power.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%203%0A%20%20%20%20Power%20is%20the%20dot%20product%3A%20%243(2)%2B4(0)%2B0(0)%3D6%24%20W.%20The%20perpendicular%20force%20component%20contributes%20no%20instantaneous%20power.%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%20Vector%20product%0A%0A%20%20%20%20The%20**cross%20product**%2C%20or%20vector%20product%2C%20between%20two%20vectors%20is%20a%20mathematical%20operation%20in%20three-dimensional%20space%20which%20results%20in%20a%20vector%20perpendicular%20to%20both%20of%20the%20vectors%20being%20multiplied%2C%20with%20a%20length%20(norm)%20equal%20to%20the%20product%20of%20the%20perpendicular%20components%20of%20the%20vectors%20being%20multiplied%20%E2%80%94%20which%20is%20equal%20to%20the%20area%20of%20the%20parallelogram%20that%20the%20vectors%20span.%0A%0A%20%20%20%20The%20cross%20product%20between%20vectors%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20and%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20is%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%0A%20%20%20%20(a_x%5C%2C%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20a_y%5C%2C%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20a_z%5C%2C%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20%5Ctimes%20(b_x%5C%2C%5Chat%7B%5Cmathbf%7Bi%7D%7D%2Bb_y%5C%2C%5Chat%7B%5Cmathbf%7Bj%7D%7D%2Bb_z%5C%2C%5Chat%7B%5Cmathbf%7Bk%7D%7D)%20%3D%0A%20%20%20%20(a_yb_z-a_zb_y)%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20(a_zb_x-a_xb_z)%5Chat%7B%5Cmathbf%7Bj%7D%7D%2B(a_xb_y-a_yb_x)%5Chat%7B%5Cmathbf%7Bk%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Because%20by%20definition%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%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%3D%200%20%5C%5C%0A%20%20%20%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%2C%20%5Cquad%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%2C%20%5Cquad%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%3D%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%5C%5C%0A%20%20%20%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%3D%20-%5Chat%7B%5Cmathbf%7Bk%7D%7D%2C%20%5Cquad%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%3D%20-%5Chat%7B%5Cmathbf%7Bi%7D%7D%2C%20%5Cquad%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%5Ctimes%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%3D%20-%5Chat%7B%5Cmathbf%7Bj%7D%7D%0A%20%20%20%20%5Cend%7Barray%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20direction%20of%20the%20vector%20resulting%20from%20the%20cross%20product%20is%20given%20by%20the%20right-hand%20rule.%20Note%20the%20second%20and%20third%20rows%3A%20**the%20cross%20product%20does%20not%20commute.**%20Swapping%20the%20operands%20flips%20the%20result.%20If%20you%20have%20ever%20got%20a%20joint%20moment%20with%20the%20wrong%20sign%2C%20this%20is%20usually%20why.%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%20geometric%20equivalent%20of%20the%20cross%20product%20is%20the%20product%20of%20the%20magnitudes%20of%20the%20two%20vectors%20and%20the%20sine%20of%20the%20angle%20between%20them%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%7C%7C%20%3D%20%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7C%7C%5C%3A%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%7C%7C%5C%3A%5Csin(%5Ctheta)%0A%20%20%20%20%24%24%0A%0A%20%20%20%20which%20is%20also%20equivalent%20to%20stating%20that%20the%20magnitude%20of%20the%20cross%20product%20between%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20and%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20is%20the%20magnitude%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20times%20the%20magnitude%20of%20the%20component%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20perpendicular%20to%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20(or%20the%20magnitude%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20times%20the%20magnitude%20of%20the%20component%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20perpendicular%20to%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24).%0A%0A%20%20%20%20So%20the%20two%20products%20are%20complementary%3A%20the%20dot%20product%20keeps%20the%20parallel%20part%20and%20the%20cross%20product%20keeps%20the%20perpendicular%20one.%20Where%20the%20dot%20product%20vanishes%2C%20the%20cross%20product%20is%20largest%2C%20and%20the%20other%20way%20around.%0A%0A%20%20%20%20The%20definition%20above%20also%20implies%20that%20the%20magnitude%20of%20the%20cross%20product%20is%20the%20area%20of%20the%20parallelogram%20spanned%20by%20the%20two%20vectors%3A%0A%0A%20%20%20%20%3Cfigure%20aria-describedby%3D%22figure-caption-6%22%3E%3Ccenter%3E%3Cimg%20src%3D%22https%3A%2F%2Fupload.wikimedia.org%2Fwikipedia%2Fcommons%2F4%2F4e%2FCross_product_parallelogram.svg%22%20width%3D160%20alt%3D%22cross%20product%20parallelogram%22%2F%3E%3C%2Fcenter%3E%3C%2Ffigure%3E%0A%0A%20%20%20%20%3Cspan%20id%3D%22figure-caption-6%22%20class%3D%22figure-caption%22%20style%3D%22display%3Ablock%3Btext-align%3Acenter%3Bfont-style%3Aitalic%22%3EFigure.%20Area%20of%20a%20parallelogram%20as%20the%20magnitude%20of%20the%20cross%20product%20(image%20from%20Wikipedia).%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%20The%20cross%20product%20can%20also%20be%20calculated%20as%20the%20determinant%20of%20a%20matrix%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%20%5Cleft%7C%20%5Cbegin%7Barray%7D%7Bccc%7D%0A%20%20%20%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%26%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%26%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20%5C%5C%0A%20%20%20%20a_x%20%26%20a_y%20%26%20a_z%20%5C%5C%0A%20%20%20%20b_x%20%26%20b_y%20%26%20b_z%0A%20%20%20%20%5Cend%7Barray%7D%20%5Cright%7C%0A%20%20%20%20%3D%20a_y%20b_z%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20a_z%20b_x%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20a_x%20b_y%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20-%20a_y%20b_x%20%5Chat%7B%5Cmathbf%7Bk%7D%7D%20-%20a_z%20b_y%20%5Chat%7B%5Cmathbf%7Bi%7D%7D%20-%20a_x%20b_z%20%5Chat%7B%5Cmathbf%7Bj%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%20(a_yb_z-a_zb_y)%5Chat%7B%5Cmathbf%7Bi%7D%7D%20%2B%20(a_zb_x-a_xb_z)%5Chat%7B%5Cmathbf%7Bj%7D%7D%20%2B%20(a_xb_y-a_yb_x)%5Chat%7B%5Cmathbf%7Bk%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20same%20result%20as%20before.%20This%20is%20the%20form%20worth%20memorizing%2C%20because%20it%20is%20the%20one%20you%20can%20reconstruct%20under%20pressure.%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%20cross%20product%20between%20two%20vectors%20can%20be%20visualized%20in%20this%20interactive%20animation%3A%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.Html(%0A%20%20%20%20%20%20%20%20%22%22%22%3Ciframe%20src%3D%22https%3A%2F%2Fwww.geogebra.org%2Fclassic%2Fcz6v2U99%3Fembed%22%0A%20%20%20%20%20%20%20%20width%3D%22100%25%22%20height%3D%22500%22%20style%3D%22border%3Anone%22%3E%3C%2Fiframe%3E%22%22%22%0A%20%20%20%20)%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%20NumPy%20function%20for%20the%20cross%20product%20is%20%60numpy.cross%60%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20vec_a%2C%20vec_b)%3A%0A%20%20%20%20print(%22vec_a%20%3D%22%2C%20vec_a%2C%20%22%5Cnvec_b%20%3D%22%2C%20vec_b)%0A%20%20%20%20print(%22np.cross(vec_a%2C%20vec_b)%20%3D%22%2C%20np.cross(vec_a%2C%20vec_b))%0A%20%20%20%20print(%22np.cross(vec_b%2C%20vec_a)%20%3D%22%2C%20np.cross(vec_b%2C%20vec_a))%0A%20%20%20%20print(%0A%20%20%20%20%20%20%20%20%22np.dot(vec_a%2C%20np.cross(vec_a%2C%20vec_b))%20%3D%22%2C%0A%20%20%20%20%20%20%20%20np.dot(vec_a%2C%20np.cross(vec_a%2C%20vec_b))%2C%0A%20%20%20%20)%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%20last%20two%20lines%20are%20the%20two%20defining%20properties%2C%20checked%20numerically%3A%20reversing%20the%20operands%20negates%20the%20result%2C%20and%20the%20result%20is%20perpendicular%20to%20both%20inputs%2C%20so%20its%20dot%20product%20with%20either%20of%20them%20is%20zero.%0A%0A%20%20%20%20For%202D%20arrays%20with%20vectors%20in%20different%20rows%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np%2C%20pos_a%2C%20pos_b)%3A%0A%20%20%20%20np.cross(pos_a%2C%20pos_b%2C%20axis%3D1)%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**Challenge%203.**%20A%20force%20%24%5Coverrightarrow%7B%5Cmathbf%7BF%7D%7D%20%3D%20(0%2C%20-300%2C%200)%24%20N%20is%20applied%20at%20a%20point%20whose%20position%20relative%20to%20a%20joint%20centre%20is%20%24%5Coverrightarrow%7B%5Cmathbf%7Br%7D%7D%20%3D%20(0.25%2C%200%2C%200)%24%20m.%20The%20moment%20of%20that%20force%20about%20the%20joint%20is%20%24%5Coverrightarrow%7B%5Cmathbf%7BM%7D%7D%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Br%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7BF%7D%7D%24.%20Compute%20it.%20Then%20compute%20%24%5Coverrightarrow%7B%5Cmathbf%7BF%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Br%7D%7D%24%20and%20say%2C%20in%20words%2C%20what%20going%20about%20it%20the%20wrong%20way%20round%20claims%20physically.%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%204.**%20A%20force%20%24(0%2C10%2C0)%24%20N%20acts%20at%20%24(0.2%2C0%2C0)%24%20m%20from%20a%20pivot.%20Find%20its%20moment%20and%20explain%20the%20sign.%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%204%0A%20%20%20%20%24%5Cmathbf%20r%5Ctimes%5Cmathbf%20F%3D(0%2C0%2C2)%24%20Nm.%20With%20a%20right-handed%20frame%2C%20positive%20z%20is%20the%20sense%20of%20rotation%20produced%20by%20positive%20x%20crossed%20with%20positive%20y.%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%20Gram%E2%80%93Schmidt%20process%0A%0A%20%20%20%20Here%20is%20the%20payoff%2C%20and%20the%20reason%20the%20rest%20of%20this%20notebook%20exists.%0A%0A%20%20%20%20In%20three-dimensional%20motion%20analysis%20you%20place%20markers%20on%20a%20segment%20%E2%80%94%20three%20of%20them%2C%20say%2C%20on%20the%20thigh%20%E2%80%94%20and%20you%20need%20a%20*coordinate%20system*%20attached%20to%20that%20segment%3A%20three%20mutually%20perpendicular%20unit%20vectors%20that%20move%20with%20the%20bone.%20What%20you%20have%20is%20three%20points%2C%20in%20no%20particular%20arrangement%2C%20measured%20with%20error.%20What%20you%20need%20is%20an%20orthonormal%20basis.%20The%20%5BGram%E2%80%93Schmidt%20process%5D(https%3A%2F%2Fen.wikipedia.org%2Fwiki%2FGram%25E2%2580%2593Schmidt_process)%2C%20with%20a%20little%20help%20from%20the%20cross%20product%2C%20is%20how%20you%20get%20from%20one%20to%20the%20other.%0A%0A%20%20%20%20Given%20three%20vectors%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%2C%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%2C%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%24%20in%203D%20space%2C%20a%20basis%20%24%5C%7B%5Chat%7Be%7D_a%2C%20%5Chat%7Be%7D_b%2C%20%5Chat%7Be%7D_c%5C%7D%24%20can%20be%20found%20as%20follows.%20The%20first%20versor%20is%20in%20the%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20direction%20(or%20in%20the%20direction%20of%20any%20of%20the%20other%20vectors)%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Chat%7Be%7D_a%20%3D%20%5Cfrac%7B%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7D%7B%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%7C%7C%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20second%20versor%2C%20orthogonal%20to%20%24%5Chat%7Be%7D_a%24%2C%20can%20be%20found%20considering%20that%20we%20can%20express%20vector%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20in%20terms%20of%20a%20part%20along%20%24%5Chat%7Be%7D_a%24%20and%20a%20part%20perpendicular%20to%20it%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%5E%5C%7C%20%2B%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%5E%5Cbot%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Then%2C%20subtracting%20the%20parallel%20part%20%E2%80%94%20which%20the%20dot%20product%20hands%20us%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%5E%5Cbot%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20-%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%5E%5C%7C%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20-%20(%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%5Ccdot%20%5Chat%7Be%7D_a%20)%20%5Chat%7Be%7D_a%0A%20%20%20%20%24%24%0A%0A%20%20%20%20Finally%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Chat%7Be%7D_b%20%3D%20%5Cfrac%7B%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%5E%5Cbot%7D%7B%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%5E%5Cbot%7C%7C%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20third%20versor%2C%20orthogonal%20to%20both%20%24%5Chat%7Be%7D_a%24%20and%20%24%5Chat%7Be%7D_b%24%2C%20is%20found%20the%20same%20way%2C%20expressing%20%24%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%24%20in%20terms%20of%20the%20two%20directions%20already%20fixed%3A%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%5E%5C%7C%20%2B%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%5E%5Cbot%2C%0A%20%20%20%20%5Cqquad%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%5E%5C%7C%20%3D%20(%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%20%5Ccdot%20%5Chat%7Be%7D_a%20)%20%5Chat%7Be%7D_a%20%2B%20(%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%20%5Ccdot%20%5Chat%7Be%7D_b%20)%20%5Chat%7Be%7D_b%0A%20%20%20%20%24%24%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%5E%5Cbot%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%20-%20%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%5E%5C%7C%2C%0A%20%20%20%20%5Cqquad%0A%20%20%20%20%5Chat%7Be%7D_c%20%3D%20%5Cfrac%7B%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%5E%5Cbot%7D%7B%7C%7C%5Coverrightarrow%7B%5Cmathbf%7Bc%7D%7D%5E%5Cbot%7C%7C%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20The%20process%20works%20for%20any%20number%20of%20vectors%2C%20and%20the%20pattern%20never%20changes%3A%20take%20the%20next%20vector%2C%20subtract%20off%20everything%20that%20lies%20along%20the%20directions%20you%20already%20have%2C%20and%20normalize%20what%20is%20left.%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%20Let's%20implement%20the%20Gram%E2%80%93Schmidt%20process%20in%20Python%2C%20and%20use%20it%20for%20what%20the%20introduction%20promised%3A%20a%20coordinate%20system%20for%20a%20segment%20carrying%20three%20markers%20at%20the%20positions%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bm_1%7D%7D%20%3D%20%5B1%2C2%2C0%5D%2C%20%5Cquad%20%5Coverrightarrow%7B%5Cmathbf%7Bm_2%7D%7D%20%3D%20%5B0%2C1%2C3%5D%2C%20%5Cquad%20%5Coverrightarrow%7B%5Cmathbf%7Bm_3%7D%7D%20%3D%20%5B1%2C0%2C1%5D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20There%20is%20a%20trap%20to%20avoid%20first.%20A%20marker%20position%20is%20an%20arrow%20from%20the%20laboratory's%20origin%20to%20the%20marker%2C%20and%20where%20that%20origin%20lies%20is%20an%20accident%20of%20how%20the%20cameras%20were%20calibrated.%20Feed%20the%20three%20positions%20themselves%20to%20the%20Gram%E2%80%93Schmidt%20process%20and%20the%20basis%20inherits%20that%20accident%3A%20move%20the%20laboratory's%20origin%20and%20the%20%22segment%22%20axes%20turn%2C%20although%20the%20segment%20has%20not%20moved%20(%5BFrame%20of%20reference%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Freference_frame.py)%20demonstrates%20it).%20What%20belongs%20to%20the%20segment%20are%20the%20*differences*%20between%20markers%2C%20which%20are%20the%20same%20wherever%20the%20origin%20is.%20So%20the%20vectors%20we%20orthonormalize%20are%0A%0A%20%20%20%20%24%24%0A%20%20%20%20%5Coverrightarrow%7B%5Cmathbf%7Bd_1%7D%7D%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Bm_2%7D%7D%20-%20%5Coverrightarrow%7B%5Cmathbf%7Bm_1%7D%7D%2C%20%5Cquad%20%5Coverrightarrow%7B%5Cmathbf%7Bd_2%7D%7D%20%3D%20%5Coverrightarrow%7B%5Cmathbf%7Bm_3%7D%7D%20-%20%5Coverrightarrow%7B%5Cmathbf%7Bm_1%7D%7D%0A%20%20%20%20%24%24%0A%0A%20%20%20%20which%20play%20the%20roles%20of%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20and%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20in%20the%20equations%20above.%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(np)%3A%0A%20%20%20%20m1%20%3D%20np.array(%5B1%2C%202%2C%200%5D)%0A%20%20%20%20m2%20%3D%20np.array(%5B0%2C%201%2C%203%5D)%0A%20%20%20%20m3%20%3D%20np.array(%5B1%2C%200%2C%201%5D)%0A%0A%20%20%20%20d1%20%3D%20m2%20-%20m1%0A%20%20%20%20d2%20%3D%20m3%20-%20m1%0A%20%20%20%20return%20d1%2C%20d2%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%20first%20versor%20is%20simply%20the%20first%20vector%2C%20normalized%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(d1%2C%20np)%3A%0A%20%20%20%20e1%20%3D%20d1%20%2F%20np.linalg.norm(d1)%0A%0A%20%20%20%20print(e1)%0A%20%20%20%20return%20(e1%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%20second%20versor%20is%20the%20second%20vector%20with%20its%20%24%5Chat%7Be%7D_1%24%20component%20removed%2C%20then%20normalized%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(d2%2C%20e1%2C%20np)%3A%0A%20%20%20%20e2%20%3D%20d2%20-%20np.dot(d2%2C%20e1)%20*%20e1%0A%20%20%20%20e2%20%3D%20e2%20%2F%20np.linalg.norm(e2)%0A%0A%20%20%20%20print(e2)%0A%20%20%20%20return%20(e2%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%20With%20a%20third%20independent%20vector%2C%20the%20third%20versor%20would%20come%20from%20the%20third%20step%20above%2C%20removing%20both%20components%20already%20accounted%20for.%20But%20three%20markers%20give%20only%20two%20independent%20differences%3A%20the%20three%20points%20always%20lie%20in%20one%20plane%2C%20and%20%24%5Chat%7Be%7D_1%24%20and%20%24%5Chat%7Be%7D_2%24%20both%20lie%20in%20it.%20In%20three%20dimensions%20we%20do%20not%20need%20a%20third%20vector.%20The%20cross%20product%20of%20two%20perpendicular%20versors%20is%20a%20versor%20perpendicular%20to%20both%2C%20and%20it%20completes%20a%20right-handed%20basis%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(e1%2C%20e2%2C%20np)%3A%0A%20%20%20%20e3%20%3D%20np.cross(e1%2C%20e2)%0A%0A%20%20%20%20print(e3)%0A%20%20%20%20return%20(e3%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%20Never%20trust%20a%20basis%20you%20have%20not%20tested.%20Orthonormal%20means%20two%20things%20%E2%80%94%20every%20pair%20perpendicular%20(dot%20product%20zero)%20and%20every%20vector%20of%20unit%20length%20%E2%80%94%20so%20check%20both%3A%0A%20%20%20%20%22%22%22)%0A%20%20%20%20return%0A%0A%0A%40app.cell%0Adef%20_(e1%2C%20e2%2C%20e3%2C%20np)%3A%0A%20%20%20%20print(%22Versors%3A%22%2C%20%22%5Cne1%20%3D%22%2C%20e1%2C%20%22%5Cne2%20%3D%22%2C%20e2%2C%20%22%5Cne3%20%3D%22%2C%20e3)%0A%20%20%20%20print(%0A%20%20%20%20%20%20%20%20%22%5CnTest%20of%20orthogonality%20(dot%20product%20between%20versors)%3A%22%2C%0A%20%20%20%20%20%20%20%20%22%5Cne1%20.%20e2%3A%22%2C%20np.dot(e1%2C%20e2)%2C%0A%20%20%20%20%20%20%20%20%22%5Cne2%20.%20e3%3A%22%2C%20np.dot(e2%2C%20e3)%2C%0A%20%20%20%20%20%20%20%20%22%5Cne3%20.%20e1%3A%22%2C%20np.dot(e3%2C%20e1)%2C%0A%20%20%20%20)%0A%20%20%20%20print(%0A%20%20%20%20%20%20%20%20%22%5CnNorm%20of%20each%20versor%3A%22%2C%0A%20%20%20%20%20%20%20%20%22%5Cn%7C%7Ce1%7C%7C%20%3D%22%2C%20np.linalg.norm(e1)%2C%0A%20%20%20%20%20%20%20%20%22%5Cn%7C%7Ce2%7C%7C%20%3D%22%2C%20np.linalg.norm(e2)%2C%0A%20%20%20%20%20%20%20%20%22%5Cn%7C%7Ce3%7C%7C%20%3D%22%2C%20np.linalg.norm(e3)%2C%0A%20%20%20%20)%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%20dot%20products%20are%20not%20exactly%20zero%20and%20the%20norms%20are%20not%20exactly%20one%3B%20they%20are%20zero%20and%20one%20to%20about%20fifteen%20decimal%20places.%20That%20is%20floating-point%20arithmetic%2C%20not%20a%20failure%20of%20the%20method%2C%20and%20it%20is%20why%20orthogonality%20is%20tested%20with%20a%20tolerance%20rather%20than%20with%20%60%3D%3D%60.%0A%0A%20%20%20%20Or%20we%20can%20use%20the%20built-in%20QR%20factorization%20function%20from%20NumPy%2C%20which%20performs%20an%20equivalent%20orthogonalization%20of%20the%20columns%20of%20a%20matrix.%20Given%20the%20two%20differences%20as%20columns%2C%20it%20returns%20two%20orthonormal%20columns%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%20np)%3A%0A%20%20%20%20differences%20%3D%20np.column_stack((d1%2C%20d2))%0A%20%20%20%20Q%2C%20R%20%3D%20np.linalg.qr(differences)%0A%0A%20%20%20%20print(Q)%0A%20%20%20%20return%20(Q%2C)%0A%0A%0A%40app.cell%0Adef%20_(Q%2C%20e1%2C%20e2%2C%20np)%3A%0A%20%20%20%20q1%2C%20q2%20%3D%20Q%5B%3A%2C%200%5D%2C%20Q%5B%3A%2C%201%5D%0A%0A%20%20%20%20print(%22Versors%3A%22%2C%20%22%5Cnq1%20%3D%22%2C%20q1%2C%20%22%5Cnq2%20%3D%22%2C%20q2)%0A%20%20%20%20print(%22%5CnTest%20of%20orthogonality%20(the%20matrix%20Q'%20Q%20should%20be%20the%20identity)%3A%22)%0A%20%20%20%20print(np.dot(Q.T%2C%20Q))%0A%20%20%20%20print(%0A%20%20%20%20%20%20%20%20%22%5CnNorm%20of%20each%20versor%3A%22%2C%0A%20%20%20%20%20%20%20%20%22%5Cn%7C%7Cq1%7C%7C%20%3D%22%2C%20np.linalg.norm(q1)%2C%0A%20%20%20%20%20%20%20%20%22%5Cn%7C%7Cq2%7C%7C%20%3D%22%2C%20np.linalg.norm(q2)%2C%0A%20%20%20%20)%0A%20%20%20%20print(%22%5CnSame%20as%20the%20Gram-Schmidt%20versors%3F%22%2C%20np.allclose(q1%2C%20e1)%2C%20np.allclose(q2%2C%20e2))%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%20QR%20returned%20exactly%20the%20versors%20we%20built%20by%20hand.%20Do%20not%20count%20on%20it%3A%20QR%20is%20free%20to%20choose%20the%20opposite%20direction%20along%20each%20axis%2C%20and%20with%20other%20inputs%20it%20does.%20For%20a%20coordinate%20system%20attached%20to%20a%20body%20segment%2C%20that%20sign%20is%20the%20difference%20between%20an%20axis%20pointing%20forward%20and%20one%20pointing%20backward%2C%20so%20it%20is%20never%20a%20detail%20you%20can%20ignore.%0A%0A%20%20%20%20**Challenge%204.**%20The%20basis%20you%20built%20depends%20on%20the%20*order*%20of%20the%20differences%3A%20%24%5Chat%7Be%7D_1%24%20is%20exactly%20along%20%24%5Coverrightarrow%7B%5Cmathbf%7Bd_1%7D%7D%24%2C%20while%20%24%5Coverrightarrow%7B%5Cmathbf%7Bd_2%7D%7D%24%20only%20contributes%20whatever%20direction%20is%20left%20over.%20Redo%20the%20process%20with%20%24%5Coverrightarrow%7B%5Cmathbf%7Bd_2%7D%7D%24%20first%20and%20compare%20the%20two%20bases%3B%20then%20pass%20the%20differences%20to%20%60np.linalg.qr%60%20in%20that%20order%20too%2C%20and%20see%20what%20happens%20to%20the%20signs.%20Finally%2C%20ask%20the%20question%20that%20matters%20in%20practice%3A%20if%20one%20marker%20is%20noisier%20than%20the%20other%20two%2C%20which%20difference%20should%20go%20first%3F%0A%0A%20%20%20%20How%20these%20bases%20become%20anatomical%20frames%20of%20reference%20%E2%80%94%20and%20what%20to%20do%20when%20the%20markers%20move%20relative%20to%20the%20bone%20%E2%80%94%20is%20the%20subject%20of%20the%20notebook%20%5BFrame%20of%20reference%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Freference_frame.py).%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.**%20Apply%20Gram%E2%80%93Schmidt%20to%20%24(1%2C0%2C0)%24%20and%20%24(1%2C1%2C0)%24.%20What%20fails%20if%20the%20second%20input%20is%20%24(2%2C0%2C0)%24%3F%0A%0A%20%20%20%20%2F%2F%2F%20details%20%7C%20Solution%20to%20Exercise%205%0A%20%20%20%20The%20first%20unit%20vector%20is%20%24(1%2C0%2C0)%24.%20Removing%20its%20projection%20from%20%24(1%2C1%2C0)%24%20leaves%20%24(0%2C1%2C0)%24%2C%20already%20unit%20length.%20A%20parallel%20second%20input%20leaves%20zero%2C%20so%20no%20second%20direction%20can%20be%20constructed.%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%20Pause%20here%20before%20the%20problems.%0A%0A%20%20%20%201.%20Go%20back%20to%20the%20three%20quantities%20you%20listed%20in%20Challenge%200.%20Which%20are%20scalars%2C%20which%20are%20vectors%2C%20and%20was%20any%20of%20them%20harder%20to%20classify%20than%20you%20expected%3F%0A%20%20%20%202.%20You%20have%20two%20arrays%20of%20the%20same%20shape%20holding%20a%20force%20and%20a%20velocity%2C%20sampled%20over%20time.%20Write%20down%20the%20expression%20for%20the%20instantaneous%20power%20at%20every%20instant.%20Which%20product%20did%20you%20use%2C%20and%20why%20not%20the%20other%20one%3F%0A%20%20%20%203.%20Name%20a%20quantity%20whose%20magnitude%20you%20would%20report%20and%20whose%20direction%20you%20would%20discard%2C%20and%20a%20quantity%20for%20which%20discarding%20the%20direction%20would%20be%20malpractice.%0A%20%20%20%204.%20Why%20can%20the%20dot%20product%20be%20computed%20for%20vectors%20of%20any%20dimension%2C%20while%20the%20cross%20product%20as%20defined%20here%20is%20a%20strictly%20three-dimensional%20operation%3F%0A%20%20%20%205.%20Your%20code%20computes%20the%20angle%20between%20two%20segments%20and%20returns%201.05.%20What%20is%20missing%20from%20that%20statement%2C%20and%20what%20are%20the%20two%20most%20likely%20mistakes%20behind%20the%20number%3F%0A%20%20%20%206.%20Three%20markers%20on%20a%20rigid%20segment%20give%20you%20a%20basis.%20What%20would%20you%20check%2C%20frame%20by%20frame%2C%20to%20convince%20yourself%20the%20segment%20really%20is%20rigid%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%20%20%20%201.%20Mass%20and%20time%20are%20scalars%3B%20velocity%20and%20force%20are%20vectors.%20Position%20requires%20an%20origin%20and%20frame.%0A%20%20%20%202.%20For%20rows%20of%20samples%3A%20%60np.sum(force%20*%20velocity%2C%20axis%3D1)%60%2C%20a%20dot%20product%20per%20row.%20A%20cross%20product%20would%20give%20a%20vector%2C%20not%20power.%0A%20%20%20%203.%20Speed%20can%20be%20reported%20without%20direction%3B%20a%20force%20used%20for%20a%20joint%20moment%20cannot.%0A%20%20%20%204.%20The%20dot%20product%20sums%20matching%20components%20in%20any%20dimension%3B%20the%20right-hand-rule%20cross%20product%20used%20here%20maps%20two%20three-dimensional%20vectors%20to%20a%20third.%0A%20%20%20%205.%20State%20radians%20or%20degrees%2C%20the%20two%20segments%2C%20and%20the%20frame.%20Common%20errors%20are%20treating%20radians%20as%20degrees%20or%20using%20point%20coordinates%20instead%20of%20segment%20differences.%0A%20%20%20%206.%20Check%20pairwise%20marker%20distances%2C%20segment%20lengths%2C%20orthonormality%2C%20handedness%2C%20and%20continuity.%20An%20orthonormal%20basis%20alone%20does%20not%20prove%20the%20markers%20stayed%20rigidly%20attached.%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.%20Given%20the%20vectors%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%3D%5B1%2C%200%2C%200%5D%24%20and%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%3D%5B1%2C%201%2C%201%5D%24%2C%20calculate%20the%20dot%20and%20cross%20products%20between%20them.%0A%0A%20%20%20%202.%20Calculate%20the%20unit%20vectors%20for%20%24%5B2%2C%20-2%2C%203%5D%24%20and%20%24%5B3%2C%20-3%2C%202%5D%24%20and%20determine%20a%20vector%20orthogonal%20to%20these%20two%20vectors.%0A%0A%20%20%20%203.%20Given%20the%20vectors%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%3D%5B1%2C%200%2C%200%5D%24%20and%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%3D%5B1%2C%201%2C%201%5D%24%2C%20calculate%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24%20and%20verify%20that%20this%20vector%20is%20orthogonal%20to%20vectors%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20and%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24.%20Also%2C%20calculate%20%24%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%24%20and%20compare%20it%20with%20%24%5Coverrightarrow%7B%5Cmathbf%7Ba%7D%7D%20%5Ctimes%20%5Coverrightarrow%7B%5Cmathbf%7Bb%7D%7D%24.%0A%0A%20%20%20%204.%20Given%20the%20vectors%20%24%5B1%2C%201%2C%200%5D%24%2C%20%24%5B1%2C%200%2C%201%5D%24%20and%20%24%5B0%2C%201%2C%201%5D%24%2C%20calculate%20a%20basis%20using%20the%20Gram%E2%80%93Schmidt%20process.%0A%0A%20%20%20%205.%20Write%20a%20Python%20function%20to%20calculate%20a%20basis%20using%20the%20Gram%E2%80%93Schmidt%20process%20(implement%20the%20algorithm!)%2C%20considering%20that%20the%20input%20consists%20of%20three%20variables%2C%20each%20containing%20the%20coordinates%20of%20vectors%20as%20columns%20and%20different%20positions%20of%20these%20vectors%20as%20rows.%20For%20example%2C%20sample%20variables%20can%20be%20generated%20with%20the%20command%20%60np.random.randn(5%2C%203)%60.%0A%0A%20%20%20%206.%20A%20jumper%20leaves%20the%20ground%20with%20a%20velocity%20of%20%24(8.0%2C%203.5%2C%200.2)%24%20m%2Fs%2C%20as%20in%20this%20notebook.%20Using%20only%20the%20operations%20defined%20here%2C%20calculate%3A%20the%20component%20of%20that%20velocity%20along%20the%20direction%20%24(1%2C%200%2C%201)%2F%5Csqrt%7B2%7D%24%3B%20the%20angle%20between%20the%20velocity%20and%20the%20vertical%3B%20and%20the%20area%20of%20the%20parallelogram%20spanned%20by%20the%20velocity%20and%20the%20vertical%20versor.%20State%20what%2C%20if%20anything%2C%20each%20of%20the%20three%20means%20physically.%0A%0A%20%20%20%20If%20you%20are%20new%20to%20scalars%20and%20vectors%2C%20you%20should%20solve%20these%20problems%20first%20by%20hand%20and%20then%20use%20Python%20to%20check%20the%20answers.%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%20Problems%0A%20%20%20%201.%20Dot%20product%3A%201.%20Cross%20product%3A%20%24(0%2C-1%2C1)%24.%0A%20%20%20%202.%20%24(2%2C-2%2C3)%2F%5Csqrt%7B17%7D%24%20and%20%24(3%2C-3%2C2)%2F%5Csqrt%7B22%7D%24%3B%20an%20orthogonal%20vector%20is%20%24(1%2C1%2C0)%24.%0A%20%20%20%203.%20%24%5Cmathbf%20a%5Ctimes%5Cmathbf%20b%3D(0%2C-1%2C1)%24%2C%20with%20both%20dot%20products%20zero%3B%20%24%5Cmathbf%20b%5Ctimes%5Cmathbf%20a%3D(0%2C1%2C-1)%24.%0A%20%20%20%204.%20One%20ordered%20orthonormal%20basis%20is%20%24(1%2C1%2C0)%2F%5Csqrt2%24%2C%20%24(1%2C-1%2C2)%2F%5Csqrt6%24%2C%20and%20%24(-1%2C1%2C1)%2F%5Csqrt3%24.%0A%20%20%20%205.%20One%20final%20implementation%20(arrays%20contain%20one%20vector%20per%20row)%3A%0A%0A%20%20%20%20%60%60%60python%0A%20%20%20%20def%20basis_rows(a%2C%20b%2C%20c)%3A%0A%20%20%20%20%20%20%20%20def%20unit(v)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20lengths%20%3D%20np.linalg.norm(v%2C%20axis%3D1%2C%20keepdims%3DTrue)%0A%20%20%20%20%20%20%20%20%20%20%20%20if%20np.any(lengths%20%3C%3D%201e-12)%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20raise%20ValueError(%22Zero%20or%20dependent%20directions%22)%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20v%20%2F%20lengths%0A%20%20%20%20%20%20%20%20e1%20%3D%20unit(np.asarray(a%2C%20dtype%3Dfloat))%0A%20%20%20%20%20%20%20%20b%20%3D%20np.asarray(b%2C%20dtype%3Dfloat)%0A%20%20%20%20%20%20%20%20c%20%3D%20np.asarray(c%2C%20dtype%3Dfloat)%0A%20%20%20%20%20%20%20%20e2%20%3D%20unit(b%20-%20np.sum(b%20*%20e1%2C%20axis%3D1%2C%20keepdims%3DTrue)%20*%20e1)%0A%20%20%20%20%20%20%20%20e3%20%3D%20unit(c%20-%20np.sum(c%20*%20e1%2C%20axis%3D1%2C%20keepdims%3DTrue)%20*%20e1%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20-%20np.sum(c%20*%20e2%2C%20axis%3D1%2C%20keepdims%3DTrue)%20*%20e2)%0A%20%20%20%20%20%20%20%20return%20e1%2C%20e2%2C%20e3%0A%20%20%20%20%60%60%60%0A%0A%20%20%20%20The%20tolerance%20here%20is%20appropriate%20only%20for%20input%20directions%20on%20a%20comparable%2C%20ordinary%20numerical%20scale.%0A%0A%20%20%20%206.%20Signed%20projection%3A%205.7983%20m%2Fs%3B%20angle%20to%20the%20vertical%3A%2066.3772%C2%B0%3B%20cross-product%20magnitude%3A%208.0025%20m%2Fs.%20These%20represent%20velocity%20along%20the%20chosen%20direction%2C%20inclination%20from%20vertical%2C%20and%20magnitude%20perpendicular%20to%20vertical%3B%20the%20last%20is%20not%20a%20physical%20area%20in%20m%C2%B2%20because%20one%20factor%20is%20a%20dimensionless%20versor.%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%20Optional%20textbook%20practice%20retained%20from%20the%20original%20guide%3A%20study%20Ruina%20and%20Pratap%E2%80%99s%20sample%20problems%20**1.1%E2%80%931.9%2C%201.11%E2%80%931.12%2C%201.14%2C%201.17%E2%80%931.24**%20and%20exercises%20**1.1.1%E2%80%931.3.16**%20in%20the%20edition%20linked%20below.%20These%20are%20external%20assignments%2C%20not%20additional%20self-contained%20problems%20in%20this%20notebook%3B%20use%20the%20book%E2%80%99s%20statements%20and%20worked%20examples.%0A%0A%20%20%20%20-%20Read%20pages%2044-92%20of%20the%20first%20chapter%20of%20%5BRuina%20and%20Pratap's%20book%5D(https%3A%2F%2Fruina.tam.cornell.edu%2FBook%2Findex.html)%20about%20scalars%20and%20vectors%20in%20mechanics.%0A%20%20%20%20-%20%5BFrame%20of%20reference%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Freference_frame.py)%20%E2%80%94%20what%20the%20bases%20built%20here%20are%20for.%0A%20%20%20%20-%20%5BKinematics%20of%20a%20particle%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fkinematics_particle.py)%20%E2%80%94%20position%2C%20displacement%2C%20velocity%20and%20acceleration%20as%20vectors.%0A%20%20%20%20-%20%5BMatrix%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Fmatrix.py)%20and%20%5BRigid-body%20transformations%20in%203D%5D(https%3A%2F%2Fmolab.marimo.io%2Fgithub%2FBMClab%2FBMC%2Fblob%2Fmaster%2Fnotebooks%2Ftransformation_3d.py)%20%E2%80%94%20where%20these%20operations%20are%20assembled%20into%20rotations.%0A%0A%20%20%20%20%23%23%23%20Video%20lectures%20on%20the%20Internet%0A%0A%20%20%20%20-%20Khan%20Academy%3A%20%5BVectors%5D(https%3A%2F%2Fwww.khanacademy.org%2Fmath%2Falgebra-home%2Falg-vectors)%0A%20%20%20%20-%20%5BVectors%2C%20what%20even%20are%20they%3F%5D(https%3A%2F%2Fyoutu.be%2FfNk_zzaMoSs)%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%20Pratap%20R%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%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%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20app.run()%0A
925cfe4049a445eff435b44dd771b50a