diff options
author | Santosh G. Vattam | 2010-01-05 15:23:02 +0530 |
---|---|---|
committer | Santosh G. Vattam | 2010-01-05 15:23:02 +0530 |
commit | ee0e1fabd1b2f0e2d71b99a93c1ecb948474f677 (patch) | |
tree | 01ab9ea0019ca45828493ce373737f38240e9279 /day1 | |
parent | 5c6a22254dd22ba8225a6bb7b816548cdb70cebc (diff) | |
parent | 508f280ce50c942f08f8fdb4bc76ee9654d4ffda (diff) | |
download | workshops-more-scipy-ee0e1fabd1b2f0e2d71b99a93c1ecb948474f677.tar.gz workshops-more-scipy-ee0e1fabd1b2f0e2d71b99a93c1ecb948474f677.tar.bz2 workshops-more-scipy-ee0e1fabd1b2f0e2d71b99a93c1ecb948474f677.zip |
Branches merged.
Diffstat (limited to 'day1')
-rwxr-xr-x | day1/cheatsheet2.tex | 2 | ||||
-rwxr-xr-x | day1/cheatsheet3.tex | 4 | ||||
-rwxr-xr-x | day1/cheatsheet4.tex | 2 | ||||
-rw-r--r-- | day1/data/after-filter.png | bin | 0 -> 153004 bytes | |||
-rw-r--r-- | day1/data/damp.png | bin | 0 -> 22368 bytes | |||
-rw-r--r-- | day1/data/four_plot.png | bin | 0 -> 54760 bytes | |||
-rw-r--r-- | day1/data/fsolve.png | bin | 0 -> 20617 bytes | |||
-rw-r--r-- | day1/data/image.png | bin | 0 -> 19554 bytes | |||
-rw-r--r-- | day1/data/location.txt (renamed from day1/data/pos.txt) | 0 | ||||
-rwxr-xr-x | day1/data/neighbour.png | bin | 0 -> 1157 bytes | |||
-rw-r--r-- | day1/data/ode.png | bin | 0 -> 59610 bytes | |||
-rw-r--r-- | day1/data/points.png | bin | 0 -> 19613 bytes | |||
-rw-r--r-- | day1/data/roots.png | bin | 0 -> 20654 bytes | |||
-rw-r--r-- | day1/data/smoothing.png | bin | 0 -> 200973 bytes | |||
-rw-r--r-- | day1/exercises.tex | 138 | ||||
-rw-r--r-- | day1/session1.tex | 60 | ||||
-rw-r--r-- | day1/session2.tex | 6 | ||||
-rw-r--r-- | day1/session3.tex | 36 | ||||
-rw-r--r-- | day1/session4.tex | 18 | ||||
-rw-r--r-- | day1/session5.tex | 2 | ||||
-rwxr-xr-x | day1/session6.tex | 30 |
21 files changed, 229 insertions, 69 deletions
diff --git a/day1/cheatsheet2.tex b/day1/cheatsheet2.tex index 58076f6..acffa20 100755 --- a/day1/cheatsheet2.tex +++ b/day1/cheatsheet2.tex @@ -29,7 +29,7 @@ \section{Plotting Points with Lists} \begin{lstlisting} -In []: x = [0, 1, 2, 3] +In []: x = [0, 1, 2, 3] # Creating a list In []: y = [7, 11, 15, 19] In []: plot(x, y) In []: clf() diff --git a/day1/cheatsheet3.tex b/day1/cheatsheet3.tex index db50de3..244cb86 100755 --- a/day1/cheatsheet3.tex +++ b/day1/cheatsheet3.tex @@ -69,7 +69,7 @@ Drawing Pie Charts \begin{lstlisting} In []: pie(science.values(), labels=science.keys()) \end{lstlisting} -Numpy Arrays +Arrays \begin{lstlisting} In []: a = array([1, 2, 3]) #Creating In []: b = array([4, 5, 6]) @@ -77,7 +77,7 @@ In []: a + b #Sum; Element-wise \end{lstlisting} Numpy statistical operations \begin{lstlisting} -In []: mean(math_scores) +In []: mean(math_scores) In []: median(math_scores) In []: std(math_scores) \end{lstlisting} diff --git a/day1/cheatsheet4.tex b/day1/cheatsheet4.tex index 68257a8..7410368 100755 --- a/day1/cheatsheet4.tex +++ b/day1/cheatsheet4.tex @@ -38,7 +38,7 @@ Out[]: (3, 2) \typ{In []: B = ones_like(C)} \\ B would be array of ones with the same shape and type as C.\\ \typ{In []: A = ones((3,2))} \\ -A would be new array of given shape(arguments), filled with ones.\\ +A would be new matrix of given shape(arguments), filled with ones.\\ \typ{In []: I = identity(3)}\\ I would be identity matrix of shape 3x3 diff --git a/day1/data/after-filter.png b/day1/data/after-filter.png Binary files differnew file mode 100644 index 0000000..ac4d953 --- /dev/null +++ b/day1/data/after-filter.png diff --git a/day1/data/damp.png b/day1/data/damp.png Binary files differnew file mode 100644 index 0000000..5307a5d --- /dev/null +++ b/day1/data/damp.png diff --git a/day1/data/four_plot.png b/day1/data/four_plot.png Binary files differnew file mode 100644 index 0000000..00a3a7a --- /dev/null +++ b/day1/data/four_plot.png diff --git a/day1/data/fsolve.png b/day1/data/fsolve.png Binary files differnew file mode 100644 index 0000000..0108215 --- /dev/null +++ b/day1/data/fsolve.png diff --git a/day1/data/image.png b/day1/data/image.png Binary files differnew file mode 100644 index 0000000..e1c7e08 --- /dev/null +++ b/day1/data/image.png diff --git a/day1/data/pos.txt b/day1/data/location.txt index adf92c8..adf92c8 100644 --- a/day1/data/pos.txt +++ b/day1/data/location.txt diff --git a/day1/data/neighbour.png b/day1/data/neighbour.png Binary files differnew file mode 100755 index 0000000..1bb69a1 --- /dev/null +++ b/day1/data/neighbour.png diff --git a/day1/data/ode.png b/day1/data/ode.png Binary files differnew file mode 100644 index 0000000..c76a483 --- /dev/null +++ b/day1/data/ode.png diff --git a/day1/data/points.png b/day1/data/points.png Binary files differnew file mode 100644 index 0000000..210286e --- /dev/null +++ b/day1/data/points.png diff --git a/day1/data/roots.png b/day1/data/roots.png Binary files differnew file mode 100644 index 0000000..c13a1a4 --- /dev/null +++ b/day1/data/roots.png diff --git a/day1/data/smoothing.png b/day1/data/smoothing.png Binary files differnew file mode 100644 index 0000000..8456e77 --- /dev/null +++ b/day1/data/smoothing.png diff --git a/day1/exercises.tex b/day1/exercises.tex index da88e05..3fe435e 100644 --- a/day1/exercises.tex +++ b/day1/exercises.tex @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {7 November, 2009\\Day 1, Session 5} +\date[] {11 January, 2010\\Day 1, Session 5} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -111,11 +111,37 @@ \end{frame} -\begin{frame} +\begin{frame}[fragile] \frametitle{Problem 1} + \begin{columns} + \column{0.5\textwidth} + \hspace*{-0.5in} + \includegraphics[height=2in, interpolate=true]{data/L-Tsq.png} + \column{0.45\textwidth} + \begin{block}{Example code} + \tiny + \begin{lstlisting} +l = [] +t = [] +for line in open('pendulum.txt'): + point = line.split() + l.append(float(point[0])) + t.append(float(point[1])) +tsq = [] +for time in t: + tsq.append(time*time) +plot(l, tsq, '.') + \end{lstlisting} + \end{block} + \end{columns} + \begin{block}{Problem Statement} + Tweak above code to plot data in file 'location.txt'. + \end{block} +\end{frame} + +\begin{frame} + \frametitle{Problem 1 cont...} \begin{itemize} - \item Open file 'pos.txt', it has X and Y Coordinate of a particle under motion - \item Plot X vs Y Graph. \item Label both the axes. \item What kind of motion is this? \item Title the graph accordingly. @@ -123,13 +149,49 @@ \end{itemize} \end{frame} -\begin{frame} +\begin{frame}[fragile] \frametitle{Problem 2} -Write a Program that plots a regular n-gon(Let n = 5). + \begin{columns} + \column{0.5\textwidth} + \hspace*{-0.5in} + \includegraphics[height=2in, interpolate=true]{data/points} + \column{0.45\textwidth} + \begin{block}{Line between two points} + \tiny + \begin{lstlisting} +In []: x = [1, 5] +In []: y = [1, 4] +In []: plot(x, y) + \end{lstlisting} + \end{block} + \end{columns} + Line can be plotted using arrays of coordinates. + \pause + \begin{block}{Problem statement} + Write a Program that plots a regular n-gon(Let n = 5). + \end{block} \end{frame} + \begin{frame}[fragile] \frametitle{Problem 3} + \begin{columns} + \column{0.5\textwidth} + \hspace*{-0.5in} + \includegraphics[height=2in, interpolate=true]{data/damp} + \column{0.45\textwidth} + \begin{block}{Damped Oscillation} + \tiny + \begin{lstlisting} +In []: x = linspace(0, 4*pi) +In []: plot(x, exp(x/10)*sin(x)) + \end{lstlisting} + \end{block} + \end{columns} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Problem 3 cont...} Create a sequence of images in which the damped oscillator($e^{x/10}sin(x)$) slowly evolves over time. \begin{columns} \column{0.35\textwidth} @@ -147,17 +209,71 @@ savefig('plot'+str(i)+'.png') #i is int variable \end{block} \end{frame} -\begin{frame} +\begin{frame}[fragile] \frametitle{Problem 4} - Legendre polynomials $P_n(x)$ are defined by the following recurrence relation + \begin{lstlisting} +In []: x = imread('smoothing.png') +In []: x.shape +Out[]: (256, 256) +In []: imshow(x,cmap=cm.gray) + \end{lstlisting} +\emphbar{Replace each pixel with mean of neighboring pixels} + \begin{center} + \includegraphics[height=1in, interpolate=true]{data/neighbour} + \end{center} +\end{frame} -\center{$(n+1)P_{n+1}(x) - (2n+1)xP_n(x) + nP_{n-1}(x) = 0$}\\ +\begin{frame} + \begin{center} + \includegraphics[height=3in, interpolate=true]{data/smoothing} + \end{center} +\end{frame} + +\begin{frame}[fragile] + \frametitle{Problem 4: Approach} + For \typ{y} being resultant image: + \begin{lstlisting} +y[1, 1] = x[0, 1]/4 + x[1, 0]/4 + + x[2, 1]/4 + x[1, 2]/4 + \end{lstlisting} + \begin{columns} + \column{0.45\textwidth} + \hspace*{-0.5in} + \includegraphics[height=1.5in, interpolate=true]{data/smoothing} + \column{0.45\textwidth} + \hspace*{-0.5in} + \includegraphics[height=1.5in, interpolate=true]{data/after-filter} + \end{columns} + \begin{block}{Hint:} + Use array Slicing. + \end{block} +\end{frame} -with $P_0(x) = 1$, $P_1(x) = x$ and $P_2(x) = (3x^2 - 1)/2$. Compute the next three - Legendre polynomials and plot all 6 over the interval [-1,1]. +\begin{frame}[fragile] + \frametitle{Solution} + \begin{lstlisting} +In []: y = zeros_like(x) +In []: y[1:-1,1:-1] = x[:-2,1:-1]/4+ + x[2:,1:-1]/4+ + x[1:-1,2:]/4+ + x[1:-1,:-2]/4 +In []: imshow(y,cmap=cm.gray) + \end{lstlisting} \end{frame} + + \end{document} +%% \begin{frame} +%% \frametitle{Problem 4} +%% Legendre polynomials $P_n(x)$ are defined by the following recurrence relation + +%% \center{$(n+1)P_{n+1}(x) - (2n+1)xP_n(x) + nP_{n-1}(x) = 0$}\\ + +%% with $P_0(x) = 1$, $P_1(x) = x$ and $P_2(x) = (3x^2 - 1)/2$. Compute the next three +%% Legendre polynomials and plot all 6 over the interval [-1,1]. +%% \end{frame} + %% \begin{frame}[fragile] %% \frametitle{Problem Set 5} %% \begin{columns} diff --git a/day1/session1.tex b/day1/session1.tex index 47051cc..48cd878 100644 --- a/day1/session1.tex +++ b/day1/session1.tex @@ -77,7 +77,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {7 November, 2009\\Day 1, Session 1} +\date[] {11 January, 2010\\Day 1, Session 1} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -125,28 +125,28 @@ \begin{frame} \frametitle{Workshop Schedule: Day 1} \begin{description} - \item[Session 1] Sat 09:00--10:00 - \item[Session 2] Sat 10:05--11:05 - \item[Session 3] Sat 11:20--12:20 - \item[Session 4] Sat 12:25--13:25 - \item[Quiz 1] Sat 14:25--14:40 - \item[Session 5] Sat 14:40--15:25 - \item[Session 6] Sat 15:40--16:40 - \item[Quiz 2] Sat 16:45--17:00 + \item[Session 1] Mon 09:00--10:00 + \item[Session 2] Mon 10:05--11:05 + \item[Session 3] Mon 11:20--12:20 + \item[Session 4] Mon 12:25--13:25 + \item[Quiz 1] Mon 14:25--14:40 + \item[Exercises] Mon 14:40--15:25 + \item[Session 5] Mon 15:40--16:40 + \item[Quiz 2] Mon 16:45--17:00 \end{description} \end{frame} \begin{frame} \frametitle{Workshop Schedule: Day 2} \begin{description} - \item[Session 1] Sun 09:00--10:00 - \item[Session 2] Sun 10:05--11:05 - \item[Session 3] Sun 11:20--12:20 - \item[Session 4] Sun 12:25--13:25 - \item[Quiz 1] Sun 14:25--14:40 - \item[Session 5] Sun 14:40--15:25 - \item[Session 6] Sun 15:40--16:40 - \item[Quiz 2] Sun 16:45--17:00 + \item[Session 1] Tue 09:00--10:00 + \item[Session 2] Tue 10:05--11:05 + \item[Session 3] Tue 11:20--12:20 + \item[Session 4] Tue 12:25--13:25 + \item[Quiz 1] Tue 14:25--14:40 + \item[Exercises] Tue 14:40--15:25 + \item[Session 5] Tue 15:40--16:40 + \item[Quiz 2] Tue 16:45--17:00 \end{description} \end{frame} @@ -189,7 +189,6 @@ \item Images \begin{itemize} \item \typ{lena.png} - \item \typ{smoothing.gif} \end{itemize} \end{enumerate} \end{frame} @@ -197,9 +196,9 @@ \begin{frame}[fragile] \frametitle{Starting up \ldots} \begin{block}{} -\begin{verbatim} +\begin{lstlisting} $ ipython -pylab -\end{verbatim} +\end{lstlisting} %$ \end{block} \begin{lstlisting} In []: print "Hello, World!" @@ -448,25 +447,36 @@ In []: ylim(ymin-0.2, ymax+0.2) \item Annotate the origin \item Set axes limits to the range of x \end{enumerate} +\vspace*{-0.1in} +\begin{center} + \includegraphics[height=2.1in, interpolate=true]{data/four_plot} +\end{center} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Review Problem \ldots} +\alert{Plotting \ldots} \begin{lstlisting} In []: x=linspace(-5*pi, 5*pi, 500) In []: plot(x, x, 'b') In []: plot(x, -x, 'b') +In []: plot(x, sin(x), 'g', linewidth=2) +In []: plot(x, x*sin(x), 'r', + linewidth=3) \end{lstlisting} $\vdots$ \end{frame} \begin{frame}[fragile] \frametitle{Review Problem \ldots} -\begin{lstlisting} -In []: plot(x, sin(x), 'g', linewidth=2) -In []: plot(x, x*sin(x), 'r', - linewidth=3) -\end{lstlisting} +\alert{Legend \& Annotation\ldots} \begin{lstlisting} In []: legend(['x', '-x', 'sin(x)', 'xsin(x)']) In []: annotate('origin', xy = (0, 0)) +\end{lstlisting} +\alert{Setting Axes limits\ldots} +\begin{lstlisting} In []: xlim(-5*pi, 5*pi) In []: ylim(-5*pi, 5*pi) \end{lstlisting} diff --git a/day1/session2.tex b/day1/session2.tex index 73637c9..12dbb58 100644 --- a/day1/session2.tex +++ b/day1/session2.tex @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {7 November, 2009\\Day 1, Session 2} +\date[] {11 January, 2010\\Day 1, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -418,12 +418,12 @@ Out[]: ['hello', 'world'] \end{lstlisting} This is what happens with \typ{line} \begin{lstlisting} -In []: line = '1.2000e-01 7.4252e-01' +In []: line = '1.20 7.42' In []: point = line.split() In []: point -Out[]: ['1.2000e-01', '7.4252e-01'] +Out[]: ['1.20', '7.42'] \end{lstlisting} \end{frame} diff --git a/day1/session3.tex b/day1/session3.tex index 3db46b3..c769fe5 100644 --- a/day1/session3.tex +++ b/day1/session3.tex @@ -79,7 +79,7 @@ \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {7 November, 2009\\Day 1, Session 3} +\date[] {11 January, 2010\\Day 1, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -147,7 +147,7 @@ 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 = 4 * pi * pi * l / (t * t) .... G.append(g) \end{lstlisting} \end{frame} @@ -166,8 +166,8 @@ total = 0 for g in G: total += g -g_mean = total / len(g) -print "Mean: ", g_mean +g_mean = total / len(G) +print 'Mean: ', g_mean \end{lstlisting} \end{frame} @@ -175,7 +175,7 @@ print "Mean: ", g_mean \frametitle{Mean ``g''} \begin{lstlisting} g_mean = sum(G) / len(G) -print "Mean: ", g_mean +print 'Mean: ', g_mean \end{lstlisting} \end{frame} @@ -183,7 +183,7 @@ print "Mean: ", g_mean \frametitle{Mean ``g''} \begin{lstlisting} g_mean = mean(G) -print "Mean: ", g_mean +print 'Mean: ', g_mean \end{lstlisting} \inctime{10} \end{frame} @@ -277,11 +277,11 @@ for record in open('sslc1.txt'): \begin{frame}[fragile] \frametitle{Dictionaries \ldots} \begin{lstlisting} -In []: d = {"jpg" : "image file", - "txt" : "text file", - "py" : "python code"} +In []: d = {'jpg' : 'image file', + 'txt' : 'text file', + 'py' : 'python code'} -In []: d["txt"] +In []: d['txt'] Out[]: 'text file' \end{lstlisting} \end{frame} @@ -289,10 +289,10 @@ Out[]: 'text file' \begin{frame}[fragile] \frametitle{Dictionaries \ldots} \begin{lstlisting} -In []: "py" in d +In []: 'py' in d Out[]: True -In []: "cpp" in d +In []: 'cpp' in d Out[]: False \end{lstlisting} \end{frame} @@ -417,11 +417,11 @@ for record in open('sslc1.txt'): \begin{frame}[fragile] \frametitle{Obtaining statistics} \begin{lstlisting} -print "Mean: ", mean(math_scores) +print 'Mean: ', mean(math_scores) -print "Median: ", median(math_scores) +print 'Median: ', median(math_scores) -print "Standard Deviation: ", +print 'Standard Deviation: ', std(math_scores) \end{lstlisting} \inctime{10} @@ -432,11 +432,11 @@ print "Standard Deviation: ", \begin{lstlisting} math_array = array(math_scores) -print "Mean: ", mean(math_array) +print 'Mean: ', mean(math_array) -print "Median: ", median(math_array) +print 'Median: ', median(math_array) -print "Standard Deviation: ", +print 'Standard Deviation: ', std(math_array) \end{lstlisting} \inctime{5} diff --git a/day1/session4.tex b/day1/session4.tex index 3cff99c..bfff165 100644 --- a/day1/session4.tex +++ b/day1/session4.tex @@ -79,7 +79,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {7 November, 2009\\Day 1, Session 4} +\date[] {11 January, 2010\\Day 1, Session 4} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -287,8 +287,6 @@ In []: a = imread('lena.png') In []: imshow(a) Out[]: <matplotlib.image.AxesImage object at 0xa0384cc> -In []: a.shape -Out[]: (512, 512, 4) \end{lstlisting} \end{small} \begin{itemize} @@ -317,6 +315,11 @@ Out[]: <matplotlib.image.AxesImage object at 0xb765c8c> \begin{frame}[fragile] \frametitle{Transpose of a Matrix} \begin{lstlisting} +In []: a = array([[ 1, 1, 2, -1], + ...: [ 2, 5, -1, -9], + ...: [ 2, 1, -1, 3], + ...: [ 1, -3, 2, 7]]) + In []: a.T Out[]: array([[ 1, 2, 2, 1], @@ -485,7 +488,14 @@ Out[]: array([-1., 8., -1.]) \frametitle{\typ{lstsq}} \begin{itemize} \item We need to fit a line through points for the equation $T^2 = m \cdot L+c$ -\item In matrix form, the equation can be represented as $T^2 = A \cdot p$, where A is +\item In matrix form, the equation can be represented as $T_{sq} = A \cdot p$, where $T_{sq}$ is + $\begin{bmatrix} + T^2_1 \\ + T^2_2 \\ + \vdots\\ + T^2_N \\ + \end{bmatrix}$ +, A is $\begin{bmatrix} L_1 & 1 \\ L_2 & 1 \\ diff --git a/day1/session5.tex b/day1/session5.tex index 22a274d..326e8fe 100644 --- a/day1/session5.tex +++ b/day1/session5.tex @@ -79,7 +79,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {31, October 2009\\Day 1, Session 5} +\date[] {11, January 2010\\Day 1, Session 5} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} diff --git a/day1/session6.tex b/day1/session6.tex index 0f1523e..0f2120f 100755 --- a/day1/session6.tex +++ b/day1/session6.tex @@ -78,7 +78,7 @@ \author[FOSSEE] {FOSSEE} \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -\date[] {7 November, 2009\\Day 1, Session 6} +\date[] {11 January, 2010\\Day 1, Session 6} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -150,7 +150,6 @@ Let us now look at how to solve this using \kwrd{matrices} [-1, 0.5, -1]]) In []: b = array([[1], [-2], [0]]) In []: x = solve(A, b) - In []: Ax = dot(A,x) \end{lstlisting} \end{frame} @@ -168,6 +167,7 @@ array([[ 1.], \begin{frame}[fragile] \frametitle{Let's check!} \begin{lstlisting} +In []: Ax = dot(A,x) In []: Ax Out[]: array([[ 1.00000000e+00], @@ -216,11 +216,17 @@ Use \kwrd{solve()} \frametitle{Scipy Methods - \typ{roots}} \begin{itemize} \item Calculates the roots of polynomials +\item To calculate the roots of $x^2-5x+6$ \end{itemize} \begin{lstlisting} - In []: coeffs = [1, 6, 13] + In []: coeffs = [1, -5, 6] In []: roots(coeffs) + Out[]: array([3., 2.]) \end{lstlisting} +\vspace*{-.2in} +\begin{center} +\includegraphics[height=1.6in, interpolate=true]{data/roots} +\end{center} \end{frame} \begin{frame}[fragile] @@ -291,6 +297,9 @@ Find the root of $sin(x)+cos^2(x)$ nearest to $0$ In []: fsolve(f, 0) Out[]: -0.66623943249251527 \end{lstlisting} +\begin{center} +\includegraphics[height=2in, interpolate=true]{data/fsolve} +\end{center} \end{frame} %% \begin{frame}[fragile] @@ -318,6 +327,7 @@ Out[]: -0.66623943249251527 \item Define a function as below \end{itemize} \begin{lstlisting} +In []: from scipy.integrate import odeint In []: def epid(y, t): .... k, L = 0.00003, 25000 .... return k*y*(L-y) @@ -338,6 +348,14 @@ In []: plot(t, y) \end{frame} \begin{frame}[fragile] +\frametitle{Result} +\begin{center} +\includegraphics[height=2in, interpolate=true]{data/image} +\end{center} +\end{frame} + + +\begin{frame}[fragile] \frametitle{ODEs - Simple Pendulum} We shall use the simple ODE of a simple pendulum. \begin{equation*} @@ -392,6 +410,12 @@ In []: pend_sol = odeint(pend_int, \end{lstlisting} \end{frame} +\begin{frame}[fragile] +\frametitle{Result} +\begin{center} +\includegraphics[height=2in, interpolate=true]{data/ode} +\end{center} +\end{frame} \begin{frame} \frametitle{Things we have learned} |