diff -r 9664eddee075 -r 8a4a1e5aec85 day1/session5.tex --- a/day1/session5.tex Sat Oct 31 01:33:41 2009 +0530 +++ b/day1/session5.tex Wed Nov 04 09:40:28 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} @@ -151,6 +169,7 @@ \item It contains x,y position of particle. \item Plot the given points. %% \item Interpolate the missing region. +%% load txt the unpack part. \end{itemize} \begin{lstlisting} In []: x, y = loadtxt('points.txt', @@ -195,6 +214,8 @@ %% \end{lstlisting} %% \end{frame} +%%better example, maybe parabola + \begin{frame}[fragile] \frametitle{Spline Interpolation} \begin{small} @@ -223,22 +244,29 @@ \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 []: Xnew = linspace(0.01,3,100) In []: Ynew = splev(Xnew, tck) In []: y.shape Out[]: (40,) In []: Ynew.shape -Out[]: (150,) +Out[]: (100,) -In []: plot(Xnew, Ynew) +In []: plot(Xnew, Ynew, '+') \end{lstlisting} \end{frame} +\begin{frame} + \frametitle{Interpolated data} + \begin{center} + \includegraphics[height=2in, interpolate=true]{data/interpolate} + \end{center} +\end{frame} + %% \begin{frame}[fragile] %% \frametitle{Interpolation \ldots} %% \begin{itemize} @@ -257,8 +285,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} @@ -277,7 +305,10 @@ \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} \begin{center} \includegraphics[height=2in, interpolate=true]{data/fwdDiff} @@ -310,27 +341,18 @@ \frametitle{Example \ldots} \begin{itemize} \item Read the file -\item Obtain an array of x, y +\item Obtain an array of X, Y(S) \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 []: S = array([X, Y]) +In []: S = loadtxt('location.txt') \end{lstlisting} \end{frame} \begin{frame}[fragile] \frametitle{Example \ldots} -\begin{itemize} -\item use \typ{deltaT = 0.05} -\end{itemize} \begin{lstlisting} In []: deltaT = 0.05 @@ -345,18 +367,17 @@ \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} @@ -406,8 +427,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} @@ -419,9 +439,7 @@ \item Functions \begin{itemize} \item Definition - \item Calling - \item Default Arguments - \item Keyword Arguments + \item Calling \end{itemize} \item Quadrature \end{itemize}