76 \title[Solving Equations \& ODEs]{Python for Science and Engg:\\Solving Equations \& ODEs} |
76 \title[Solving Equations \& ODEs]{Python for Science and Engg:\\Solving Equations \& ODEs} |
77 |
77 |
78 \author[FOSSEE] {FOSSEE} |
78 \author[FOSSEE] {FOSSEE} |
79 |
79 |
80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} |
81 \date[] {08 March, 2010\\Day 1, Session 6} |
81 \date[] {02 April, 2010\\Day 1, Session 6} |
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
82 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
83 |
83 |
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
84 %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} |
85 %\logo{\pgfuseimage{iitmlogo}} |
85 %\logo{\pgfuseimage{iitmlogo}} |
86 |
86 |
237 \end{itemize} |
237 \end{itemize} |
238 \end{frame} |
238 \end{frame} |
239 |
239 |
240 \begin{frame}[fragile] |
240 \begin{frame}[fragile] |
241 \frametitle{\typ{fsolve}} |
241 \frametitle{\typ{fsolve}} |
242 Find the root of $sin(x)+cos^2(x)$ nearest to $0$ |
242 Find the root of $sin(z)+cos^2(z)$ nearest to $0$ |
243 \vspace{-0.1in} |
243 \vspace{-0.1in} |
244 \begin{center} |
244 \begin{center} |
245 \includegraphics[height=2.8in, interpolate=true]{data/fsolve} |
245 \includegraphics[height=2.8in, interpolate=true]{data/fsolve} |
246 \end{center} |
246 \end{center} |
247 \end{frame} |
247 \end{frame} |
248 |
248 |
249 \begin{frame}[fragile] |
249 \begin{frame}[fragile] |
250 \frametitle{\typ{fsolve}} |
250 \frametitle{\typ{fsolve}} |
251 Root of $sin(x)+cos^2(x)$ nearest to $0$ |
251 Root of $sin(z)+cos^2(z)$ nearest to $0$ |
252 \begin{lstlisting} |
252 \begin{lstlisting} |
253 In []: fsolve(sin(x)+cos(x)*cos(x), 0) |
253 In []: fsolve(sin(z)+cos(z)*cos(z), 0) |
254 NameError: name 'x' is not defined |
254 NameError: name 'z' is not defined |
255 \end{lstlisting} |
255 \end{lstlisting} |
256 \end{frame} |
256 \end{frame} |
257 |
257 |
258 \begin{frame}[fragile] |
258 \begin{frame}[fragile] |
259 \frametitle{\typ{fsolve}} |
259 \frametitle{\typ{fsolve}} |
260 \begin{lstlisting} |
260 \begin{lstlisting} |
261 In []: x = linspace(-pi, pi) |
261 In []: z = linspace(-pi, pi) |
262 In []: fsolve(sin(x)+cos(x)*cos(x), 0) |
262 In []: fsolve(sin(z)+cos(z)*cos(z), 0) |
263 \end{lstlisting} |
263 \end{lstlisting} |
264 \begin{small} |
264 \begin{small} |
265 \alert{\typ{TypeError:}} |
265 \alert{\typ{TypeError:}} |
266 \typ{'numpy.ndarray' object is not callable} |
266 \typ{'numpy.ndarray' object is not callable} |
267 \end{small} |
267 \end{small} |
299 More on Functions later \ldots |
299 More on Functions later \ldots |
300 \end{frame} |
300 \end{frame} |
301 |
301 |
302 \begin{frame}[fragile] |
302 \begin{frame}[fragile] |
303 \frametitle{\typ{fsolve} \ldots} |
303 \frametitle{\typ{fsolve} \ldots} |
304 Find the root of $sin(x)+cos^2(x)$ nearest to $0$ |
304 Find the root of $sin(z)+cos^2(z)$ nearest to $0$ |
305 \begin{lstlisting} |
305 \begin{lstlisting} |
306 In []: fsolve(f, 0) |
306 In []: fsolve(f, 0) |
307 Out[]: -0.66623943249251527 |
307 Out[]: -0.66623943249251527 |
308 \end{lstlisting} |
308 \end{lstlisting} |
309 \begin{center} |
309 \begin{center} |
311 \end{center} |
311 \end{center} |
312 \end{frame} |
312 \end{frame} |
313 |
313 |
314 \begin{frame}[fragile] |
314 \begin{frame}[fragile] |
315 \frametitle{Exercise Problem} |
315 \frametitle{Exercise Problem} |
316 Find the root of the equation $x^2 - sin(x) + cos^2(x)$ nearest to $0$ |
316 Find the root of the equation $x^2 - sin(x) + cos^2(x) == tan(x)$ nearest to $0$ |
317 \end{frame} |
317 \end{frame} |
318 |
318 |
319 \begin{frame}[fragile] |
319 \begin{frame}[fragile] |
320 \frametitle{Solution} |
320 \frametitle{Solution} |
321 \begin{small} |
321 \begin{small} |
322 \begin{lstlisting} |
322 \begin{lstlisting} |
323 def f(x): |
323 def f(x): |
324 return x**2 - sin(x) + cos(x)*cos(x) |
324 return x**2 - sin(x) + cos(x)*cos(x) - tan(x) |
325 fsolve(f, 0) |
325 fsolve(f, 0) |
326 \end{lstlisting} |
326 \end{lstlisting} |
327 \end{small} |
327 \end{small} |
328 \begin{center} |
328 \begin{center} |
329 \includegraphics[height=2in, interpolate=true]{data/fsolve_tanx} |
329 \includegraphics[height=2in, interpolate=true]{data/fsolve_tanx} |
330 \end{center} |
330 \end{center} |