diff options
Diffstat (limited to 'day1')
-rwxr-xr-x | day1/cheatsheet1.tex | 140 | ||||
-rwxr-xr-x | day1/cheatsheet2.tex | 162 | ||||
-rwxr-xr-x | day1/cheatsheet3.tex | 4 | ||||
-rwxr-xr-x | day1/cheatsheet4.tex | 111 | ||||
-rwxr-xr-x | day1/cheatsheet6.tex | 145 | ||||
-rw-r--r-- | day1/data/image.png | bin | 0 -> 19554 bytes | |||
-rw-r--r-- | day1/data/ode.png | bin | 0 -> 59610 bytes | |||
-rw-r--r-- | day1/exercises.tex | 2 | ||||
-rw-r--r-- | day1/session1.tex | 117 | ||||
-rw-r--r-- | day1/session2.tex | 10 | ||||
-rw-r--r-- | day1/session3.tex | 2 | ||||
-rw-r--r-- | day1/session4.tex | 144 | ||||
-rwxr-xr-x | day1/session6.tex | 21 |
13 files changed, 583 insertions, 275 deletions
diff --git a/day1/cheatsheet1.tex b/day1/cheatsheet1.tex index 26edf77..00488c8 100755 --- a/day1/cheatsheet1.tex +++ b/day1/cheatsheet1.tex @@ -6,7 +6,8 @@ \usepackage{listings} \lstset{language=Python, basicstyle=\ttfamily, -commentstyle=\itshape\bfseries +commentstyle=\itshape\bfseries, +showstringspaces=false, } \newcommand{\typ}[1]{\lstinline{#1}} \usepackage[english]{babel} @@ -33,49 +34,118 @@ Exiting \begin{lstlisting} In [2]: (Ctrl-D)^D Do you really want to exit ([y]/n)? y -\end{lstlisting} +\end{lstlisting} %$ \section{Plotting} +\subsection{linspace} +\typ{In []: x = linspace(start, stop, num)}\\ +\typ{linspace} returns array of length \typ{num}, for which \typ{x[0] = start} and \typ{x[num-1] = stop} \\ +\emph{Please note indices of array starts from zero(0)} + +\subsection{plot} +\typ{In []: plot(X, Y)}\\ +For given arrays of equal length(above case X and Y), \typ{plot} plots the corresponding *x* and *y* pairs taken from X and Y. + +\subsection{Colors of plots} +\typ{In []: plot(y, sin(y), 'g')}\\ +Plots graph with green color. Other options available are: +\begin{lstlisting} + 'r' ---> Red + 'b' ---> Blue + 'r' ---> Red + 'c' ---> Cyan + 'm' ---> Magenta + 'y' ---> Yellow + 'k' ---> Black + 'w' ---> White +\end{lstlisting} +One can set the width of the plotline using optional argument \typ{linewidth}. For example:\\ +\typ{In []: plot(x, cos(x), 'r', linewidth=2)}\\ +Plots the line with linewidth = 2 +\subsection{label and title} +\typ{In []: xlabel('Length') #sets *x* axis label to Length}\\ +\typ{In []: ylabel('Time') #sets *y* axis label to Time.}\\ +\typ{In []: title('Sinusoid') #sets title of plot}\\ +\\ +\textbf{Additionally}\\ +Pylab accepts TeX equation expressions in any text expression. To get something like:\\ +$\sigma_i=15$ \\ +on title of figure use: +\begin{lstlisting} +In []: title('$\sigma_i=15$') +\end{lstlisting} +Same way one can have TeX expression on xlabel, ylabel etc. + +\subsection{legends} +\typ{In []: legend('sin(x)',loc=center)} \\ +Place a legend on the current plot at location *loc*.\\ +Apart from \typ{center}, some other \typ{loc} which can be specified are: +\begin{lstlisting} +'best' +'right' +'upper right' +'upper left' +'lower left' +'lower right' +'center left' +'center right' +'lower center' +'upper center' +\end{lstlisting} +\newpage +One can also mention explicit co-ordinates for placement of legend. +\begin{lstlisting} +In []: legend(['sin(2y)'], loc=(.8,.1)) +\end{lstlisting} +\typ{loc = 0, 1} (top left position of graph)\\ +\typ{loc = 0.5, 0.5} (center of graph). - \begin{lstlisting} -In [1]: x = linspace(0, 2*pi, 50) -In [2]: plot(x, sin(x)) -In [3]: xlabel('x') -In [4]: ylabel('sin(x)') -In [5]: title('Sinusoids') -In [6]: legend(['sin(y)']) -In [7]: legend(['sin(2y)'], loc = 'center') -# loc = 'upper right', 'upper left', 'lower left, 'lower right', 'center left', -# 'center right', 'lower center', 'upper center', 'best', 'right', 'center' - -In [8]: legend(['sin(2y)'], loc = (.8, .1)) - -In [9]: savefig('sin.png') # Save figure -In [10]: close() # Closes the figure - -In [11]: clf() # Clears the Plot area - -In [12]: plot(y, sin(y), 'g') -# Colors can be: 'b', 'g', 'r', 'c', 'm', 'y', 'k', 'w' - -In [13]: plot(y, cos(y), 'r', linewidth=2) +\subsection{Annotate} +\typ{In []: annotate('local max', xy=(1.5, 1))}\\ +Annotates current plot with text, 'local max', at position specified to \typ{xy}. -In [14]: legend(['x', '-x']) -In [15]: annotate('origin', xy=(0, 0)) +\subsection{Saving figures} +\typ{In []: savefig('sinusoids.png')}\\ +Saves the current figure with file name 'sinusoids.png' in current working directory. One can save figure in any of these formats: png, pdf, ps, eps and svg. -In [16]: xmin, xman = xlim() # Without arguments gets -In [17]: ymin, ymax = ylim() # values +\subsection{Miscellaneous} +\typ{In []: clf() #Clears the current plot area}\\ +\typ{In []: close() #Closes the figure} +\section{Saving and running scripts} +\begin{itemize} + \item \typ{\%hist}\\ + It returns the logs of all commands(including mistakes) used in IPython interpreter. + \item \typ{\%hist -n}\\ +It disables the line number representation of logs. + \item \typ{\%save four\_plot.py 16 18-27}\\ +For creating a script named four\_plot which includes line 16 and line 18 to 27 of logs. + \item \typ{\%run -i four\_plot.py}\\ +Running the python script inside IPython interpreter. +\end{itemize} -In [18]: xlim(0, 2 * pi) # With values, sets the -In [19]: ylim(ymin - 0.2, ymax + 0.2) # specified values +\section{Example} + \begin{lstlisting} +In []: x = linspace(0, 2*pi, 50) +In []: plot(x, sin(x), 'g') +In []: plot(x, cos(x), 'r', linewidth=2) +In []: xlabel('x') +In []: title('Sinusoidal Waves') +In []: legend(['sin(x)', 'cos(x)']) +In []: annotate('origin', xy=(0, 0)) +In []: xmin, xman = xlim() # returns current X axis limits. +In []: ymin, ymax = ylim() +In []: xlim(0, 2 * pi) # sets the X axis limits to passed values +In []: ylim(ymin - 0.2, ymax + 0.2) + +In []: savefig('sin.png') # Save figure +In []: close() \end{lstlisting} -\section{Saving and running scripts} +\section{References} \begin{itemize} - \item \typ{\%hist} - \item \typ{\%save four\_plot.py 16 18-27} - \item \typ{\%run -i four\_plot.py} + \item For documentation on IPython refer: \\ http://ipython.scipy.org/moin/Documentation + \item Plotting(matplotlib) related documentation are available at:\\ http://matplotlib.sourceforge.net/contents.html + \item Explore examples and plots based on matplotlib at \\ http://matplotlib.sourceforge.net/examples/index.html \end{itemize} - \end{document} diff --git a/day1/cheatsheet2.tex b/day1/cheatsheet2.tex index 9823aa3..fa76388 100755 --- a/day1/cheatsheet2.tex +++ b/day1/cheatsheet2.tex @@ -25,87 +25,135 @@ \LARGE{Plotting Points}\\ \large{FOSSEE} \end{center} -\section{Plotting from Data files} -\begin{verbatim} -l = [] #Empty List -t = [] -for line in open('pendulum.txt'): # Opening & Reading files - points = line.split() # Splitting a string - l.append(float(points[0])) # Appending to a list - t.append(float(points[1])) -tsq = [] -for time in t: #Iterating through lists - tsq.append(t*t) -plot(l, tsq, '.') # Plotting points -\end{verbatim} + \section{Plotting Points with Lists} \begin{lstlisting} -In [1]: x = [0, 1, 2, 3] -In [2]: y = [7, 11, 15, 19] -In [3]: plot(x, y) -In [4]: clf() -In [5]: plot(x, y, 'o') # Plotting Circles -#Dots - '.', #Dashed lines - '--' #Lines - '-' +In []: x = [0, 1, 2, 3] # Creating a list +In []: y = [7, 11, 15, 19] +In []: plot(x, y) +In []: clf() +In []: plot(x, y, 'o') # Plotting Circles +\end{lstlisting} + +\subsection{Line style/marker} +\begin{lstlisting} +The following format string characters are accepted +to control the line style or marker: + + ================ =============================== + character description + ================ =============================== + '-' solid line style + '--' dashed line style + '-.' dash-dot line style + ':' dotted line style + '.' point marker + ',' pixel marker + 'o' circle marker + 'v' triangle_down marker + '^' triangle_up marker + '<' triangle_left marker + '>' triangle_right marker + '1' tri_down marker + '2' tri_up marker + '3' tri_left marker + '4' tri_right marker + 's' square marker + 'p' pentagon marker + '*' star marker + 'h' hexagon1 marker + 'H' hexagon2 marker + '+' plus marker + 'x' x marker + 'D' diamond marker + 'd' thin_diamond marker + '|' vline marker + '_' hline marker + ================ =============================== + \end{lstlisting} +\subsection{Marker combinations} +\typ{In []: plot(x, y, 'ro')} \\ +This plots figure with red colored filled circles.\\ +Similarly other combination of colors and marker can be used. \section{Lists} Initializing \begin{lstlisting} -In [10]: mtlist = [] # Empty List -In [11]: lst = [ 1, 2, 3, 4, 5] +In []: mtlist = [] # Empty List +In []: lst = [ 1, 2, 3, 4, 5] \end{lstlisting} Slicing \begin{lstlisting} -In [12]: lst[1:3] # A slice. -Out[12]: [2, 3] +In []: lst[1:3] # A slice. +Out[]: [2, 3] -In [13]: lst[1:-1] -Out[13]: [2, 3, 4] +In []: lst[1:-1] +Out[]: [2, 3, 4] \end{lstlisting} -Appending to lists +\subsection{Appending to lists} \begin{lstlisting} -In [14]: a = [ 6, 7, 8, 9] -In [15]: b = lst + a -In [16]: b -Out[16]: [1, 2, 3, 4, 5, 6, 7, 8, 9] - -In [17]: lst.append(6) -In [18]: lst -Out[18]: [ 1, 2, 3, 4, 5, 6] -\end{lstlisting} +In []: a = [ 6, 7, 8, 9] +In []: b = lst + a +In []: b +Out[]: [1, 2, 3, 4, 5, 6, 7, 8, 9] -Iterating over a List +In []: lst.append(6) +In []: lst +Out[]: [ 1, 2, 3, 4, 5, 6] +\end{lstlisting} +\subsection{Iterating over a List} \begin{lstlisting} -In [19]: for each in b: # Iterating over the list, element-wise - ....: print b # Print each element +In []: for element in b: # Iterating over the list, element-wise + ....: print element # Print each element ....: \end{lstlisting} -Splitting Strings +\section{Strings} +\subsection{Splitting Strings} +\begin{lstlisting} +In []: greet = ``hello world'' +In []: print greet.split() +Out[]: ['hello', 'world'] +In []: greet = ``hello, world'' +In []: print greet.split(',') +Out[]: ['hello', ' world'] # Note the whitespace before 'world' +\end{lstlisting} +A string can be split based on the delimiter specified within quotes. A combination of more than one delimiter can also be used.\\ +\typ{In []: greet.split(', ')}\\ +\typ{Out[]: ['hello', 'world']}\\Note the whitespace is not there anymore. +\newpage +\section{Plotting from Files} +\subsection{Opening files} + +\typ{In []: f = open('datafile.txt')}\\By default opens in read mode. \\If file does not exist then it throws an exception\\ +\typ{In []: f = open('datafile.txt','r')}\\Specifying the read mode\\ +\typ{In []: f = open('datafile.txt', 'w')}\\Opens the file in write mode. \\If the file already exists, then it deletes all the previous content and opens. + +\subsection{Reading from files} +Just like lists files are iterable as well. + \begin{lstlisting} -In [20]: line = '1.2000e-01 7.4252e-01' -In [21]: point = line.split() # Splits the string at the space -Out[21]: ['1.2000e-01', '7.4252e-01'] + In []: for line in f: + ...: print line + ...: + ...: \end{lstlisting} -Plotting from Files +\subsection{Plotting} \begin{lstlisting} -In [22]: L = [] -In [23]: T = [] - -#Open a file & operate on each line -In [24]: for line in open('pendulum.txt'): - .... point = line.split() - .... L.append(float(point[0])) - .... T.append(float(point[1])) -In [25]: TSq = [] -In [26]: for t in T: - ....: TSq.append(t*t) - ....: - ....: -In [27]: plot(L, TSq, '.') +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{document} 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 a7a6a6e..d89e8a2 100755 --- a/day1/cheatsheet4.tex +++ b/day1/cheatsheet4.tex @@ -24,25 +24,42 @@ \large{FOSSEE} \end{center} \section{Matrices} -Inputting a Matrix +\subsection{Basics} +Matrix Creation\\ +\typ{In []: C = array([[1,1,2], [2,4,1], [-1,3,7]])}\\ +It creates C matrix of shape 3x3\\ +Shape is dimensions of given array. \begin{lstlisting} -In []: C = array([[1,1,2], - [2,4,1], - [-1,3,7]]) -In []: B = ones_like(C) -In []: A = ones((3,2)) -In []: I = identity(3) +In []: C.shape +Out[]: (3, 3) +In []: shape([[1,2],[4,5],[3,0]]) +Out[]: (3, 2) \end{lstlisting} -Accessing Elements +\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 matrix of given shape(arguments), filled with ones.\\ +\typ{In []: I = identity(3)}\\ +I would be identity matrix of shape 3x3 + +\subsection{Accessing Elements} \begin{lstlisting} +In []: C +Out[]: +array([[ 1, 1, 2], + [ 2, 4, 1], + [-1, 3, 7]]) In []: C[1,2] Out[]: 1 - +\end{lstlisting} +Two indexes seperated by \typ{','} specifies [row, column]. So \typ{C[1,2]} gets third element of second row(indices starts from 0). +\newpage +\begin{lstlisting} In []: C[1] Out[]: array([2, 4, 1]) \end{lstlisting} - -Changing elements +Single index implies complete row. +\subsection{Changing elements} \begin{lstlisting} In []: C[1,1] = -2 In []: C @@ -59,19 +76,27 @@ array([[ 1, 1, 2], [-1, 3, 7]]) \end{lstlisting} -Slicing +\subsection{Slicing} +Accessing rows with Matrices is straightforward. But If one wants to access particular Column, or want a sub-matrix, Slicing is the way to go. \begin{lstlisting} In []: C[:,1] Out[]: array([1, 0, 3]) - +\end{lstlisting} +First index(:) specifies row(':' implies all the rows) and second index(1) specifies column(second column). +\begin{lstlisting} In []: C[1,:] Out[]: array([0, 0, 0]) - +\end{lstlisting} +Here we get second row(1), all columns(':') of C matrix. +\newpage +\begin{lstlisting} In []: C[0:2,:] Out[]: array([[1, 1, 2], [0, 0, 0]]) - +\end{lstlisting} +Result is sub-matrix with first and second row(endpoint is excluded), and all columns from C. +\begin{lstlisting} In []: C[1:3,:] Out[]: array([[ 0, 0, 0], @@ -81,7 +106,9 @@ In []: C[:2,:] Out[]: array([[1, 1, 2], [0, 0, 0]]) - +\end{lstlisting} +\typ{':2'} => start from first row, till and excluding third row. +\begin{lstlisting} In []: C[1:,:] Out[]: array([[ 0, 0, 0], @@ -92,36 +119,45 @@ Out[]: array([[ 0, 0], [-1, 3]]) \end{lstlisting} - -Striding +\typ{'1:'} => Start from second row, till last row\\ +\typ{':2'} => Start from first column, till and excluding third column. +\newpage +\subsection{Striding} +Often apart from submatrix, one needs to get some mechanism to jump a step. For example, how can we have all alternate rows of a Matrix. \\ +Following method will return Matrix with alternate rows. \begin{lstlisting} In []: C[::2,:] Out[]: array([[ 1, 1, 2], [-1, 3, 7]]) - +\end{lstlisting} +\typ{C[startR:stopR:stepR,startC:stopC:stepC]} => Syntax of mentioning starting index, ending index, and step to jump.\\ +In above mentioned case, \typ{'::2'} means, start from first row, till last row(both are blank), with step of 2, that is, skipping alternate row. After first row, C[startR], next row would be C[startR+stepR] and so on. +\begin{lstlisting} In []: C[:,::2] Out[]: xarray([[ 1, 2], [ 0, 0], [-1, 7]]) - +\end{lstlisting} +Same as above, just that here we get matrix with each alternate column and all rows. +\begin{lstlisting} In []: C[::2,::2] Out[]: array([[ 1, 2], [-1, 7]]) \end{lstlisting} - -Matrix Operations +\section{Matrix Operations} +For a Matrix A and B of equal shapes. \begin{lstlisting} In []: A.T # Transpose In []: sum(A) # Sum of all elements In []: A+B # Addition -In []: A*B # Product +In []: A*B # Element wise product +In []: dot(A,b) #Matrix multiplication In []: inv(A) # Inverse In []: det(A) # Determinant \end{lstlisting} - Eigen Values and Eigen Vectors \begin{lstlisting} In []: eig(A) #Eigen Values and Vectors @@ -135,14 +171,33 @@ In []: eigvals(A) #Eigen Values %% \begin{lstlisting} %% In []: svd(A) %% \end{lstlisting} -Least Square Fit Line +\section{Least Square Fit Line} +\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} +This is exact curve we get from L Vs Tsq from data.This relation among L and Tsq is not of straight line. For getting Least Square Fit line, we have to solve the relations:\\ +$L=m*Tsq+c$ (something similar to $y=m*x+c$)\\ +For present scenario, we have L and corresponding Tsq values. For finding m and c at given points we use \typ{lstlq} function provided by pylab. It returns the least-squares solution to an equation. \\ +For finding Least Square Fit line for this particular data we have to do following steps:\\ +\typ{In []: A = array([L, ones\_like(L)])}\\ +A is 2x(Length of array L) array. \begin{lstlisting} -In []: A = array([L, ones_like(L)]) -In []: A = A.T +In []: A = A.T #now A.shape = (Length of array L)x2 In []: result = lstsq(A,TSq) In []: coef = result[0] In []: Tline = coef[0]*L + coef[1] -In []: plot(L, Tline) \end{lstlisting} +\typ{coef[0]} is array with all $m$ values, and \typ{coef[1]} contains $c$.\\ +To get the final plot.\\ +\typ{In []: plot(L, Tline)} \end{document} diff --git a/day1/cheatsheet6.tex b/day1/cheatsheet6.tex index 2e9de97..7eddb8f 100755 --- a/day1/cheatsheet6.tex +++ b/day1/cheatsheet6.tex @@ -1,6 +1,21 @@ \documentclass[12pt]{article} \title{Solving Equations \& ODEs} \author{FOSSEE} +\usepackage{listings} +\lstset{language=Python, + basicstyle=\ttfamily, +commentstyle=\itshape\bfseries, +showstringspaces=false, +} +\newcommand{\typ}[1]{\lstinline{#1}} +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage{times} +\usepackage[T1]{fontenc} +\usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} +\usepackage[scaled=.95]{helvet} +\usepackage{amsmath} \begin{document} \date{} \vspace{-1in} @@ -9,36 +24,112 @@ \large{FOSSEE} \end{center} \section{Solving linear equations} -\begin{verbatim} - In []: A = array([[3,2,-1], - [2,-2,4], - [-1, 0.5, -1]]) - In []: b = array([[1], [-2], [0]]) - In []: x = solve(A, b) - In []: Ax = dot(A,x) - In []: allclose(Ax, b) - Out[]: True -\end{verbatim} +Condier following sets of equations:\\ + \begin{align*} + 3x + 2y - z & = 1 \\ + 2x - 2y + 4z & = -2 \\ + -x + \frac{1}{2}y -z & = 0 + \end{align*}\\ +The matrix representation is:\\ +\begin{center} +$A*x = B$ +\end{center} +Where A is coefficient matrix(in this case 3x3)\\ +B is constant matrix(1x3)\\ +x is the required solution.\\ +\begin{lstlisting} +In []: A = array([[3,2,-1], [2,-2,4], [-1, 0.5, -1]]) +In []: B = array([[1], [-2], [0]]) +In []: x = solve(A, B) +\end{lstlisting} +Solve the equation $A x = B$ for $x$.\\ +To check whether solution is correct try this: +\begin{lstlisting} +In []: Ax = dot(A,x) #Matrix multiplication of A and x(LHS) +In []: allclose(Ax, B) +Out[]: True +\end{lstlisting} +\typ{allclose} Returns \typ{True} if two arrays(in above case Ax and B) are element-wise equal within a tolerance. +\newpage \section{Finding roots} -\begin{verbatim} - In []: coeffs = [1, 6, 13] - In []: roots(coeffs) -\end{verbatim} -Finding the roots of a function -\begin{verbatim} -In []: fsolve(sin(x)+cos(x)**2, 0) -\end{verbatim} +\subsection{Polynomials} +\begin{center} + $x^2+6x+13=0$ +\end{center} +to find roots, pylab provides \typ{roots} function. +\begin{lstlisting} +In []: coeffs = [1, 6, 13] #list of all coefficients +In []: roots(coeffs) +\end{lstlisting} +\subsection{functions} +Functions can be defined and used by following syntax: +\begin{lstlisting} +def func_name(arg1, arg2): + #function code + return ret_value +\end{lstlisting} +A simple example can be +\begin{lstlisting} +def expression(x): + y = x*sin(x) + return y +\end{lstlisting} +Above function when called with a argument, will return $xsin(x)$ value for that argument. +\begin{lstlisting} +In [95]: expression(pi/2) +Out[95]: 1.5707963267948966 + +In [96]: expression(pi/3) +Out[96]: 0.90689968211710881 +\end{lstlisting} +\subsection{Roots of non-linear equations} +For Finding the roots of a non linear equation(defined as $f(x)=0$), around a starting estimate we use \typ{fsolve}:\\ +\typ{In []: from scipy.optimize import fsolve}\\ +\typ{fsolve} is not a part of \typ{pylab}, instead is a function in the \textbf{optimize} module of \textbf{scipy}, and hence we \textbf{import} it.\\ +%\typ{fsolve} takes first argument as name of function, which evaluates $f(x)$, whose roots one wants to find. And second argument is starting estimate, around which roots are found. +For illustration, we want to find roots of equation: +\begin{center} + $f(x)=sin(x)+cos(x)^2$ +\end{center} +So just like we did above, we define a function: +\begin{lstlisting} +In []: def f(x): + ....: return sin(x)+cos(x)**2 + ....: +\end{lstlisting} +Now to find roots of this non linear equation, around a initial estimate value, say 0, we use \typ{fsolve} in following way: +\begin{lstlisting} +In []: fsolve(f, 0) #arguments are function name and estimate +Out[]: -0.66623943249251527 +\end{lstlisting} + \section{ODE} -\begin{verbatim} - In []: def epid(y, t): + +We wish to solve an (a system of) Ordinary Differential Equation. For this purpose, we shall use \typ{odeint}.\\ +\typ{In []: from scipy.integrate import odeint}\\ +\typ{odeint} is a function in the \textbf{integrate} module of \textbf{scipy}.\\ +As an illustration, let us solve the ODE below:\\ +$\frac{dy}{dt} = ky(L-y)$, L = 25000, k = 0.00003, y(0) = 250\\ +We define a function (as below) that takes $y$ and time as arguments and returns the right hand side of the ODE. +\begin{lstlisting} +In []: def f(y, t): .... k, L = 0.00003, 25000 .... return k*y*(L-y) .... - - In []: t = arange(0, 12, 0.2) - - In []: y = odeint(epid, 250, t) - - In []: plot(t, y) -\end{verbatim} +\end{lstlisting} +Next we define the time over which we wish to solve the ODE. We also note the initial conditions given to us. +\begin{lstlisting} +In []: t = linspace(0, 12, 61) +In []: y0 = 250 +\end{lstlisting} +To solve the ODE, we call the \typ{odeint} function with three arguments - the function \typ{f}, initial conditions and the time vector. +\begin{lstlisting} +In []: y = odeint(f, y0, t) +\end{lstlisting} +Note: To solve a system of ODEs, we need to change the function to return the right hand side of all the equations and the system and the pass the required number of initial conditions to the \typ{odeint} function. +\section{Links and References} +\begin{itemize} +\item Documentation for Numpy and Scipy is available at:\\ http://docs.scipy.org/doc/ + \item For "recipes" or worked examples of commonly-done tasks in SciPy explore: \\ http://www.scipy.org/Cookbook/ +\end{itemize} \end{document} 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/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/exercises.tex b/day1/exercises.tex index da88e05..91310ef 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[] {14 December, 2009\\Day 1, Session 5} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} diff --git a/day1/session1.tex b/day1/session1.tex index 125f823..e3040a0 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[] {14 December, 2009\\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} @@ -162,7 +162,7 @@ \begin{block}{Goal: Successful participants will be able to} \begin{itemize} \item Use Python as plotting, computational tool - \item Understand how Python can be used as a scripting and problem solving language. + \item Understand how to use Python as a scripting and problem solving language. \item Train students for the same \end{itemize} \end{block} @@ -186,15 +186,19 @@ \item \typ{sslc_allreg.py} \item \typ{sslc_science.py} \end{itemize} + \item Images + \begin{itemize} + \item \typ{lena.png} + \end{itemize} \end{enumerate} \end{frame} \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!" @@ -290,7 +294,9 @@ In []: ylabel('sin(x)') \frametitle{Another example} \begin{lstlisting} In []: clf() -#Clears the plot area. + \end{lstlisting} +\emphbar{Clears the plot area.} + \begin{lstlisting} In []: y = linspace(0, 2*pi, 50) In []: plot(y, sin(2*y)) In []: xlabel('y') @@ -306,7 +312,6 @@ In []: ylabel('sin(2y)') % \small \begin{lstlisting} In []: title('Sinusoids') -#Sets the title of the figure In []: legend(['sin(2y)']) \end{lstlisting} % \small @@ -329,37 +334,29 @@ In []: legend(['sin(2y)'], loc = 'center') \begin{columns} \column{0.6\textwidth} \includegraphics[height=2in, interpolate=true]{data/position} -\begin{lstlisting} -'best', 'right', 'center' -\end{lstlisting} \column{0.45\textwidth} \vspace{-0.2in} \begin{lstlisting} -'upper right' -'upper left' -'lower left' -'lower right' -'center left' -'center right' -'lower center' -'upper center' +'best' +'right' +'center' \end{lstlisting} \end{columns} \end{frame} -\begin{frame}[fragile] - \frametitle{For arbitrary location} -\vspace*{-0.1in} -\begin{lstlisting} -In []: legend(['sin(2y)'], loc=(.8,.1)) -# Specify south-east corner position -\end{lstlisting} -%\vspace*{-0.2in} -\begin{center} - \includegraphics[height=2in, interpolate=true]{data/loc} -\end{center} -%\inctime{10} -\end{frame} +%% \begin{frame}[fragile] +%% \frametitle{For arbitrary location} +%% \vspace*{-0.1in} +%% \begin{lstlisting} +%% In []: legend(['sin(2y)'], loc=(.8,.1)) +%% \end{lstlisting} +%% \emphbar{Specify south-east corner position} +%% %\vspace*{-0.2in} +%% \begin{center} +%% \includegraphics[height=2in, interpolate=true]{data/loc} +%% \end{center} +%% %\inctime{10} +%% \end{frame} \begin{frame}[fragile] \frametitle{Saving \& Closing} @@ -406,7 +403,7 @@ In []: close() In []: plot(y, sin(y), 'g') In []: clf() -In []: plot(y, sin(y), 'g', linewidth=2) +In []: plot(y, cos(y), 'r', linewidth=2) \end{lstlisting} \vspace*{-0.2in} \begin{center} @@ -429,13 +426,14 @@ In []: annotate('local max', xy=(1.5, 1)) \begin{frame}[fragile] \frametitle{Axes lengths} +\emphbar{Get the axes limits} \begin{lstlisting} -#Get the axes limits In []: xmin, xmax = xlim() In []: ymin, ymax = ylim() - + \end{lstlisting} +\emphbar{Set the axes limits} + \begin{lstlisting} In []: xmax = 2*pi -#Set the axes limits In []: xlim(xmin, xmax) In []: ylim(ymin-0.2, ymax+0.2) \end{lstlisting} @@ -447,7 +445,7 @@ In []: ylim(ymin-0.2, ymax+0.2) \item Plot x, -x, sin(x), xsin(x) in range $-5\pi$ to $5\pi$ \item Add a legend \item Annotate the origin -\item Set axis limits to the range of x +\item Set axes limits to the range of x \end{enumerate} \begin{lstlisting} In []: x=linspace(-5*pi, 5*pi, 500) @@ -481,23 +479,28 @@ Save commands of review problem into file \item Identify the required line numbers \item Then, use \typ{\%save} command of IPython \end{itemize} -\begin{lstlisting} - In []: %hist - In []: %save four_plot.py 16 18-27 -\end{lstlisting} +\typ{In []: \%hist}\\ +\typ{In []: \%save four_plot.py} \alert{\typ{16 18-27}} +\begin{block}{Careful about errors!} + \kwrd{\%hist} will contain the errors as well,\\ + so be careful while selecting line numbers. +\end{block} \end{frame} \begin{frame} \frametitle{Python Scripts\ldots} This is called a Python Script. \begin{itemize} - \item run the script in IPython using \typ{\%run -i sine_plot.py}\\ + \item run the script in IPython using \typ{\%run -i four_plot.py}\\ \end{itemize} \end{frame} -\begin{frame} +\begin{frame}[fragile] \frametitle{What did we learn?} \begin{itemize} + \item \kwrd{\%hist} + \item Saving commands to a script + \item Running a script using \kwrd{\%run -i} \item Creating simple plots. \item Adding labels and legends. \item Annotating plots. diff --git a/day1/session2.tex b/day1/session2.tex index 0c3caf8..884a653 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[] {14 December, 2009\\Day 1, Session 2} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -331,7 +331,7 @@ This gives \kwrd{tsq} which is the list of squares of \typ{t} values. \frametitle{What about larger data sets?} \alert{Data is usually present in a file!} \\ Lets look at the \typ{pendulum.txt} file. -\begin{lstlisting} +\begin{lstlisting} $ cat pendulum.txt 1.0000e-01 6.9004e-01 1.1000e-01 6.9497e-01 @@ -339,7 +339,7 @@ $ cat pendulum.txt 1.3000e-01 7.5360e-01 1.4000e-01 8.3568e-01 1.5000e-01 8.6789e-01 -\end{lstlisting} +\end{lstlisting} %$ \ldots \begin{block}{Windows users:} C:> type pendulum.txt @@ -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..79f7dc9 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[] {14 December, 2009\\Day 1, Session 3} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} diff --git a/day1/session4.tex b/day1/session4.tex index 79da193..33f1f68 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[] {14 December, 2009\\Day 1, Session 4} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\pgfdeclareimage[height=0.75cm]{iitmlogo}{iitmlogo} @@ -134,16 +134,15 @@ \begin{frame}[fragile] \frametitle{Matrices: Initializing} \begin{lstlisting} -In []: A = array([[ 1, 1, 2, -1], - [ 2, 5, -1, -9], - [ 2, 1, -1, 3], - [ 1, -3, 2, 7]]) -In []: A +In []: c = array([[1,1,2], + [2,4,1], + [-1,3,7]]) + +In []: c Out[]: -array([[ 1, 1, 2, -1], - [ 2, 5, -1, -9], - [ 2, 1, -1, 3], - [ 1, -3, 2, 7]]) +array([[1,1,2], + [2,4,1], + [-1,3,7]]) \end{lstlisting} \end{frame} @@ -157,8 +156,8 @@ array([[ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.], [ 1., 1., 1., 1., 1.]]) -In []: ones_like([1, 2, 3, 4, 5]) -Out[]: array([1, 1, 1, 1, 1]) +In []: ones_like([1, 2, 3, 4]) +Out[]: array([1, 1, 1, 1]) In []: identity(2) Out[]: @@ -173,17 +172,17 @@ Also available \alert{\typ{zeros, zeros_like, empty, empty_like}} \begin{frame}[fragile] \frametitle{Accessing elements} \begin{lstlisting} -In []: C = array([[1,1,2], - [2,4,1], - [-1,3,7]]) +In []: c +Out[]: +array([[1,1,2], + [2,4,1], + [-1,3,7]]) -In []: C[1][2] +In []: c[1][2] Out[]: 1 - -In []: C[1,2] +In []: c[1,2] Out[]: 1 - -In []: C[1] +In []: c[1] Out[]: array([2, 4, 1]) \end{lstlisting} \end{frame} @@ -192,15 +191,15 @@ Out[]: array([2, 4, 1]) \frametitle{Changing elements} \begin{small} \begin{lstlisting} -In []: C[1,1] = -2 -In []: C +In []: c[1,1] = -2 +In []: c Out[]: array([[ 1, 1, 2], [ 2, -2, 1], [-1, 3, 7]]) -In []: C[1] = [0,0,0] -In []: C +In []: c[1] = [0,0,0] +In []: c Out[]: array([[ 1, 1, 2], [ 0, 0, 0], @@ -214,18 +213,18 @@ How to change one \alert{column}? \frametitle{Slicing} \begin{small} \begin{lstlisting} -In []: C[:,1] +In []: c[:,1] Out[]: array([1, 0, 3]) -In []: C[1,:] +In []: c[1,:] Out[]: array([0, 0, 0]) -In []: C[0:2,:] +In []: c[0:2,:] Out[]: array([[1, 1, 2], [0, 0, 0]]) -In []: C[1:3,:] +In []: c[1:3,:] Out[]: array([[ 0, 0, 0], [-1, 3, 7]]) @@ -237,17 +236,17 @@ array([[ 0, 0, 0], \frametitle{Slicing \ldots} \begin{small} \begin{lstlisting} -In []: C[:2,:] +In []: c[:2,:] Out[]: array([[1, 1, 2], [0, 0, 0]]) -In []: C[1:,:] +In []: c[1:,:] Out[]: array([[ 0, 0, 0], [-1, 3, 7]]) -In []: C[1:,:2] +In []: c[1:,:2] Out[]: array([[ 0, 0], [-1, 3]]) @@ -260,18 +259,18 @@ array([[ 0, 0], \frametitle{Striding} \begin{small} \begin{lstlisting} -In []: C[::2,:] +In []: c[::2,:] Out[]: array([[ 1, 1, 2], [-1, 3, 7]]) -In []: C[:,::2] +In []: c[:,::2] Out[]: xarray([[ 1, 2], [ 0, 0], [-1, 7]]) -In []: C[::2,::2] +In []: c[::2,::2] Out[]: array([[ 1, 2], [-1, 7]]) @@ -283,13 +282,11 @@ array([[ 1, 2], \frametitle{Slicing \& Striding Exercises} \begin{small} \begin{lstlisting} -In []: A = imread('lena.png') +In []: a = imread('lena.png') -In []: imshow(A) +In []: imshow(a) Out[]: <matplotlib.image.AxesImage object at 0xa0384cc> -In []: A.shape -Out[]: (512, 512, 4) \end{lstlisting} \end{small} \begin{itemize} @@ -303,13 +300,13 @@ Out[]: (512, 512, 4) \frametitle{Solutions} \begin{small} \begin{lstlisting} -In []: imshow(A[:256,:256]) +In []: imshow(a[:256,:256]) Out[]: <matplotlib.image.AxesImage object at 0xb6f658c> -In []: imshow(A[200:400,200:400]) +In []: imshow(a[200:400,200:400]) Out[]: <matplotlib.image.AxesImage object at 0xb757c2c> -In []: imshow(A[::2,::2]) +In []: imshow(a[::2,::2]) Out[]: <matplotlib.image.AxesImage object at 0xb765c8c> \end{lstlisting} \end{small} @@ -318,7 +315,12 @@ Out[]: <matplotlib.image.AxesImage object at 0xb765c8c> \begin{frame}[fragile] \frametitle{Transpose of a Matrix} \begin{lstlisting} -In []: A.T +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], [ 1, 5, 1, -3], @@ -330,7 +332,7 @@ array([[ 1, 2, 2, 1], \begin{frame}[fragile] \frametitle{Sum of all elements} \begin{lstlisting} -In []: sum(A) +In []: sum(a) Out[]: 12 \end{lstlisting} \end{frame} @@ -338,11 +340,11 @@ Out[]: 12 \begin{frame}[fragile] \frametitle{Matrix Addition} \begin{lstlisting} -In []: B = array([[3,2,-1,5], +In []: b = array([[3,2,-1,5], [2,-2,4,9], [-1,0.5,-1,-7], [9,-5,7,3]]) -In []: A + B +In []: a + b Out[]: array([[ 4. , 3. , 1. , 4. ], [ 4. , 3. , 3. , 0. ], @@ -354,7 +356,7 @@ array([[ 4. , 3. , 1. , 4. ], \begin{frame}[fragile] \frametitle{Elementwise Multiplication} \begin{lstlisting} -In []: A*B +In []: a*b Out[]: array([[ 3. , 2. , -2. , -5. ], [ 4. , -10. , -4. , -81. ], @@ -367,7 +369,7 @@ array([[ 3. , 2. , -2. , -5. ], \begin{frame}[fragile] \frametitle{Matrix Multiplication} \begin{lstlisting} -In []: dot(A,B) +In []: dot(a, b) Out[]: array([[ -6. , 6. , -6. , -3. ], [-64. , 38.5, -44. , 35. ], @@ -379,7 +381,7 @@ array([[ -6. , 6. , -6. , -3. ], \begin{frame}[fragile] \frametitle{Inverse of a Matrix} \begin{lstlisting} -In []: inv(A) +In []: inv(a) \end{lstlisting} \begin{small} \begin{lstlisting} @@ -395,7 +397,7 @@ array([[-0.5 , 0.55, -0.15, 0.7 ], \begin{frame}[fragile] \frametitle{Determinant} \begin{lstlisting} -In []: det(A) +In []: det(a) Out[]: 80.0 \end{lstlisting} \end{frame} @@ -405,16 +407,16 @@ Out[]: 80.0 \frametitle{Eigenvalues and Eigen Vectors} \begin{small} \begin{lstlisting} -In []: E = array([[3,2,4],[2,0,2],[4,2,3]]) +In []: e = array([[3,2,4],[2,0,2],[4,2,3]]) -In []: eig(E) +In []: eig(e) Out[]: (array([-1., 8., -1.]), array([[-0.74535599, 0.66666667, -0.1931126 ], [ 0.2981424 , 0.33333333, -0.78664085], [ 0.59628479, 0.66666667, 0.58643303]])) -In []: eigvals(E) +In []: eigvals(e) Out[]: array([-1., 8., -1.]) \end{lstlisting} \end{small} @@ -423,7 +425,7 @@ Out[]: array([-1., 8., -1.]) %% \begin{frame}[fragile] %% \frametitle{Computing Norms} %% \begin{lstlisting} -%% In []: norm(E) +%% In []: norm(e) %% Out[]: 8.1240384046359608 %% \end{lstlisting} %% \end{frame} @@ -432,7 +434,7 @@ Out[]: array([-1., 8., -1.]) %% \frametitle{Singular Value Decomposition} %% \begin{small} %% \begin{lstlisting} -%% In []: svd(E) +%% In []: svd(e) %% Out[]: %% (array( %% [[ -6.66666667e-01, -1.23702565e-16, 7.45355992e-01], @@ -503,9 +505,33 @@ Out[]: array([-1., 8., -1.]) \end{frame} \begin{frame}[fragile] +\frametitle{Getting $L$ and $T^2$} +If you \alert{closed} IPython after session 2 +\begin{lstlisting} +In []: l = [] +In []: t = [] +In []: for line in open('pendulum.txt'): + .... point = line.split() + .... l.append(float(point[0])) + .... t.append(float(point[1])) + .... + .... +\end{lstlisting} +\end{frame} + +\begin{frame}[fragile] +\frametitle{Getting $L$ and $T^2$ \dots} +\begin{lstlisting} +In []: l = array(l) +In []: t = array(t) +\end{lstlisting} +\alert{\typ{In []: tsq = t*t}} +\end{frame} + +\begin{frame}[fragile] \frametitle{Generating $A$} \begin{lstlisting} -In []: A = array([L, ones_like(L)]) +In []: A = array([l, ones_like(l)]) In []: A = A.T \end{lstlisting} %% \begin{itemize} @@ -524,7 +550,7 @@ In []: A = A.T \item Along with a lot of things, it returns the least squares solution \end{itemize} \begin{lstlisting} -In []: result = lstsq(A,TSq) +In []: result = lstsq(A,tsq) In []: coef = result[0] \end{lstlisting} \end{frame} @@ -533,13 +559,13 @@ In []: coef = result[0] \frametitle{Least Square Fit Line \ldots} We get the points of the line from \typ{coef} \begin{lstlisting} -In []: Tline = coef[0]*L + coef[1] +In []: Tline = coef[0]*l + coef[1] \end{lstlisting} \begin{itemize} -\item Now plot Tline vs. L, to get the Least squares fit line. +\item Now plot \typ{Tline} vs. \typ{l}, to get the Least squares fit line. \end{itemize} \begin{lstlisting} -In []: plot(L, Tline) +In []: plot(l, Tline) \end{lstlisting} \end{frame} diff --git a/day1/session6.tex b/day1/session6.tex index acfc687..906fb54 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[] {14 December, 2009\\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], @@ -318,6 +318,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) @@ -328,7 +329,7 @@ In []: def epid(y, t): \begin{frame}[fragile] \frametitle{Solving ODEs using SciPy \ldots} \begin{lstlisting} -In []: t = arange(0, 12, 0.2) +In []: t = linspace(0, 12, 61) In []: y = odeint(epid, 250, t) @@ -338,6 +339,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 +401,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} |