diff options
author | Santosh G. Vattam | 2010-01-25 17:53:03 +0530 |
---|---|---|
committer | Santosh G. Vattam | 2010-01-25 17:53:03 +0530 |
commit | 70b670dbfbe9be9f55691a6a46d5f3ca999f64ff (patch) | |
tree | 2c5744db9b8a97881cc48cc68dddaa2f88ef1318 /day1 | |
parent | 9f180b657d4a5d47d29b9058d6794b2b3503f6ea (diff) | |
parent | 0462fa1d7e83d26378ae1d2252126c554d2ba7b1 (diff) | |
download | workshops-70b670dbfbe9be9f55691a6a46d5f3ca999f64ff.tar.gz workshops-70b670dbfbe9be9f55691a6a46d5f3ca999f64ff.tar.bz2 workshops-70b670dbfbe9be9f55691a6a46d5f3ca999f64ff.zip |
Branches merged.
Diffstat (limited to 'day1')
-rw-r--r-- | day1/session1.tex | 2 | ||||
-rw-r--r-- | day1/session3.tex | 25 | ||||
-rw-r--r-- | day1/session4.tex | 77 | ||||
-rw-r--r-- | day1/session5.tex | 2 | ||||
-rwxr-xr-x | day1/session6.tex | 46 |
5 files changed, 84 insertions, 68 deletions
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/session3.tex b/day1/session3.tex index 2de2634..135bfc1 100644 --- a/day1/session3.tex +++ b/day1/session3.tex @@ -142,13 +142,13 @@ \begin{frame}[fragile] \frametitle{Acceleration due to gravity - ``g''\ldots} \begin{lstlisting} -In []: G = [] +In []: g_list = [] In []: for line in open('pendulum.txt'): .... point = line.split() .... l = float(point[0]) .... t = float(point[1]) .... g = 4 * pi * pi * l / (t * t) - .... G.append(g) + .... g_list.append(g) \end{lstlisting} \end{frame} @@ -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_list: + ....: total += g + ....: -g_mean = total / len(G) -print 'Mean: ', g_mean +In []: g_mean = total / len(g_list) +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_list) / len(g_list) +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_list) +In []: print 'Mean: ', g_mean \end{lstlisting} \inctime{10} \end{frame} @@ -332,7 +333,6 @@ science = {} science = {} for record in open('sslc1.txt'): - record = record.strip() fields = record.split(';') region_code = fields[0].strip() @@ -395,7 +395,6 @@ savefig('science.png') math_scores = [] for record in open('sslc1.txt'): - record = record.strip() fields = record.split(';') score_str = fields[5].strip() diff --git a/day1/session4.tex b/day1/session4.tex index 257fd54..9195ff6 100644 --- a/day1/session4.tex +++ b/day1/session4.tex @@ -134,15 +134,15 @@ \begin{frame}[fragile] \frametitle{Matrices: Initializing} \begin{lstlisting} -In []: c = array([[1,1,2], - [2,4,1], - [-1,3,7]]) +In [23]: c = array([[11,12,13], + [21,22,23], + [31,32,33]]) In []: c Out[]: -array([[1,1,2], - [2,4,1], - [-1,3,7]]) +array([[11, 12, 13], + [21, 22, 23], + [31, 32, 33]]) \end{lstlisting} \end{frame} @@ -174,16 +174,16 @@ Also available \alert{\typ{zeros, zeros_like, empty, empty_like}} \begin{lstlisting} In []: c Out[]: -array([[1,1,2], - [2,4,1], - [-1,3,7]]) +array([[11, 12, 13], + [21, 22, 23], + [31, 32, 33]]) In []: c[1][2] -Out[]: 1 +Out[]: 23 In []: c[1,2] -Out[]: 1 +Out[]: 23 In []: c[1] -Out[]: array([2, 4, 1]) +Out[]: array([21, 22, 23]) \end{lstlisting} \end{frame} @@ -191,19 +191,19 @@ Out[]: array([2, 4, 1]) \frametitle{Changing elements} \begin{small} \begin{lstlisting} -In []: c[1,1] = -2 +In []: c[1,1] = -22 In []: c Out[]: -array([[ 1, 1, 2], - [ 2, -2, 1], - [-1, 3, 7]]) +array([[ 11, 12, 13], + [ 21, -22, 23], + [ 31, 32, 33]]) -In []: c[1] = [0,0,0] +In []: c[1] = 0 In []: c Out[]: -array([[ 1, 1, 2], +array([[11, 12, 13], [ 0, 0, 0], - [-1, 3, 7]]) + [31, 32, 33]]) \end{lstlisting} \end{small} How to change one \alert{column}? @@ -214,20 +214,20 @@ How to change one \alert{column}? \begin{small} \begin{lstlisting} In []: c[:,1] -Out[]: array([1, 0, 3]) +Out[]: array([12, 0, 32]) In []: c[1,:] Out[]: array([0, 0, 0]) In []: c[0:2,:] Out[]: -array([[1, 1, 2], - [0, 0, 0]]) +array([[11, 12, 13], + [ 0, 0, 0]]) In []: c[1:3,:] Out[]: array([[ 0, 0, 0], - [-1, 3, 7]]) + [31, 32, 33]]) \end{lstlisting} \end{small} \end{frame} @@ -238,18 +238,18 @@ array([[ 0, 0, 0], \begin{lstlisting} In []: c[:2,:] Out[]: -array([[1, 1, 2], - [0, 0, 0]]) +array([[11, 12, 13], + [ 0, 0, 0]]) In []: c[1:,:] Out[]: array([[ 0, 0, 0], - [-1, 3, 7]]) + [31, 32, 33]]) In []: c[1:,:2] Out[]: array([[ 0, 0], - [-1, 3]]) + [31, 32]]) \end{lstlisting} \end{small} @@ -261,19 +261,19 @@ array([[ 0, 0], \begin{lstlisting} In []: c[::2,:] Out[]: -array([[ 1, 1, 2], - [-1, 3, 7]]) +array([[11, 12, 13], + [31, 32, 33]]) In []: c[:,::2] Out[]: -xarray([[ 1, 2], +array([[11, 13], [ 0, 0], - [-1, 7]]) + [31, 33]]) In []: c[::2,::2] Out[]: -array([[ 1, 2], - [-1, 7]]) +array([[11, 13], + [31, 33]]) \end{lstlisting} \end{small} \end{frame} @@ -477,11 +477,16 @@ Out[]: array([-1., 8., -1.]) \begin{frame} \frametitle{Least Square Fit Curve} +\begin{center} \begin{itemize} -\item $T^2$ and $L$ have a linear relationship -\item Hence, Least Square Fit Curve is a line -\item we shall use the \typ{lstsq} function +\item $L \alpha T^2$ +\item Best Fit Curve $\rightarrow$ Linear + \begin{itemize} + \item Least Square Fit + \end{itemize} +\item \typ{lstsq()} \end{itemize} +\end{center} \end{frame} \begin{frame}[fragile] 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..a5c1a2c 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,11 +240,26 @@ 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) +In []: fsolve(sin(x)+cos(x)*cos(x), 0) NameError: name 'x' is not defined +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{\typ{fsolve}} +\begin{lstlisting} In []: x = linspace(-pi, pi) -In []: fsolve(sin(x)+cos(x)**2, 0) +In []: fsolve(sin(x)+cos(x)*cos(x), 0) \end{lstlisting} \begin{small} \alert{\typ{TypeError:}} @@ -263,7 +272,7 @@ In []: fsolve(sin(x)+cos(x)**2, 0) We have been using them all along. Now let's see how to define them. \begin{lstlisting} In []: def f(x): - return sin(x)+cos(x)**2 + return sin(x)+cos(x)*cos(x) \end{lstlisting} \begin{itemize} \item \typ{def} @@ -329,7 +338,8 @@ Out[]: -0.66623943249251527 \begin{lstlisting} In []: from scipy.integrate import odeint In []: def epid(y, t): - .... k, L = 0.00003, 25000 + .... k = 0.00003 + .... L = 25000 .... return k*y*(L-y) .... \end{lstlisting} @@ -379,8 +389,10 @@ We shall use the simple ODE of a simple pendulum. \end{itemize} \begin{lstlisting} In []: def pend_int(initial, t): - .... theta, omega = initial - .... g, L = 9.81, 0.2 + .... theta = initial[0] + .... omega = initial[1] + .... g = 9.81 + .... L = 0.2 .... f=[omega, -(g/L)*sin(theta)] .... return f .... @@ -394,7 +406,7 @@ In []: def pend_int(initial, t): \item \typ{initial} has the initial values \end{itemize} \begin{lstlisting} -In []: t = linspace(0, 10, 101) +In []: t = linspace(0, 20, 101) In []: initial = [10*2*pi/360, 0] \end{lstlisting} \end{frame} |