# HG changeset patch # User Puneeth Chaganti # Date 1257308581 -19800 # Node ID 28d4714a97021026bab967b5c165cdcfca34e7d1 # Parent ac31e2f3754e77a10d8619bf5cd50ddbfbdec0eb# Parent 8a4a1e5aec857cc567aaedcdcc2ae25140bf11ae Merged with mainline. diff -r 8a4a1e5aec85 -r 28d4714a9702 day1/cheatsheet1.tex --- a/day1/cheatsheet1.tex Wed Nov 04 09:40:28 2009 +0530 +++ b/day1/cheatsheet1.tex Wed Nov 04 09:53:01 2009 +0530 @@ -2,54 +2,43 @@ \title{Interactive Plotting} \author{FOSSEE} \begin{document} -\maketitle +\date{} +\vspace{-1in} +\begin{center} +\LARGE{Interactive Plotting}\\ +\large{FOSSEE} +\end{center} +\section{Starting up...} -\section{Starting up...} \begin{verbatim} $ ipython -pylab \end{verbatim} -Exiting Ipython +Exiting \begin{verbatim} - In [1]: print "Hello, World!" - In [2]: ^D - Do you really want to exit ([y]/n)? y +In [2]: (Ctrl-D)^D +Do you really want to exit ([y]/n)? y \end{verbatim} Breaking out of loops \begin{verbatim} - In [1]: while True: - ...: print "Hello, World!" - ...: - Hello, World! - Hello, World!^C -\end{verbatim} - -\section{First Plot} -\begin{verbatim} - In [2]: x=linspace(0, 2*pi, 50) - - In [3]: plot(x,sin(x)) - Out[3]: [] +In [1]: while True: + ...: print "Hello, World!" + ...: +Hello, World! +Hello, World!(Ctrl-C)^C \end{verbatim} -\section{Labeling} -\begin{verbatim} - In [4]: xlabel('x') - - In [5]: ylabel('sin(x)') -\end{verbatim} - -\section{Another example} +\section{Plotting} \begin{verbatim} -In [6]: clf() - -In [7]: y = linspace(0,10,101) - -In [8]: plot(y, exp(-y)) - -In [9]: xlabel('y') - -In [10]: ylabel(r'$e^{-y}$') +In [1]: x = linspace(0, 2*pi, 50) +In [2]: plot(x,sin(x)) +In [3]: xlabel('x') +In [4]: ylabel('sin(x)') +In [5]: legend(['x', '-x', 'sin(x)', 'xsin(x)']) +In [6]: annotate('origin', xy=(0, 0), xytext=(0, -7), + arrowprops=dict(shrink=0.05)) +In [7]: xlim(5*pi, 5*pi) +In [8]: ylim(5*pi, 5*pi) +In [9]: clf() #Clears the Plot area \end{verbatim} - \end{document} diff -r 8a4a1e5aec85 -r 28d4714a9702 day1/data/annotate.png Binary file day1/data/annotate.png has changed diff -r 8a4a1e5aec85 -r 28d4714a9702 day1/data/interpolate.png diff -r 8a4a1e5aec85 -r 28d4714a9702 day1/data/missing_points.png diff -r 8a4a1e5aec85 -r 28d4714a9702 day1/session1.tex --- a/day1/session1.tex Wed Nov 04 09:40:28 2009 +0530 +++ b/day1/session1.tex Wed Nov 04 09:53:01 2009 +0530 @@ -49,7 +49,7 @@ } \newcounter{time} \setcounter{time}{0} -\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} +\newcommand{%\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} \newcommand{\typ}[1]{\lstinline{#1}} @@ -77,7 +77,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {31, October 2009\\Day 1, Session 1} +\date[] {31 October, 2009\\Day 1, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -106,7 +106,7 @@ % the following command: %\beamerdefaultoverlayspecification{<+->} -%\includeonlyframes{current,current1,current2,current3,current4,current5,current6} +%%\includeonlyframes{current,current1,current2,current3,current4,current5,current6} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % DOCUMENT STARTS @@ -129,10 +129,10 @@ \item[Session 2] Sat 10:05--11:05 \item[Session 3] Sat 11:20--12:20 \item[Session 4] Sat 12:25--13:25 - \item[Quiz -1] Sat 14:25--14:40 + \item[Quiz 1] Sat 14:25--14:40 \item[Session 5] Sat 14:40--15:40 \item[Session 6] Sat 15:55--16:55 - \item[Quiz -2] Sat 17:00--17:15 + \item[Quiz 2] Sat 17:00--17:15 \end{description} \end{frame} @@ -143,10 +143,10 @@ \item[Session 2] Sun 10:05--11:05 \item[Session 3] Sun 11:20--12:20 \item[Session 4] Sun 12:25--13:25 - \item[Quiz -1] Sun 14:25--14:40 + \item[Quiz 1] Sun 14:25--14:40 \item[Session 5] Sun 14:40--15:40 \item[Session 6] Sun 15:55--16:55 - \item[Quiz -2] Sun 17:00--17:15 + \item[Quiz 2] Sun 17:00--17:15 \end{description} \end{frame} @@ -161,9 +161,9 @@ \begin{block}{Goal: Successful participants will be able to} \begin{itemize} - \item Use Python as plotting, computational toolkit - \item Understand how Python can be used as scripting and problem solving language. - \item Train the students to use Python for the same + \item Use Python as plotting, computational tool + \item Understand how Python can be used as a scripting and problem solving language. + \item Train students for the same \end{itemize} \end{block} \end{frame} @@ -172,14 +172,25 @@ \begin{frame} \frametitle{Checklist} \begin{enumerate} - \item IPython: Type ipython at the command line. Is it available? + \item IPython \item Editor: We recommend scite. - \item Data files: Make sure you have all data files. + \item Data files: + \begin{itemize} + \item \typ{sslc1.txt} + \item \typ{pendulum.txt} + \item \typ{points.txt} + \item \typ{pos.txt} + \end{itemize} + \item Python scripts: + \begin{itemize} + \item \typ{sslc_allreg.py} + \item \typ{sslc_science.py} + \end{itemize} \end{enumerate} \end{frame} \begin{frame}[fragile] -\frametitle{Starting up...} +\frametitle{Starting up \ldots} \begin{block}{} \begin{verbatim} $ ipython -pylab @@ -196,20 +207,20 @@ \end{lstlisting} \end{frame} -\begin{frame}[fragile] -\frametitle{Loops} -Breaking out of loops -\begin{lstlisting} - In []: while True: - ...: print "Hello, World!" - ...: - Hello, World! - Hello, World!^C(Ctrl-C) - ------------------------------------ - KeyboardInterrupt +%% \begin{frame}[fragile] +%% \frametitle{Loops} +%% Breaking out of loops +%% \begin{lstlisting} +%% In []: while True: +%% ...: print "Hello, World!" +%% ...: +%% Hello, World! +%% Hello, World!^C(Ctrl-C) +%% ------------------------------------ +%% KeyboardInterrupt -\end{lstlisting} -\end{frame} +%% \end{lstlisting} +%% \end{frame} \section{Plotting} @@ -224,7 +235,7 @@ \begin{block}{} \begin{small} \begin{lstlisting} -In []: x = linspace(0, 2*pi, 51) +In []: x = linspace(0, 2*pi, 50) In []: plot(x, sin(x)) \end{lstlisting} \end{small} @@ -246,6 +257,7 @@ \begin{block}{\typ{plot(x, y)}} plots \typ{x} and \typ{y} using default line style and color \end{block} +%\inctime{10} \end{frame} \subsection{Decoration} @@ -279,12 +291,11 @@ \begin{lstlisting} In []: clf() #Clears the plot area. -In []: y = linspace(0, 2*pi, 51) +In []: y = linspace(0, 2*pi, 50) In []: plot(y, sin(2*y)) In []: xlabel('y') In []: ylabel('sin(2y)') \end{lstlisting} -\emphbar{By default plots would be overlaid!} \end{frame} \subsection{More decoration} @@ -308,11 +319,10 @@ \begin{frame}[fragile] \frametitle{Legend Placement} - \begin{block}{} \small \begin{lstlisting} -In []: legend(['sin(2y)'], loc='center') +In []: legend(['sin(2y)'], loc = 'center') \end{lstlisting} \end{block} @@ -348,6 +358,7 @@ \begin{center} \includegraphics[height=2in, interpolate=true]{data/loc} \end{center} +%\inctime{10} \end{frame} \begin{frame}[fragile] @@ -361,8 +372,22 @@ \section{Multiple plots} \begin{frame}[fragile] +\frametitle{Overlaid Plots} +\begin{lstlisting} +In []: clf() +In []: plot(y, sin(y)) +In []: plot(y, cos(y)) +In []: xlabel('y') +In []: ylabel('f(y)') +In []: legend(['sin(y)', 'cos(y)']) +\end{lstlisting} +\emphbar{By default plots would be overlaid!} +\end{frame} + +\begin{frame}[fragile] \frametitle{Plotting separate figures} \begin{lstlisting} +In []: clf() In []: figure(1) In []: plot(y, sin(y)) In []: figure(2) @@ -381,23 +406,20 @@ In []: plot(y, sin(y), 'g') In []: clf() -In []: plot(y, sin(y), linewidth=2) +In []: plot(y, sin(y), 'g', linewidth=2) \end{lstlisting} \vspace*{-0.2in} \begin{center} \includegraphics[height=2.2in, interpolate=true]{data/green} \end{center} +%\inctime{10} \end{frame} \begin{frame}[fragile] \frametitle{Annotating} \vspace*{-0.15in} \begin{lstlisting} -In []: annotate('local max', - xy=(1.5, 1), - xytext=(2.5, .8), - arrowprops=dict( - shrink=0.05),) +In []: annotate('local max', xy=(1.5, 1)) \end{lstlisting} \vspace*{-0.2in} \begin{center} @@ -415,7 +437,7 @@ In []: xmax = 2*pi #Set the axes limits In []: xlim(xmin, xmax) -In []: ylim(ymin, ymax) +In []: ylim(ymin-0.2, ymax+0.2) \end{lstlisting} \end{frame} @@ -428,34 +450,29 @@ \item Set axis limits to the range of x \end{enumerate} \begin{lstlisting} -In []: x=linspace(-5*pi, 5*pi, 501) +In []: x=linspace(-5*pi, 5*pi, 500) In []: plot(x, x, 'b') In []: plot(x, -x, 'b') \end{lstlisting} $\vdots$ \end{frame} -\section{Exercises} \begin{frame}[fragile] \frametitle{Review Problem \ldots} -\small{ \begin{lstlisting} In []: plot(x, sin(x), 'g', linewidth=2) -In []: plot(x, x*sin(x), 'r', linewidth=3) +In []: plot(x, x*sin(x), 'r', + linewidth=3) \end{lstlisting} - \begin{lstlisting} -In []: legend(['x', '-x', 'sin(x)', 'xsin(x)']) -In []: annotate('origin', - xy=(0, 0), - xytext=(0, -7), - arrowprops=dict( - shrink=0.05)) -In []: xlim(5*pi, 5*pi) -In []: ylim(5*pi, 5*pi) +In []: legend(['x', '-x', 'sin(x)', + 'xsin(x)']) +In []: annotate('origin', xy = (0, 0)) +In []: xlim(-5*pi, 5*pi) +In []: ylim(-5*pi, 5*pi) \end{lstlisting} -} \end{frame} + \begin{frame} \frametitle{What did we learn?} \begin{itemize} @@ -467,6 +484,7 @@ \begin{block}{Note} \centerline{\alert{Don't Close \typ{IPython}}} \end{block} +%%\inctime{10} \end{frame} \end{document} diff -r 8a4a1e5aec85 -r 28d4714a9702 day1/session5.tex --- a/day1/session5.tex Wed Nov 04 09:40:28 2009 +0530 +++ b/day1/session5.tex Wed Nov 04 09:53:01 2009 +0530 @@ -169,7 +169,6 @@ \item It contains x,y position of particle. \item Plot the given points. %% \item Interpolate the missing region. -%% load txt the unpack part. \end{itemize} \begin{lstlisting} In []: x, y = loadtxt('points.txt', @@ -214,8 +213,6 @@ %% \end{lstlisting} %% \end{frame} -%%better example, maybe parabola - \begin{frame}[fragile] \frametitle{Spline Interpolation} \begin{small} @@ -246,27 +243,20 @@ \frametitle{\typ{splev}} To Evaluate a spline and it's derivatives \begin{lstlisting} -In []: Xnew = linspace(0.01,3,100) +In []: Xnew = arange(0.01,3,0.02) In []: Ynew = splev(Xnew, tck) In []: y.shape Out[]: (40,) In []: Ynew.shape -Out[]: (100,) +Out[]: (150,) -In []: plot(Xnew, Ynew, '+') +In []: plot(Xnew, Ynew) \end{lstlisting} \end{frame} -\begin{frame} - \frametitle{Interpolated data} - \begin{center} - \includegraphics[height=2in, interpolate=true]{data/interpolate} - \end{center} -\end{frame} - %% \begin{frame}[fragile] %% \frametitle{Interpolation \ldots} %% \begin{itemize} @@ -274,6 +264,13 @@ %% \end{itemize} %% \end{frame} +\begin{frame} + \frametitle{Plot} + \begin{center} + \includegraphics[height=2in, interpolate=true]{data/interpolate} + \end{center} +\end{frame} + \section{Differentiation} \begin{frame}[fragile] @@ -310,8 +307,9 @@ In []: plot(x, y) In []: plot(x[:-1], fD) \end{lstlisting} +\vspace{-.2in} \begin{center} - \includegraphics[height=2in, interpolate=true]{data/fwdDiff} + \includegraphics[height=1.8in, interpolate=true]{data/fwdDiff} \end{center} \end{frame} @@ -341,12 +339,14 @@ \frametitle{Example \ldots} \begin{itemize} \item Read the file -\item Obtain an array of X, Y(S) +\item Obtain an array of X, Y \item Obtain velocity and acceleration \item use \typ{deltaT = 0.05} \end{itemize} \begin{lstlisting} -In []: S = loadtxt('location.txt') +In []: data = loadtxt('pos.txt') +In []: X,Y = data[:,0], data[:,1] +In []: S = array([X, Y]) \end{lstlisting} \end{frame} @@ -360,7 +360,19 @@ In []: a = (v[:,1:]-v[:,:-1])/deltaT \end{lstlisting} -Try Plotting the position, velocity \& acceleration. +\end{frame} + +\begin{frame}[fragile] +\frametitle{Example \ldots} +Plotting Y, $v_y$, $a_y$ +\begin{lstlisting} +In []: plot(Y) +In []: plot(v[1,:]) +In []: plot(a[1,:]) +\end{lstlisting} +\begin{center} + \includegraphics[height=1.8in, interpolate=true]{data/pos_vel_accel} +\end{center} \end{frame} \section{Quadrature} @@ -376,8 +388,8 @@ \item Inputs - function to integrate, limits \end{itemize} \begin{lstlisting} -%% In []: quad(sin(x)+x**2, 0, 1) -%% NameError: name 'x' is not defined +In []: quad(sin(x)+x**2, 0, 1) +NameError: name 'x' is not defined In []: x = 0 In []: quad(sin(x)+x**2, 0, 1) \end{lstlisting} @@ -439,7 +451,9 @@ \item Functions \begin{itemize} \item Definition - \item Calling + \item Calling + \item Default Arguments + \item Keyword Arguments \end{itemize} \item Quadrature \end{itemize} diff -r 8a4a1e5aec85 -r 28d4714a9702 day1/session6.tex --- a/day1/session6.tex Wed Nov 04 09:40:28 2009 +0530 +++ b/day1/session6.tex Wed Nov 04 09:53:01 2009 +0530 @@ -123,7 +123,6 @@ %% % You might wish to add the option [pausesections] %% \end{frame} -%%more exercise on plotting \section{ODEs} \begin{frame}[fragile] @@ -152,7 +151,7 @@ \begin{lstlisting} In []: def pend_int(initial, t): .... theta, omega = initial - .... g, L = 9.81, 0.2 + .... g, L = -9.81, 0.2 .... f=[omega, -(g/L)*sin(theta)] .... return f ....