day1/session2.tex
changeset 193 a31b0e76c0fb
parent 179 eea01ca072ff
child 194 7288d3867df2
equal deleted inserted replaced
179:eea01ca072ff 193:a31b0e76c0fb
   168   \end{itemize}
   168   \end{itemize}
   169 \end{frame}
   169 \end{frame}
   170 
   170 
   171 \begin{frame}[fragile]
   171 \begin{frame}[fragile]
   172 \frametitle{How often do we plot analytical functions?}
   172 \frametitle{How often do we plot analytical functions?}
       
   173 Plotting experimental data is done more often and also more useful.\\
   173 Let us look at a small example:
   174 Let us look at a small example:
   174 \begin{lstlisting}
   175 \begin{lstlisting}
   175 In []: x = [0, 1, 2, 3]
   176 In []: x = [0, 1, 2, 3]
   176 
   177 
   177 In []: y = [7, 11, 15, 19]
   178 In []: y = [7, 11, 15, 19]
   224 
   225 
   225 \begin{frame}[fragile]
   226 \begin{frame}[fragile]
   226 \frametitle{Accessing elements of a list}
   227 \frametitle{Accessing elements of a list}
   227 \begin{lstlisting}
   228 \begin{lstlisting}
   228 In []: lst[0]+lst[1]+lst[-1]
   229 In []: lst[0]+lst[1]+lst[-1]
   229 Out[]: 7
   230 Out[]: 8
   230 \end{lstlisting}
   231 \end{lstlisting}
   231 \end{frame}
   232 \end{frame}
   232 
   233 
   233 \begin{frame}[fragile]
   234 \begin{frame}[fragile]
   234   \frametitle{List: Slicing}
   235   \frametitle{List: Slicing}
   260 
   261 
   261 \section{Simple Pendulum}
   262 \section{Simple Pendulum}
   262 \begin{frame}[fragile]
   263 \begin{frame}[fragile]
   263 \frametitle{Simple Pendulum - L and T}
   264 \frametitle{Simple Pendulum - L and T}
   264 Let us look at a more realistic example of the Simple Pendulum experiment.
   265 Let us look at a more realistic example of the Simple Pendulum experiment.
   265 \end{frame}
   266 \begin{center}
   266 
   267 \begin{small}
   267 \begin{frame}[fragile]
   268 \begin{tabular}{| l | c | r |}
   268 \frametitle{Plotting $L$ vs. $T^2$}
   269 \hline
       
   270 L & T & T^2 \\ \hline
       
   271 0.1 & 0.6900 & \\ \hline
       
   272 0.2 & 0.8989 & \\ \hline
       
   273 0.3 & 1.1867 & \\ \hline
       
   274 0.4 & 1.2991 & \\ \hline
       
   275 0.5 & 1.4656 & \\ \hline
       
   276 0.6 & 1.5843 & \\ \hline
       
   277 0.7 & 1.7706 & \\ \hline
       
   278 0.8 & 1.8296 & \\ \hline
       
   279 0.9 & 1.9440 & \\ \hline
       
   280 \end{tabular}
       
   281 \end{small}\\
       
   282 \alert{$L$ \alpha $T^2$}
       
   283 \end{center}
       
   284 \end{frame}
       
   285 
       
   286 \begin{frame}[fragile]
       
   287 \frametitle{Lets use lists}
       
   288 \begin{lstlisting}
       
   289 In []: L = [0.1, 0.2, 0.3, 0.4, 0.5, 
       
   290 0.6, 0.7, 0.8, 0.9]
       
   291 
       
   292 In []: T = [0.69, 0.8989, 1.1867, 
       
   293 1.2991, 1.4656, 1.5843, 1.7706, 1.8296, 1.9440]
       
   294 \end{lstlisting}
       
   295 \end{frame}
       
   296 
       
   297 \begin{frame}[fragile]
       
   298 \frametitle{Plotting $L$ vs $T^2$}
   269 \begin{itemize}
   299 \begin{itemize}
   270 \item We must square each of the values in T
   300 \item We must square each of the values in T
   271 \item How to do it?
   301 \item How to do it?
   272 \item T is a \kwrd{list} and we use a \kwrd{for} loop to iterate over it
   302 \item We use a \kwrd{for} loop to iterate over T
   273 \end{itemize}
   303 \end{itemize}
   274 \end{frame}
   304 \end{frame}
   275 
   305 
   276 \begin{frame}[fragile]
   306 \begin{frame}[fragile]
   277 \frametitle{Plotting $L$ vs $T^2$}
   307 \frametitle{Plotting $L$ vs $T^2$}
   282  ....:     TSq.append(t*t)
   312  ....:     TSq.append(t*t)
   283 
   313 
   284 In []: plot(L, TSq)
   314 In []: plot(L, TSq)
   285 Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
   315 Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>]
   286 \end{lstlisting}
   316 \end{lstlisting}
   287 \end{frame}
   317 This gives the list \kwrd{TSq} which is the list of squares of T values.
   288 
       
   289 \begin{frame}{New Concepts}
       
   290   \begin{itemize}
       
   291     \item lists
       
   292     \item \typ{for}
       
   293   \end{itemize}
       
   294 \end{frame}
   318 \end{frame}
   295 
   319 
   296 \begin{frame}[fragile]
   320 \begin{frame}[fragile]
   297 \frametitle{\texttt{for}}
   321 \frametitle{\texttt{for}}
   298 Used to iterate over lists\\ Let us look at another example.
   322 \begin{itemize}
       
   323 \item Used to iterate over lists
       
   324 \item Let us look at another example.
       
   325 \end{itemize}
   299 \begin{lstlisting}
   326 \begin{lstlisting}
   300 In []: lst = [1,2,3,4,5,6]
   327 In []: lst = [1,2,3,4,5,6]
   301 In []: for num in lst:
   328 In []: for num in lst:
   302  ....:     print num, num*num
   329  ....:     print num, num*num
   303  ....:    
   330  ....:    
   309 6 36
   336 6 36
   310 \end{lstlisting}
   337 \end{lstlisting}
   311 \end{frame}
   338 \end{frame}
   312 
   339 
   313 \begin{frame}[fragile]
   340 \begin{frame}[fragile]
       
   341 \frametitle{Whats unusual about the previous example??}
       
   342 \alert{Data is usually present in a file!} \\
       
   343 Lets look at the pendulum.txt file.
       
   344 \begin{lstlisting}
       
   345 cat data/pendulum.txt
       
   346 1.0000e-01 6.9004e-01
       
   347 1.1000e-01 6.9497e-01
       
   348 1.2000e-01 7.4252e-01
       
   349 1.3000e-01 7.5360e-01
       
   350 1.4000e-01 8.3568e-01
       
   351 1.5000e-01 8.6789e-01
       
   352 \end{lstlisting}
       
   353 \ldots
       
   354 \end{frame}
       
   355 
       
   356 \begin{frame}[fragile]
   314 \frametitle{Reading pendulum.txt}
   357 \frametitle{Reading pendulum.txt}
   315 \begin{itemize}
   358 \begin{itemize}
   316   \item We now wish to repeat the plot using the values from a file
   359   \item We now wish to repeat the plot using the values from a file
   317   \item Given a file containing L vs. T values 
   360   \item Given a file containing L vs. T values 
   318   \item Column1 - L; Column2 - T  
   361   \item Column1 - L; Column2 - T  
   347 
   390 
   348 In []: plot(L, TSq, '.')
   391 In []: plot(L, TSq, '.')
   349 \end{lstlisting}
   392 \end{lstlisting}
   350 \end{frame}
   393 \end{frame}
   351 
   394 
   352 \begin{frame}{New Concepts}
       
   353   \begin{itemize}
       
   354     \item File handling
       
   355     \item Strings
       
   356     \item Data-type conversion
       
   357   \end{itemize}
       
   358 \end{frame}
       
   359 
       
   360 \begin{frame}[fragile]
   395 \begin{frame}[fragile]
   361   \frametitle{Reading files \ldots}
   396   \frametitle{Reading files \ldots}
   362 \typ{In []: for line in open('pendulum.txt'):}
   397 \typ{In []: for line in open('pendulum.txt'):}
   363 \begin{itemize}
   398 \begin{itemize}
   364 \item opening file `pendulum.txt'
   399 \item opening file `pendulum.txt'
   365 \item iterating through file using variable \typ{line}
   400 \item iterating through file using variable \typ{line}
   366 \item \typ{line} is a \kwrd{string} variable
   401 \item \typ{line} is a \kwrd{string} variable
   367 \end{itemize}
   402 \end{itemize}
   368 \end{frame}
   403 \end{frame}
   369 
   404 
       
   405 \section{Strings}
   370 \begin{frame}[fragile]
   406 \begin{frame}[fragile]
   371 \frametitle{Strings}
   407 \frametitle{Strings}
   372 Anything within ``quotes'' is a string!
   408 Anything within ``quotes'' is a string!
   373 \begin{lstlisting}
   409 \begin{lstlisting}
   374 ' This is a string '  
   410 ' This is a string '  
   410   \end{lstlisting}
   446   \end{lstlisting}
   411 \end{frame}
   447 \end{frame}
   412 
   448 
   413 \begin{frame}[fragile]
   449 \begin{frame}[fragile]
   414 \begin{figure}
   450 \begin{figure}
   415 %\includegraphics[width=3.5in]{data/L-Tsq.png}
   451 \includegraphics[width=3.5in]{data/L-Tsq.png}
   416 \end{figure}
   452 \end{figure}
   417 \vspace{-0.2in}
   453 \vspace{-0.2in}
   418 Coming up - \alert{Least Square Fit \ldots}
   454 Coming up - \alert{Least Square Fit \ldots}
   419 \end{frame}
   455 \end{frame}
   420 
   456 
       
   457 \section {Summary}
       
   458 \begin{frame}
       
   459 \frametitle{Summary}
       
   460 So what did we learn in this session??
       
   461 \begin{itemize}
       
   462   \item Creating and running Python scripts
       
   463   \item Plotting points and Plotting attributes
       
   464   \item Lists
       
   465   \item \kwrd{for}
       
   466   \item Reading files
       
   467   \item Strings
       
   468 \end{itemize}
       
   469 \end{frame}
       
   470 
   421 \end{document}
   471 \end{document}