day1/session2.tex
changeset 358 162e3e453920
parent 352 b44d7bcc6609
child 359 cb17c87b090e
equal deleted inserted replaced
355:6af6441034f9 358:162e3e453920
   177 \end{frame}
   177 \end{frame}
   178 
   178 
   179 \begin{frame}[fragile]
   179 \begin{frame}[fragile]
   180 \frametitle{Additional Plotting Attributes}
   180 \frametitle{Additional Plotting Attributes}
   181 \begin{itemize}
   181 \begin{itemize}
   182   \item \kwrd{'o'} - Filled circles
   182   \item \typ{'o'} - Filled circles
   183   \item \kwrd{'.'} - Small Dots
   183   \item \typ{'.'} - Small Dots
   184   \item \kwrd{'-'} - Lines
   184   \item \typ{'-'} - Lines
   185   \item \kwrd{'- -'} - Dashed lines
   185   \item \typ{'--'} - Dashed lines
   186 \end{itemize}
   186 \end{itemize}
   187 \end{frame}
   187 \end{frame}
   188 
   188 
   189 \section{Lists}
   189 \section{Lists}
   190 \begin{frame}[fragile]
   190 \begin{frame}[fragile]
   191   \frametitle{Lists: Introduction}
   191   \frametitle{Lists: Introduction}
   192   \begin{lstlisting}
   192   \begin{lstlisting}
   193     In []: x = [0, 1, 2, 3]
   193     In []: x = [4, 2, 1, 3]
   194 
   194 
   195     In []: y = [7, 11, 15, 19]
   195     In []: y = [7, 11, 15, 19]
   196 
   196 
   197   \end{lstlisting}
   197   \end{lstlisting}
   198 What are \typ{x} and \typ{y}?\\
   198 What are \typ{x} and \typ{y}?\\
   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 []: a = [ 5, 2, 3, 1, 4] 
   212 
   212 
   213 In []: a[0]+a[1]+a[-1]
   213 In []: a[0]+a[1]+a[-1]
   214 Out[]: 8
   214 Out[]: 11
   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 []: a = [ 5, 2, 3, 1, 4]}
   222   \end{block}
   222   \end{block}
   223 \begin{lstlisting}
   223 \begin{lstlisting}
   224 In []: a[1:3]
   224 In []: a[1:3]
   225 Out[]: [2, 3]
   225 Out[]: [2, 3]
   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 []: a[1:-1]
   230 Out[]: [2, 3, 4]
   230 Out[]: [2, 3, 1]
   231 \end{lstlisting}
   231 \end{lstlisting}
   232 \alert{\typ{list[initial:final]}}
   232 \alert{\typ{list[initial:final]}}
   233 \end{frame}
   233 \end{frame}
   234 
   234 
   235 %% more on list slicing
   235 %% more on list slicing
   236 \begin{frame}[fragile]
   236 \begin{frame}[fragile]
   237 \frametitle{List operations}
   237 \frametitle{List operations}
   238 \begin{lstlisting}
   238 \begin{lstlisting}
   239 In []: b = [ 6, 7, 8, 9]
   239 In []: b = [ 8, 6, 9, 9]
   240 In []: c = a + b
   240 In []: c = a + b
   241 
   241 
   242 In []: c
   242 In []: c
   243 Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9]
   243 Out[]: [5, 2, 3, 1, 4, 8, 6, 9, 9]
   244 
   244 
   245 In []: a.append(6)
   245 In []: a.append(6)
   246 In []: a
   246 In []: a
   247 Out[]: [ 1, 2, 3, 4, 5, 6]
   247 Out[]: [5, 2, 3, 1, 4, 6]
   248 \end{lstlisting}
   248 \end{lstlisting}
   249 %\inctime{10}
   249 %\inctime{10}
   250 \end{frame}
   250 \end{frame}
   251 
   251 
   252 \section{Simple Pendulum}
   252 \section{Simple Pendulum}
   301 
   301 
   302 In []: for time in t:
   302 In []: for time in t:
   303  ....:     tsq.append(time*time)
   303  ....:     tsq.append(time*time)
   304  ....:
   304  ....:
   305  ....:
   305  ....:
   306 
   306 \end{lstlisting}
       
   307 Hit the ``ENTER'' key twice to come to the previous indentation level
       
   308 \begin{lstlisting}
       
   309 In []: print tsq
       
   310 \end{lstlisting}
       
   311 \kwrd{tsq} is the list of squares of \typ{t} values.
       
   312 \end{frame}
       
   313 
       
   314 \begin{frame}[fragile]
       
   315 \frametitle{Plotting $L$ vs $T^2$ \ldots}
       
   316 \begin{lstlisting}
   307 In []: plot(l, tsq)
   317 In []: plot(l, tsq)
   308 Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
   318 Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
   309 \end{lstlisting}
   319 \end{lstlisting}
   310 This gives \kwrd{tsq} which is the list of squares of \typ{t} values.
   320 This gives the required plot. 
   311 \end{frame}
       
   312 
       
   313 \begin{frame}[fragile]
       
   314   \frametitle{How to come out of the \texttt{for} loop?}
       
   315   Hit the ``ENTER'' key twice to come to the previous indentation level
       
   316   \begin{lstlisting}
       
   317     In []: for time in t:
       
   318      ....:     tsq.append(time*time)
       
   319      ....:     
       
   320      ....:     
       
   321 
       
   322     In []: print tsq
       
   323   \end{lstlisting}
       
   324 \end{frame}
       
   325 
       
   326 \begin{frame}[fragile]
       
   327 \begin{figure}
   321 \begin{figure}
   328 \includegraphics[width=3.5in]{data/L-TSq-limited.png}
   322 \includegraphics[width=2.2in]{data/L-TSq-limited.png}
   329 \end{figure}
   323 \end{figure}
   330 \end{frame}
   324 \end{frame}
   331 
   325 
   332 \begin{frame}[fragile]
   326 \begin{frame}[fragile]
   333 \frametitle{What about larger data sets?}
   327 \frametitle{What about larger data sets?}
   369     t.append(float(point[1]))
   363     t.append(float(point[1]))
   370 tsq = []
   364 tsq = []
   371 for time in t:
   365 for time in t:
   372     tsq.append(time*time)
   366     tsq.append(time*time)
   373 plot(l, tsq, '.')
   367 plot(l, tsq, '.')
       
   368 show()
   374 \end{lstlisting}
   369 \end{lstlisting}
   375 \end{frame}
   370 \end{frame}
   376 
   371 
   377 \begin{frame}
   372 \begin{frame}
   378 \frametitle{Save and run}
   373 \frametitle{Save and run}
   455     t.append(float(point[1]))
   450     t.append(float(point[1]))
   456 tsq = []
   451 tsq = []
   457 for time in t:
   452 for time in t:
   458     tsq.append(time*time)
   453     tsq.append(time*time)
   459 plot(l, tsq, '.')
   454 plot(l, tsq, '.')
       
   455 show()
   460 \end{lstlisting}
   456 \end{lstlisting}
   461 \end{frame}
   457 \end{frame}
   462 
   458 
   463 \begin{frame}[fragile]
   459 \begin{frame}[fragile]
   464 \begin{figure}
   460 \begin{figure}