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