From 8622ffa26f8da8ed8c4409a23a9d8d2cf2c86469 Mon Sep 17 00:00:00 2001 From: Puneeth Chaganti Date: Thu, 21 Jan 2010 15:26:11 +0530 Subject: Added files to be circulated during workshops. --- day1/session1.tex | 2 +- day1/session2.tex | 56 ++++++++++++++++++++++++++----------------------------- day1/session3.tex | 19 ++++++++++--------- day1/session5.tex | 2 +- day1/session6.tex | 23 +++++++++++++---------- 5 files changed, 51 insertions(+), 51 deletions(-) (limited to 'day1') diff --git a/day1/session1.tex b/day1/session1.tex index a0a9595..eb2dbe2 100644 --- a/day1/session1.tex +++ b/day1/session1.tex @@ -530,7 +530,7 @@ Save commands of review problem into file \frametitle{\incqno } Draw (roughly) the plot obtained by the following: \begin{lstlisting} -In []: x = linspace(0, 2*pi, 3) +In []: x = linspace(0, pi, 3) In []: plot(x, sin(x)) \end{lstlisting} \end{frame} diff --git a/day1/session2.tex b/day1/session2.tex index ed30335..54dbd37 100644 --- a/day1/session2.tex +++ b/day1/session2.tex @@ -179,10 +179,10 @@ Out[]: \begin{frame}[fragile] \frametitle{Additional Plotting Attributes} \begin{itemize} - \item \kwrd{'o'} - Filled circles - \item \kwrd{'.'} - Small Dots - \item \kwrd{'-'} - Lines - \item \kwrd{'- -'} - Dashed lines + \item \typ{'o'} - Filled circles + \item \typ{'.'} - Small Dots + \item \typ{'-'} - Lines + \item \typ{'--'} - Dashed lines \end{itemize} \end{frame} @@ -190,7 +190,7 @@ Out[]: \begin{frame}[fragile] \frametitle{Lists: Introduction} \begin{lstlisting} - In []: x = [0, 1, 2, 3] + In []: x = [4, 2, 1, 3] In []: y = [7, 11, 15, 19] @@ -208,17 +208,17 @@ In []: mtlist = [] \end{lstlisting} \emphbar{Empty List} \begin{lstlisting} -In []: a = [ 1, 2, 3, 4, 5] +In []: a = [ 5, 2, 3, 1, 4] In []: a[0]+a[1]+a[-1] -Out[]: 8 +Out[]: 11 \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{List: Slicing} \begin{block}{Remember\ldots} - \kwrd{In []: a = [ 1, 2, 3, 4, 5]} + \kwrd{In []: a = [ 5, 2, 3, 1, 4]} \end{block} \begin{lstlisting} In []: a[1:3] @@ -227,7 +227,7 @@ Out[]: [2, 3] \emphbar{A slice} \begin{lstlisting} In []: a[1:-1] -Out[]: [2, 3, 4] +Out[]: [2, 3, 1] \end{lstlisting} \alert{\typ{list[initial:final]}} \end{frame} @@ -236,15 +236,15 @@ Out[]: [2, 3, 4] \begin{frame}[fragile] \frametitle{List operations} \begin{lstlisting} -In []: b = [ 6, 7, 8, 9] +In []: b = [ 8, 6, 9, 9] In []: c = a + b In []: c -Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9] +Out[]: [5, 2, 3, 1, 4, 8, 6, 9, 9] In []: a.append(6) In []: a -Out[]: [ 1, 2, 3, 4, 5, 6] +Out[]: [5, 2, 3, 1, 4, 6] \end{lstlisting} %\inctime{10} \end{frame} @@ -303,29 +303,23 @@ In []: for time in t: ....: tsq.append(time*time) ....: ....: - -In []: plot(l, tsq) -Out[]: [] \end{lstlisting} -This gives \kwrd{tsq} which is the list of squares of \typ{t} values. -\end{frame} - -\begin{frame}[fragile] - \frametitle{How to come out of the \texttt{for} loop?} - Hit the ``ENTER'' key twice to come to the previous indentation level - \begin{lstlisting} - In []: for time in t: - ....: tsq.append(time*time) - ....: - ....: - - In []: print tsq - \end{lstlisting} +Hit the ``ENTER'' key twice to come to the previous indentation level +\begin{lstlisting} +In []: print tsq +\end{lstlisting} +\kwrd{tsq} is the list of squares of \typ{t} values. \end{frame} \begin{frame}[fragile] +\frametitle{Plotting $L$ vs $T^2$ \ldots} +\begin{lstlisting} +In []: plot(l, tsq) +Out[]: [] +\end{lstlisting} +This gives the required plot. \begin{figure} -\includegraphics[width=3.5in]{data/L-TSq-limited.png} +\includegraphics[width=2.2in]{data/L-TSq-limited.png} \end{figure} \end{frame} @@ -371,6 +365,7 @@ tsq = [] for time in t: tsq.append(time*time) plot(l, tsq, '.') +show() \end{lstlisting} \end{frame} @@ -457,6 +452,7 @@ tsq = [] for time in t: tsq.append(time*time) plot(l, tsq, '.') +show() \end{lstlisting} \end{frame} diff --git a/day1/session3.tex b/day1/session3.tex index 2de2634..567a12c 100644 --- a/day1/session3.tex +++ b/day1/session3.tex @@ -162,28 +162,29 @@ In []: for line in open('pendulum.txt'): \begin{frame}[fragile] \frametitle{Mean ``g''} \begin{lstlisting} -total = 0 -for g in G: - total += g +In []: total = 0 +In []: for g in G: + ....: total += g + ....: -g_mean = total / len(G) -print 'Mean: ', g_mean +In []: g_mean = total / len(G) +In []: print 'Mean: ', g_mean \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Mean ``g''} \begin{lstlisting} -g_mean = sum(G) / len(G) -print 'Mean: ', g_mean +In []: g_mean = sum(G) / len(G) +In []: print 'Mean: ', g_mean \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Mean ``g''} \begin{lstlisting} -g_mean = mean(G) -print 'Mean: ', g_mean +In []: g_mean = mean(G) +In []: print 'Mean: ', g_mean \end{lstlisting} \inctime{10} \end{frame} diff --git a/day1/session5.tex b/day1/session5.tex index 3fe435e..1098b3e 100644 --- a/day1/session5.tex +++ b/day1/session5.tex @@ -135,7 +135,7 @@ plot(l, tsq, '.') \end{block} \end{columns} \begin{block}{Problem Statement} - Tweak above code to plot data in file 'location.txt'. + Tweak above code to plot data in file `pos.txt'. \end{block} \end{frame} diff --git a/day1/session6.tex b/day1/session6.tex index 409f07c..71afcd3 100755 --- a/day1/session6.tex +++ b/day1/session6.tex @@ -148,7 +148,7 @@ Let us now look at how to solve this using \kwrd{matrices} In []: A = array([[3,2,-1], [2,-2,4], [-1, 0.5, -1]]) - In []: b = array([[1], [-2], [0]]) + In []: b = array([1, -2, 0]) In []: x = solve(A, b) \end{lstlisting} \end{frame} @@ -157,22 +157,16 @@ Let us now look at how to solve this using \kwrd{matrices} \frametitle{Solution:} \begin{lstlisting} In []: x -Out[]: -array([[ 1.], - [-2.], - [-2.]]) +Out[]: array([ 1., -2., -2.]) \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Let's check!} \begin{lstlisting} -In []: Ax = dot(A,x) +In []: Ax = dot(A, x) In []: Ax -Out[]: -array([[ 1.00000000e+00], - [ -2.00000000e+00], - [ 2.22044605e-16]]) +Out[]: array([ 1.00000000e+00, -2.00000000e+00, -1.11022302e-16]) \end{lstlisting} \begin{block}{} The last term in the matrix is actually \alert{0}!\\ @@ -246,6 +240,15 @@ Use \kwrd{solve()} \begin{frame}[fragile] \frametitle{\typ{fsolve}} Find the root of $sin(x)+cos^2(x)$ nearest to $0$ +\vspace{-0.1in} +\begin{center} +\includegraphics[height=2.8in, interpolate=true]{data/fsolve} +\end{center} +\end{frame} + +\begin{frame}[fragile] +\frametitle{\typ{fsolve}} +Root of $sin(x)+cos^2(x)$ nearest to $0$ \begin{lstlisting} In []: fsolve(sin(x)+cos(x)**2, 0) NameError: name 'x' is not defined -- cgit