-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightning-talk-2024.py
220 lines (164 loc) · 4.72 KB
/
lightning-talk-2024.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import marimo
__generated_with = "0.9.1"
app = marimo.App(app_title="Bicycle Integral")
@app.cell
def __():
import sympy as sp
import marimo as mo
import matplotlib.pyplot as plt
return mo, plt, sp
@app.cell(hide_code=True)
def __(mo):
mo.md(
r"""
# Una Elegante Integral Escondida En Una Bicicleta
### Enrique Millan Valbuena
### web.adapting.dev
---
"""
)
return
@app.cell(hide_code=True)
def __(mo):
mo.image("/Users/valbuena/git/github.com/pycones24-lightning-talk/diagram.png", rounded=True)
return
@app.cell(hide_code=True)
def __(mo):
mo.md(
r"""
## Estrategia
1. **No-deslizamiento**
1. Construir un **triángulo**
1. Encontrar el **centro instantáneo de rotación** (CIR).
### **CIR + punto velocidad conocida = velocidad angular**.
¡Empezamos!
"""
)
return
@app.cell(hide_code=True)
def __(mo):
mo.image("/Users/valbuena/git/github.com/pycones24-lightning-talk/diagram-cropped.png", height=400)
return
@app.cell(hide_code=True)
def __(mo):
mo.md(
r"""
## Cálculo de $\phi(t)$
La altura $H(\phi)$ es la suma de dos lados de cada triángulo, $p(\phi)$ y $q(\phi)$,
$$
\begin{align}
H(\phi) &= p(\phi) + q(\phi) \\
H(\phi) &= \sin{\left(\phi \right)} \tan{\left(\phi \right)} + \cos{\left(\phi \right)}
\end{align}
$$
Conocido $H(\phi)$, tenemos una ecuación diferencial para hallar $\phi(t)$:
$$
\begin{align}
H(\phi) \frac{d\phi}{dt} &= v_0 \\
\int \left(\sin{\left(\phi \right)} \tan{\left(\phi \right)} + \cos{\left(\phi \right)}\right) d\phi &= v_0 t + C
\end{align}
$$
"""
)
return
@app.cell
def __(sp):
phi, t, x, y = sp.symbols("phi, t, x, y")
return phi, t, x, y
@app.cell
def __(phi, sp, t):
xM = t - sp.sin(phi)
yM = sp.cos(phi)
return xM, yM
@app.cell(hide_code=True)
def __(mo):
mo.md(
r"""
Con SymPy, podemos obtener la primitiva de esta función:
$$
\int \left(\sin{\left(\phi \right)} \tan{\left(\phi \right)} + \cos{\left(\phi \right)}\right) d\phi
=
\frac{1}{2}\ln{\left(\frac{\sin{\left(\phi \right)} + 1}{\sin{\left(\phi \right)} - 1} \right)}
$$
"""
)
return
@app.cell(hide_code=True)
def __(phi, sp):
p_phi = sp.sin(phi) * sp.tan(phi)
q_phi = sp.cos(phi)
H_phi = p_phi + q_phi
primitive = sp.logcombine(sp.integrate(H_phi), force=True)
primitive
return H_phi, p_phi, primitive, q_phi
@app.cell(hide_code=True)
def __(mo):
mo.md(r"""**Nota:** han sido mejores los resultados de SymPy que de WolframAlpha.""")
return
@app.cell(hide_code=True)
def __(mo):
mo.image("/Users/valbuena/git/github.com/pycones24-lightning-talk/wolfram-alpha.png", height=300)
return
@app.cell(hide_code=True)
def __(mo):
mo.md(
r"""
Nos queda un último paso, despejar $\phi(t)$:
$$
\begin{align}
\frac{1}{2}\ln{\left(\frac{\sin{\left(\phi \right)} + 1}{\sin{\left(\phi \right)} - 1} \right)} &= t
\\[5mm]
\phi(t) &= \sin^{-1}{\left(\tanh{\left(t \right)} \right)}
\end{align}
$$
"""
)
return
@app.cell
def __(phi, sp, t):
solutions = sp.solve((1+sp.sin(phi))/(1-sp.sin(phi))-sp.exp(2*t),phi)
return (solutions,)
@app.cell
def __(solutions):
solutions
return
@app.cell(hide_code=True)
def __(mo):
mo.md(r"""SymPy nos da **dos** soluciones, las **cuestiones con ángulos** a menudo tienen **solución** pero no **unicidad**.""")
return
@app.cell(hide_code=True)
def __(solutions, sp, t):
phi_time = solutions[1]
sp.plot(phi_time, sp.pi/2,(t, 0, 8), title="Bicycle angle $\phi$ in time", xlabel="Time", ylabel="$\phi [rad]$", size=(7,3))
return (phi_time,)
@app.cell(hide_code=True)
def __(phi, phi_time, sp, t, xM, yM):
xM_time = xM.subs(phi, phi_time)
yM_time = yM.subs(phi, phi_time)
sp.plot_parametric(xM_time, yM_time, (t, 0, 8), title = "Trajectory of the rear tyre", xlabel="Time", ylabel= "Movement of Point M", size=(7,3))
return xM_time, yM_time
@app.cell(hide_code=True)
def __(mo):
mo.md(
r"""
### Ecuaciones originales (dos parámetros no independientes)
$$
\begin{align}
x_M &= t - \sin(\phi)
\\
y_M &= \cos(\phi)
\end{align}
$$
### Ecuaciones paramétricas finales
$$
\begin{align}
x_M &= t - \tanh(t)
\\
y_M &= \sqrt{1-\tanh^2(t)}
\end{align}
$$
"""
)
return
if __name__ == "__main__":
app.run()