136 \end{itemize} |
136 \end{itemize} |
137 \begin{align} |
137 \begin{align} |
138 \dot{\theta} &= \omega \\ |
138 \dot{\theta} &= \omega \\ |
139 \dot{\omega} &= -\frac{g}{L}sin(\theta) \\ |
139 \dot{\omega} &= -\frac{g}{L}sin(\theta) \\ |
140 \text{At}\ t &= 0 : \nonumber \\ |
140 \text{At}\ t &= 0 : \nonumber \\ |
141 \theta = \theta_0\quad & \&\quad \omega = 0 \nonumber |
141 \theta = \theta_0(10^o)\quad & \&\quad \omega = 0\ (Initial\ values)\nonumber |
142 \end{align} |
142 \end{align} |
143 \end{frame} |
143 \end{frame} |
144 |
144 |
145 \begin{frame}[fragile] |
145 \begin{frame}[fragile] |
146 \frametitle{Solving ODEs using SciPy} |
146 \frametitle{Solving ODEs using SciPy} |
147 \begin{itemize} |
147 \begin{itemize} |
148 \item We use the \typ{odeint} function from scipy to do the integration |
148 \item We use the \typ{odeint} function from scipy to do the integration |
149 \item Define a function as below |
149 \item Define a function as below |
150 \end{itemize} |
150 \end{itemize} |
151 \begin{lstlisting} |
151 \begin{lstlisting} |
152 In []: def pend_int(unknown, t, p): |
152 In []: def pend_int(initial, t): |
153 .... theta, omega = unknown |
153 .... theta, omega = initial |
154 .... g, L = p |
154 .... g, L = -9.81, 0.2 |
155 .... f=[omega, -(g/L)*sin(theta)] |
155 .... f=[omega, -(g/L)*sin(theta)] |
156 .... return f |
156 .... return f |
157 .... |
157 .... |
158 \end{lstlisting} |
158 \end{lstlisting} |
159 \end{frame} |
159 \end{frame} |
160 |
160 |
161 \begin{frame}[fragile] |
161 \begin{frame}[fragile] |
162 \frametitle{Solving ODEs using SciPy \ldots} |
162 \frametitle{Solving ODEs using SciPy \ldots} |
163 \begin{itemize} |
163 \begin{itemize} |
164 \item \typ{t} is the time variable \\ |
164 \item \typ{t} is the time variable \\ |
165 \item \typ{p} has the constants \\ |
|
166 \item \typ{initial} has the initial values |
165 \item \typ{initial} has the initial values |
167 \end{itemize} |
166 \end{itemize} |
168 \begin{lstlisting} |
167 \begin{lstlisting} |
169 In []: t = linspace(0, 10, 101) |
168 In []: t = linspace(0, 10, 101) |
170 In []: p=(-9.81, 0.2) |
|
171 In []: initial = [10*2*pi/360, 0] |
169 In []: initial = [10*2*pi/360, 0] |
172 \end{lstlisting} |
170 \end{lstlisting} |
173 \end{frame} |
171 \end{frame} |
174 |
172 |
175 \begin{frame}[fragile] |
173 \begin{frame}[fragile] |
176 \frametitle{Solving ODEs using SciPy \ldots} |
174 \frametitle{Solving ODEs using SciPy \ldots} |
177 \begin{small} |
175 %%\begin{small} |
178 \typ{In []: from scipy.integrate import odeint} |
176 \typ{In []: from scipy.integrate import odeint} |
179 \end{small} |
177 %%\end{small} |
180 \begin{lstlisting} |
178 \begin{lstlisting} |
181 In []: pend_sol = odeint(pend_int, |
179 In []: pend_sol = odeint(pend_int, |
182 initial,t, |
180 initial,t) |
183 args=(p,)) |
|
184 \end{lstlisting} |
181 \end{lstlisting} |
185 \end{frame} |
182 \end{frame} |
186 |
183 |
187 \section{Finding Roots} |
184 \section{Finding Roots} |
188 |
185 |
306 \end{frame} |
303 \end{frame} |
307 |
304 |
308 \begin{frame}[fragile] |
305 \begin{frame}[fragile] |
309 \frametitle{Initial Estimates \ldots} |
306 \frametitle{Initial Estimates \ldots} |
310 \begin{lstlisting} |
307 \begin{lstlisting} |
311 In []: def our_f(x): |
308 In []: def our_f(x): |
312 ....: return cos(x)-x**2 |
309 ....: return cos(x) - x*x |
313 ....: |
310 ....: |
314 In []: x = linspace(-pi/2, pi/2, 11) |
311 In []: x = linspace(-pi/2, pi/2, 11) |
315 \end{lstlisting} |
312 In []: y = our_f(x) |
316 \begin{itemize} |
313 \end{lstlisting} |
317 \item Get the intervals of x, where sign changes occur |
314 Get the intervals of x, where sign changes occur |
318 \end{itemize} |
|
319 \end{frame} |
315 \end{frame} |
320 |
316 |
321 \begin{frame}[fragile] |
317 \begin{frame}[fragile] |
322 \frametitle{Initial Estimates \ldots} |
318 \frametitle{Initial Estimates \ldots} |
323 \begin{lstlisting} |
319 \begin{lstlisting} |