Changes to session1, 5 and 6 at Goa.
authorPuneeth Chaganti <punchagan@fossee.in>
Wed, 04 Nov 2009 09:33:37 +0530
changeset 265 ac31e2f3754e
parent 264 c3a1de5b8216
child 266 28d4714a9702
Changes to session1, 5 and 6 at Goa.
day1/session1.tex
day1/session5.tex
day1/session6.tex
--- a/day1/session1.tex	Sat Oct 31 01:23:23 2009 +0530
+++ b/day1/session1.tex	Wed Nov 04 09:33:37 2009 +0530
@@ -181,6 +181,11 @@
       \item \typ{points.txt}
       \item \typ{pos.txt}
       \end{itemize}
+    \item Python scripts: 
+      \begin{itemize}
+      \item \typ{sslc_allreg.py}
+      \item \typ{sslc_science.py}
+      \end{itemize}
   \end{enumerate}
 \end{frame}
 
--- a/day1/session5.tex	Sat Oct 31 01:23:23 2009 +0530
+++ b/day1/session5.tex	Wed Nov 04 09:33:37 2009 +0530
@@ -124,8 +124,25 @@
 %% %  \pausesections
 %% \end{frame}
 
+\section{\typ{loadtxt}}
 
-\section{\typ{loadtxt}}
+\begin{frame}[fragile]
+  \frametitle{Array slicing}
+  \begin{lstlisting}
+In []: A = array([[ 1,  1,  2, -1],
+                  [ 2,  5, -1, -9],
+                  [ 2,  1, -1,  3],
+                  [ 1, -3,  2,  7]])
+
+In []: A[:,0]
+Out[]: array([ 1,  2,  2, 1])
+
+In []: A[1:3,1:3]
+Out[]: 
+array([[ 5, -1],
+       [ 1, -1]])
+\end{lstlisting}
+\end{frame}
 
 \begin{frame}[fragile]
   \frametitle{\typ{loadtxt}}
@@ -134,8 +151,9 @@
   \item Each row must have same number of values.
   \end{itemize}
 \begin{lstlisting}
-In []: L, T = loadtxt('pendulum.txt', 
-                       unpack = True)
+In []: data = loadtxt('pendulum.txt')
+In []: x = data[:, 0]
+In []: y = data[:, 1]
 \end{lstlisting}
 \end{frame}
 
@@ -145,14 +163,13 @@
 
 \section{Interpolation}
 \begin{frame}[fragile]
-\frametitle{Interpolation}
+\frametitle{Loading data (revisited)}
 \begin{itemize}
   \item Given data file \typ{points.txt}.
   \item It contains x,y position of particle.
   \item Plot the given points.
 %%  \item Interpolate the missing region.
 \end{itemize}
-\emphbar{Loading data (revisited)}
 \begin{lstlisting}
 In []: x, y = loadtxt('points.txt',
                        unpack = True)
@@ -160,6 +177,12 @@
 \end{lstlisting}
 \end{frame}
 
+\begin{frame}
+  \frametitle{Plot}
+  \begin{center}
+    \includegraphics[height=2in, interpolate=true]{data/missing_points}
+  \end{center}
+\end{frame}
 %% \begin{frame}[fragile]
 %% \frametitle{Interpolation \ldots}
 %% \begin{small}
@@ -218,7 +241,7 @@
 
 \begin{frame}[fragile]
 \frametitle{\typ{splev}}
-To Evaluate a B-spline and it's derivatives
+To Evaluate a spline and it's derivatives
 \begin{lstlisting}
 In []: Xnew = arange(0.01,3,0.02)
 In []: Ynew = splev(Xnew, tck)
@@ -241,6 +264,13 @@
 %% \end{itemize}
 %% \end{frame}
 
+\begin{frame}
+  \frametitle{Plot}
+  \begin{center}
+    \includegraphics[height=2in, interpolate=true]{data/interpolate}
+  \end{center}
+\end{frame}
+
 \section{Differentiation}
 
 \begin{frame}[fragile]
@@ -252,8 +282,8 @@
 \end{itemize}
 \begin{center}
 \begin{tabular}{l l}
-$f(x+h)=f(x)+h.f^{'}(x)$ &Forward \\
-$f(x-h)=f(x)-h.f^{'}(x)$ &Backward
+$f(x+h)=f(x)+hf^{'}(x)$ &Forward \\
+$f(x-h)=f(x)-hf^{'}(x)$ &Backward
 \end{tabular}
 \end{center}
 \end{frame}
@@ -272,10 +302,14 @@
 \frametitle{Forward Difference \ldots}
 \begin{lstlisting}
 In []: fD = (y[1:] - y[:-1]) / deltax
-In []: plot(x, y, x[:-1], fD)
+In []: print len(fD)
+Out[]: 99
+In []: plot(x, y) 
+In []: plot(x[:-1], fD)
 \end{lstlisting}
+\vspace{-.2in}
 \begin{center}
-  \includegraphics[height=2in, interpolate=true]{data/fwdDiff}
+  \includegraphics[height=1.8in, interpolate=true]{data/fwdDiff}
 \end{center}
 \end{frame}
 
@@ -305,17 +339,13 @@
 \frametitle{Example \ldots}
 \begin{itemize}
 \item Read the file
-\item Obtain an array of x, y
+\item Obtain an array of X, Y
 \item Obtain velocity and acceleration
 \item use \typ{deltaT = 0.05}
 \end{itemize}
 \begin{lstlisting}
-In []: X = []
-In []: Y = []
-In []: for line in open('location.txt'):
-  ....     points = line.split()
-  ....     X.append(float(points[0]))
-  ....     Y.append(float(points[1]))
+In []: data = loadtxt('pos.txt')
+In []: X,Y = data[:,0], data[:,1]
 In []: S = array([X, Y])
 \end{lstlisting}
 \end{frame}
@@ -323,9 +353,6 @@
 
 \begin{frame}[fragile]
 \frametitle{Example \ldots}
-\begin{itemize}
-\item use \typ{deltaT = 0.05}
-\end{itemize}
 \begin{lstlisting}
 In []: deltaT = 0.05
 
@@ -333,25 +360,36 @@
 
 In []: a = (v[:,1:]-v[:,:-1])/deltaT
 \end{lstlisting}
-Try Plotting the position, velocity \& acceleration.
+\end{frame}
+
+\begin{frame}[fragile]
+\frametitle{Example \ldots}
+Plotting Y, $v_y$, $a_y$
+\begin{lstlisting}
+In []: plot(Y)
+In []: plot(v[1,:])
+In []: plot(a[1,:])
+\end{lstlisting}
+\begin{center}
+  \includegraphics[height=1.8in, interpolate=true]{data/pos_vel_accel}  
+\end{center}
 \end{frame}
 
 \section{Quadrature}
 
 \begin{frame}[fragile]
 \frametitle{Quadrature}
-\begin{itemize}
-\item We wish to find area under a curve
-\item Area under $(sin(x) + x^2)$ in $(0,1)$
-\item scipy has functions to do that
-\end{itemize}
-\begin{small}
-  \typ{In []: from scipy.integrate import quad}
-\end{small}
+
+\emphbar{$\int_0^1(sin(x) + x^2)$}
+
+\typ{In []: from scipy.integrate import quad}
+
 \begin{itemize}
 \item Inputs - function to integrate, limits
 \end{itemize}
 \begin{lstlisting}
+In []: quad(sin(x)+x**2, 0, 1)
+NameError: name 'x' is not defined
 In []: x = 0
 In []: quad(sin(x)+x**2, 0, 1)
 \end{lstlisting}
@@ -401,8 +439,7 @@
 \end{lstlisting}
 Returns the integral and an estimate of the absolute error in the result.
 \begin{itemize}
-\item Look at \typ{dblquad} for Double integrals
-\item Use \typ{tplquad} for Triple integrals
+\item \typ{dblquad}, \typ{tplquad} are available
 \end{itemize}
 \end{frame}
 
--- a/day1/session6.tex	Sat Oct 31 01:23:23 2009 +0530
+++ b/day1/session6.tex	Wed Nov 04 09:33:37 2009 +0530
@@ -138,7 +138,7 @@
 \dot{\theta} &= \omega \\
 \dot{\omega} &= -\frac{g}{L}sin(\theta) \\
  \text{At}\ t &= 0 : \nonumber \\
- \theta = \theta_0\quad & \&\quad  \omega = 0 \nonumber
+ \theta = \theta_0(10^o)\quad & \&\quad  \omega = 0\ (Initial\ values)\nonumber 
 \end{align}
 \end{frame}
 
@@ -149,9 +149,9 @@
 \item Define a function as below
 \end{itemize}
 \begin{lstlisting}
-In []: def pend_int(unknown, t, p):
-  ....     theta, omega = unknown
-  ....     g, L = p
+In []: def pend_int(initial, t):
+  ....     theta, omega = initial
+  ....     g, L = -9.81, 0.2
   ....     f=[omega, -(g/L)*sin(theta)]
   ....     return f
   ....
@@ -162,25 +162,22 @@
 \frametitle{Solving ODEs using SciPy \ldots}
 \begin{itemize}
 \item \typ{t} is the time variable \\ 
-\item \typ{p} has the constants \\
 \item \typ{initial} has the initial values
 \end{itemize}
 \begin{lstlisting}
 In []: t = linspace(0, 10, 101)
-In []: p=(-9.81, 0.2)
 In []: initial = [10*2*pi/360, 0]
-\end{lstlisting}
+\end{lstlisting} 
 \end{frame}
 
 \begin{frame}[fragile]
 \frametitle{Solving ODEs using SciPy \ldots}
-\begin{small}
-  \typ{In []: from scipy.integrate import odeint}
-\end{small}
+%%\begin{small}
+\typ{In []: from scipy.integrate import odeint}
+%%\end{small}
 \begin{lstlisting}
 In []: pend_sol = odeint(pend_int, 
-                         initial,t, 
-                         args=(p,))
+                         initial,t)
 \end{lstlisting}
 \end{frame}
 
@@ -308,14 +305,13 @@
 \begin{frame}[fragile]
 \frametitle{Initial Estimates \ldots}
 \begin{lstlisting}
-  In []: def our_f(x):
-   ....:     return cos(x)-x**2
-   ....: 
-  In []: x = linspace(-pi/2, pi/2, 11)
+In []: def our_f(x):
+ ....:     return cos(x) - x*x
+ ....: 
+In []: x = linspace(-pi/2, pi/2, 11)
+In []: y = our_f(x)
 \end{lstlisting}
-\begin{itemize}
-\item Get the intervals of x, where sign changes occur
-\end{itemize}
+Get the intervals of x, where sign changes occur
 \end{frame}
 
 \begin{frame}[fragile]
@@ -335,7 +331,6 @@
 \frametitle{Scipy Methods - \typ{roots}}
 \begin{itemize}
 \item Calculates the roots of polynomials
-\item Array of coefficients is the only parameter
 \end{itemize}
 \begin{lstlisting}
   In []: coeffs = [1, 6, 13]