day1/session2.tex
changeset 381 b797cd67982b
parent 379 682b6f66fe11
child 382 41c34770d63a
equal deleted inserted replaced
380:669b72283b55 381:b797cd67982b
   279 \end{frame}
   279 \end{frame}
   280 
   280 
   281 \begin{frame}[fragile]
   281 \begin{frame}[fragile]
   282 \frametitle{Lets use lists}
   282 \frametitle{Lets use lists}
   283 \begin{lstlisting}
   283 \begin{lstlisting}
   284 In []: l = [0.1, 0.2, 0.3, 0.4, 0.5, 
   284 In []: L = [0.1, 0.2, 0.3, 0.4, 0.5, 
   285             0.6, 0.7, 0.8, 0.9]
   285             0.6, 0.7, 0.8, 0.9]
   286 
   286 
   287 In []: t = [0.69, 0.90, 1.19, 
   287 In []: t = [0.69, 0.90, 1.19, 
   288             1.30, 1.47, 1.58, 
   288             1.30, 1.47, 1.58, 
   289             1.77, 1.83, 1.94]
   289             1.77, 1.83, 1.94]
   307 In []: for time in t:
   307 In []: for time in t:
   308  ....:     tsq.append(time*time)
   308  ....:     tsq.append(time*time)
   309  ....:
   309  ....:
   310  ....:
   310  ....:
   311 
   311 
   312 In []: print len(l), len(t), len(tsq)
       
   313 \end{lstlisting}
   312 \end{lstlisting}
   314 This gives \kwrd{tsq} which is the list of squares of \typ{t} values.
   313 This gives \kwrd{tsq} which is the list of squares of \typ{t} values.
       
   314 \begin{lstlisting}
       
   315 In []: print len(L), len(t), len(tsq)
       
   316 Out[]: 9 9 9
       
   317 \end{lstlisting}
   315 \end{frame}
   318 \end{frame}
   316 
   319 
   317 \begin{frame}[fragile]
   320 \begin{frame}[fragile]
   318   \frametitle{How to come out of the \texttt{for} loop?}
   321   \frametitle{How to come out of the \texttt{for} loop?}
   319   Hitting the ``ENTER'' key twice returns the cursor to the previous indentation level
   322   Hitting the ``ENTER'' key twice returns the cursor to the previous indentation level
   321     In []: for time in t:
   324     In []: for time in t:
   322      ....:     tsq.append(time*time)
   325      ....:     tsq.append(time*time)
   323      ....:     
   326      ....:     
   324      ....:     
   327      ....:     
   325 
   328 
   326     In []: plot(l, tsq)
   329     In []: plot(L, tsq)
   327   \end{lstlisting}
   330   \end{lstlisting}
   328 \end{frame}
   331 \end{frame}
   329 
   332 
   330 \begin{frame}[fragile]
   333 \begin{frame}[fragile]
   331 \begin{figure}
   334 \begin{figure}
   360 
   363 
   361 \begin{frame}[fragile]
   364 \begin{frame}[fragile]
   362 \frametitle{Plotting from \typ{pendulum.txt}}
   365 \frametitle{Plotting from \typ{pendulum.txt}}
   363 Open a new script and type the following:
   366 Open a new script and type the following:
   364 \begin{lstlisting}
   367 \begin{lstlisting}
   365 l = []
   368 L = []
   366 t = []
   369 t = []
   367 for line in open('pendulum.txt'):
   370 for line in open('pendulum.txt'):
   368     point = line.split()
   371     point = line.split()
   369     l.append(float(point[0]))
   372     L.append(float(point[0]))
   370     t.append(float(point[1]))
   373     t.append(float(point[1]))
   371 tsq = []
   374 tsq = []
   372 for time in t:
   375 for time in t:
   373     tsq.append(time*time)
   376     tsq.append(time*time)
   374 plot(l, tsq, '.')
   377 plot(L, tsq, '.')
   375 \end{lstlisting}
   378 \end{lstlisting}
   376 \end{frame}
   379 \end{frame}
   377 
   380 
   378 \begin{frame}
   381 \begin{frame}
   379 \frametitle{Save and run}
   382 \frametitle{Save and run}
   446 \end{frame}
   449 \end{frame}
   447 
   450 
   448 \begin{frame}[fragile]
   451 \begin{frame}[fragile]
   449 \frametitle{Let's review the code}
   452 \frametitle{Let's review the code}
   450 \begin{lstlisting}
   453 \begin{lstlisting}
   451 l = []
   454 L = []
   452 t = []
   455 t = []
   453 for line in open('pendulum.txt'):
   456 for line in open('pendulum.txt'):
   454     point = line.split()
   457     point = line.split()
   455     l.append(float(point[0]))
   458     L.append(float(point[0]))
   456     t.append(float(point[1]))
   459     t.append(float(point[1]))
   457 tsq = []
   460 tsq = []
   458 for time in t:
   461 for time in t:
   459     tsq.append(time*time)
   462     tsq.append(time*time)
   460 plot(l, tsq, '.')
   463 plot(L, tsq, '.')
   461 \end{lstlisting}
   464 \end{lstlisting}
   462 \end{frame}
   465 \end{frame}
   463 
   466 
   464 \begin{frame}[fragile]
   467 \begin{frame}[fragile]
   465 \begin{figure}
   468 \begin{figure}