summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPuneeth Chaganti2009-11-04 09:33:37 +0530
committerPuneeth Chaganti2009-11-04 09:33:37 +0530
commit3e13b7024c7bc4a754fc2abe7267e9f0fe31fc59 (patch)
treee571f06ef39160ec33c3f5c12162f4da9107e235
parent9d7f28f8c6a27468827cd205c11bcfb86db95d3b (diff)
downloadworkshops-3e13b7024c7bc4a754fc2abe7267e9f0fe31fc59.tar.gz
workshops-3e13b7024c7bc4a754fc2abe7267e9f0fe31fc59.tar.bz2
workshops-3e13b7024c7bc4a754fc2abe7267e9f0fe31fc59.zip
Changes to session1, 5 and 6 at Goa.
-rw-r--r--day1/session1.tex5
-rw-r--r--day1/session5.tex99
-rwxr-xr-x[-rw-r--r--]day1/session6.tex35
3 files changed, 88 insertions, 51 deletions
diff --git a/day1/session1.tex b/day1/session1.tex
index df5e105..fbaadc3 100644
--- a/day1/session1.tex
+++ b/day1/session1.tex
@@ -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}
diff --git a/day1/session5.tex b/day1/session5.tex
index c7709c5..20e58d1 100644
--- a/day1/session5.tex
+++ b/day1/session5.tex
@@ -124,18 +124,36 @@
%% % \pausesections
%% \end{frame}
-
\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}}
\begin{itemize}
\item Load data from a text file.
\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 @@ In []: L, T = loadtxt('pendulum.txt',
\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 @@ In []: plot(x, y, '.')
\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 @@ In []: tck = splrep(x, y)
\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 @@ In []: plot(Xnew, Ynew)
%% \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 @@ In []: plot(Xnew, Ynew)
\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 @@ Obtain the finite forward difference of y
\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 @@ $X$ & $Y$ \\ \hline
\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 @@ In []: S = array([X, Y])
\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 []: v = (S[:,1:]-S[:,:-1])/deltaT
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 @@ In []: quad(f, 0, 1)
\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}
diff --git a/day1/session6.tex b/day1/session6.tex
index 0b5f681..06e2eb0 100644..100755
--- a/day1/session6.tex
+++ b/day1/session6.tex
@@ -138,7 +138,7 @@ We shall use the simple ODE of a simple pendulum.
\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 @@ We shall use the simple ODE of a simple pendulum.
\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 @@ In []: def pend_int(unknown, t, p):
\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 @@ In []: pend_sol = odeint(pend_int,
\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 @@ Now use Newton-Raphson?
\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]