day1/session2.tex
changeset 373 f04eca8b2f3d
parent 366 ec4cb3ba7f09
child 378 2299700a8b97
equal deleted inserted replaced
372:5f02dfb93df1 373:f04eca8b2f3d
    76 \title[Plotting with Python]{Python for Science and Engg: Plotting experimental data}
    76 \title[Plotting with Python]{Python for Science and Engg: Plotting experimental data}
    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[] {28 January, 2010\\Day 1, Session 2}
    81 \date[] {12 February, 2010\\Day 1, Session 2}
    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 
   206 \begin{lstlisting}
   206 \begin{lstlisting}
   207 In []: mtlist = [] 
   207 In []: mtlist = [] 
   208 \end{lstlisting}
   208 \end{lstlisting}
   209 \emphbar{Empty List}
   209 \emphbar{Empty List}
   210 \begin{lstlisting}
   210 \begin{lstlisting}
   211 In []: a = [ 1, 2, 3, 4, 5] 
   211 In []: p = [ 2, 3, 5, 7] 
   212 
   212 
   213 In []: a[0]+a[1]+a[-1]
   213 In []: p[0]+p[1]+p[-1]
   214 Out[]: 8
   214 Out[]: 12
   215 \end{lstlisting}
   215 \end{lstlisting}
   216 \end{frame}
   216 \end{frame}
   217 
   217 
   218 \begin{frame}[fragile]
   218 \begin{frame}[fragile]
   219   \frametitle{List: Slicing}
   219   \frametitle{List: Slicing}
   220   \begin{block}{Remember\ldots}
   220   \begin{block}{Remember\ldots}
   221 	\kwrd{In []: a = [ 1, 2, 3, 4, 5]}
   221 	\kwrd{In []: p = [ 2, 3, 5, 7]}
   222   \end{block}
   222   \end{block}
   223 \begin{lstlisting}
   223 \begin{lstlisting}
   224 In []: a[1:3]
   224 In []: p[1:3]
   225 Out[]: [2, 3]
   225 Out[]: [3, 5]
   226 \end{lstlisting}
   226 \end{lstlisting}
   227 \emphbar{A slice}
   227 \emphbar{A slice}
   228 \begin{lstlisting}
   228 \begin{lstlisting}
   229 In []: a[1:-1]
   229 In []: p[0:-1]
   230 Out[]: [2, 3, 4]
   230 Out[]: [2, 3, 5]
   231 \end{lstlisting}
   231 In []: p[::2]
   232 \alert{\typ{list[initial:final]}}
   232 Out[]: [2, 5]
       
   233 \end{lstlisting}
       
   234 \alert{\typ{list[initial:final:step]}}
   233 \end{frame}
   235 \end{frame}
   234 
   236 
   235 %% more on list slicing
   237 %% more on list slicing
   236 \begin{frame}[fragile]
   238 \begin{frame}[fragile]
   237 \frametitle{List operations}
   239 \frametitle{List operations}
   238 \begin{lstlisting}
   240 \begin{lstlisting}
   239 In []: b = [ 6, 7, 8, 9]
   241 In []: b = [ 11, 13, 17]
   240 In []: c = a + b
   242 In []: c = p + b
   241 
   243 
   242 In []: c
   244 In []: c
   243 Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
   245 Out[]: [2, 3, 5, 7, 11, 13, 17]
   244 
   246 
   245 In []: a.append(6)
   247 In []: p.append(11)
   246 In []: a
   248 In []: p
   247 Out[]: [ 1, 2, 3, 4, 5, 6]
   249 Out[]: [ 2, 3, 5, 7, 11]
   248 \end{lstlisting}
   250 \end{lstlisting}
   249 %\inctime{10}
   251 %\inctime{10}
   250 \end{frame}
   252 \end{frame}
   251 
   253 
   252 \section{Simple Pendulum}
   254 \section{Simple Pendulum}
   297 \begin{frame}[fragile]
   299 \begin{frame}[fragile]
   298 \frametitle{Plotting $L$ vs $T^2$}
   300 \frametitle{Plotting $L$ vs $T^2$}
   299 \begin{lstlisting}
   301 \begin{lstlisting}
   300 In []: tsq = []
   302 In []: tsq = []
   301 
   303 
       
   304 In []: len(l)
       
   305 Out[]: 9
       
   306 
       
   307 In []: len(t)
       
   308 Out[]: 9
       
   309 
   302 In []: for time in t:
   310 In []: for time in t:
   303  ....:     tsq.append(time*time)
   311  ....:     tsq.append(time*time)
   304  ....:
   312  ....:
   305  ....:
   313  ....:
   306 
   314 
   310 This gives \kwrd{tsq} which is the list of squares of \typ{t} values.
   318 This gives \kwrd{tsq} which is the list of squares of \typ{t} values.
   311 \end{frame}
   319 \end{frame}
   312 
   320 
   313 \begin{frame}[fragile]
   321 \begin{frame}[fragile]
   314   \frametitle{How to come out of the \texttt{for} loop?}
   322   \frametitle{How to come out of the \texttt{for} loop?}
   315   Recall that hitting the ``ENTER'' key twice returns the cursor to the previous indentation level
   323   Hitting the ``ENTER'' key twice returns the cursor to the previous indentation level
   316   \begin{lstlisting}
   324   \begin{lstlisting}
   317     In []: for time in t:
   325     In []: for time in t:
   318      ....:     tsq.append(time*time)
   326      ....:     tsq.append(time*time)
   319      ....:     
   327      ....:     
   320      ....:     
   328      ....:     
   321 
   329 
   322     In []: print tsq
   330     In []: print tsq, len(tsq)
       
   331     In []: plot(l, tsq)
   323   \end{lstlisting}
   332   \end{lstlisting}
   324 \end{frame}
   333 \end{frame}
   325 
   334 
   326 \begin{frame}[fragile]
   335 \begin{frame}[fragile]
   327 \begin{figure}
   336 \begin{figure}