diff options
-rw-r--r-- | day1/session2.tex | 130 | ||||
-rw-r--r-- | day1/session4.tex | 85 |
2 files changed, 139 insertions, 76 deletions
diff --git a/day1/session2.tex b/day1/session2.tex index 431f495..2e15408 100644 --- a/day1/session2.tex +++ b/day1/session2.tex @@ -123,6 +123,26 @@ % You might wish to add the option [pausesections] \end{frame} +\begin{frame} +\frametitle{Why we didn't close the IPython??} +\begin{itemize} + \item Because all the command history is lost + \item We can go back, edit, and re-execute our commands +\end{itemize} +\end{frame} + +\begin{frame} +\frametitle{But its impractical..} +\begin{itemize} + \item Because we can't always keep running the IPython shell for days + \item And lets admit it, its a pain to go back and edit +\end{itemize} +And the solution is..\\ +\begin{center} +\alert {\typ{Scripts!!}} +\end{center} +\end{frame} + \section{Creating and running scripts} \begin{frame}[fragile] \frametitle{Python Scripts} @@ -141,57 +161,30 @@ \begin{itemize} \item Open a new file in an \alert{editor} \item Copy and paste required lines from the output of \typ{\%hist -n} - \item Save the file as \typ{first_plot.py} + \item Save the file as \typ{sine_plot.py} \end{itemize} \begin{itemize} - \item run the file in IPython using \typ{\%run first_plot.py}\\ + \item run the file in IPython using \typ{\%run sine_plot.py}\\ \end{itemize} \end{frame} -\section{Plotting Points} \begin{frame}[fragile] -\frametitle{Simple Pendulum - L and T} - \begin{itemize} - \item Given data of Length and Time-period of a Simple pendulum - \item $T^2 = \frac{4\pi^2}{g}L$\\ \alert{{$L$} and {$T^2$} vary linearly} - \item We wish to plot L vs. \alert{$T^2$} - \end{itemize} +\frametitle{How often do we plot analytical functions?} +Let us look at a small example: \begin{lstlisting} -In []: L = [0.1, 0.2, 0.3, - 0.4, 0.5, 0.6, - 0.7, 0.8, 0.9] -In []: T = [0.6529, 0.8485, 1.0590, - 1.2390, 1.4124, 1.5061, - 1.6441, 1.7949, 1.8758] -\end{lstlisting} -\end{frame} +In []: x = [0, 1, 2, 3] -\begin{frame}[fragile] -\frametitle{Plotting $L$ vs. $T^2$} -\begin{itemize} -\item We must square each of the values in T -\item How to do it? -\item T is a \kwrd{list} and we use a \kwrd{for} loop to iterate over it -\end{itemize} -\end{frame} - -\begin{frame}[fragile] -\frametitle{Plotting $L$ vs $T^2$} -\begin{lstlisting} -In []: TSq = [] - -In []: for t in T: - ....: TSq.append(t*t) +In []: y = [7, 11, 15, 19] -In []: plot(L, TSq) -Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>] +In []: plot(x, y) +Out[]: [<matplotlib.lines.Line2D object at 0xa73aa8c>] \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Plotting points} \begin{itemize} -\item But we want to plot points! +\item What if we want to plot points! \end{itemize} \begin{lstlisting} In []: clf() @@ -215,21 +208,23 @@ Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>] \end{itemize} \end{frame} -\begin{frame}{New Concepts} - \begin{itemize} - \item lists - \item \typ{for} - \end{itemize} -\end{frame} - \section{Lists} \begin{frame}[fragile] - \frametitle{How to create and use lists?} + \frametitle{How to create?} +What are \typ{x} and \typ{y} here??\\ +\begin{center} +\alert{\typ{lists!!}} +\end{center} \begin{lstlisting} In []: mtlist = [] #Empty List -In []: lst = [1,2,3,4] +In []: lst = [1,2,3,4,5] +\end{lstlisting} +\end{frame} +\begin{frame}[fragile] +\frametitle{Accessing elements of a list} +\begin{lstlisting} In []: lst[0]+lst[1]+lst[-1] Out[]: 7 \end{lstlisting} @@ -237,7 +232,7 @@ Out[]: 7 \begin{frame}[fragile] \frametitle{List: Slicing} -list[initial:final:step] +\alert{\typ{list[initial:final:step]}} \begin{lstlisting} In []: lst[1:3] # A slice. Out[]: [2, 3] @@ -248,8 +243,14 @@ Out[]: [2, 3] \end{frame} \begin{frame}[fragile] - \frametitle{List methods} + \frametitle{List concatenation and list methods} \begin{lstlisting} +In []: anthrlst = [6,7,8,9] +In []: lnglst = lst + anthrlst + +In []: lnglst +Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9] + In []: lst.append(6) In []: lst Out[]: [1, 2, 3, 4, 5, 6] @@ -257,6 +258,41 @@ Out[]: [1, 2, 3, 4, 5, 6] %\inctime{10} \end{frame} +\section{Simple Pendulum} +\begin{frame}[fragile] +\frametitle{Simple Pendulum - L and T} +Let us look at a more realistic example of the Simple Pendulum experiment. +\end{frame} + +\begin{frame}[fragile] +\frametitle{Plotting $L$ vs. $T^2$} +\begin{itemize} +\item We must square each of the values in T +\item How to do it? +\item T is a \kwrd{list} and we use a \kwrd{for} loop to iterate over it +\end{itemize} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Plotting $L$ vs $T^2$} +\begin{lstlisting} +In []: TSq = [] + +In []: for t in T: + ....: TSq.append(t*t) + +In []: plot(L, TSq) +Out[]: [<matplotlib.lines.Line2D object at 0xa5b05ac>] +\end{lstlisting} +\end{frame} + +\begin{frame}{New Concepts} + \begin{itemize} + \item lists + \item \typ{for} + \end{itemize} +\end{frame} + \begin{frame}[fragile] \frametitle{\texttt{for}} Used to iterate over lists\\ Let us look at another example. diff --git a/day1/session4.tex b/day1/session4.tex index fb8e2e4..0fe9c7a 100644 --- a/day1/session4.tex +++ b/day1/session4.tex @@ -124,6 +124,53 @@ % \pausesections \end{frame} +\section{Solving linear equations} +\begin{frame}[fragile] +\frametitle{Solution of equations} +Consider, + \begin{align*} + 3x + 2y - z & = 1 \\ + 2x - 2y + 4z & = -2 \\ + -x + \frac{1}{2}y -z & = 0 + \end{align*} +Solution: + \begin{align*} + x & = 1 \\ + y & = -2 \\ + z & = -2 + \end{align*} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Solving using Matrices} +Let us now look at how to solve this using \kwrd{matrices} + \begin{lstlisting} + In []: A = matrix([[3,2,-1],[2,-2,4],[-1, 0.5, -1]]) + In []: b = matrix([[1], [-2], [0]]) + In []: x = linalg.solve(A, b) + In []: Ax = dot(A, x) + In []: allclose(Ax, b) + Out[]: True + \end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Solution:} +\begin{lstlisting} +In []: x +Out[]: +array([[ 1.], + [-2.], + [-2.]]) + +In []: Ax +Out[]: +matrix([[ 1.00000000e+00], + [ -2.00000000e+00], + [ 2.22044605e-16]]) +\end{lstlisting} +\end{frame} + \section{Matrices} \subsection{Initializing} \begin{frame}[fragile] @@ -144,13 +191,15 @@ \subsection{Basic Operations} \begin{frame}[fragile] \frametitle{Inverse of a Matrix} + \begin{small} \begin{lstlisting} - In []: linalg.inv(a) - Out[]: - matrix([[ 3.15221191e+15, -6.30442381e+15, 3.15221191e+15], - [ -6.30442381e+15, 1.26088476e+16, -6.30442381e+15], - [ 3.15221191e+15, -6.30442381e+15, 3.15221191e+15]]) +In []: linalg.inv(A) +Out[]: +matrix([[ 0.07734807, 0.01657459, 0.32044199], + [ 0.09944751, -0.12154696, -0.01657459], + [-0.02762431, -0.07734807, 0.17127072]]) + \end{lstlisting} \end{small} \end{frame} @@ -176,11 +225,11 @@ \begin{small} \begin{lstlisting} In []: linalg.eigvals(a) - Out[]: array([ 1.61168440e+01, -1.11684397e+00, -1.22196337e-15]) + Out[]: array([1.61168440e+01, -1.11684397e+00, -1.22196337e-15]) In []: linalg.eig(a) Out[]: - (array([ 1.61168440e+01, -1.11684397e+00, -1.22196337e-15]), + (array([ 1.61168440e+01, -1.11684397e+00, -1.22196337e-15]), matrix([[-0.23197069, -0.78583024, 0.40824829], [-0.52532209, -0.08675134, -0.81649658], [-0.8186735 , 0.61232756, 0.40824829]])) @@ -188,28 +237,6 @@ \end{small} \end{frame} -\section{Solving linear equations} -\begin{frame}[fragile] -\frametitle{Solution of equations} -Example problem: Consider the set of equations -\vspace{-0.1in} - \begin{align*} - 3x + 2y - z & = 1 \\ - 2x - 2y + 4z & = -2 \\ - -x + \frac{1}{2}y -z & = 0 - \end{align*} -\vspace{-0.08in} - To Solve this, - \begin{lstlisting} - In []: A = array([[3,2,-1],[2,-2,4],[-1, 0.5, -1]]) - In []: b = array([1, -2, 0]) - In []: x = linalg.solve(A, b) - In []: Ax = dot(A, x) - In []: allclose(Ax, b) - Out[]: True - \end{lstlisting} -\end{frame} - \section{Integration} |