# HG changeset patch # User Puneeth Chaganti # Date 1289299106 -19800 # Node ID f29d9014e1fcc477f83ed534a9b86139bf6d1972 # Parent c4c5d1123f07131410c4c0b2c7f597fc93ae0922# Parent 27d2561e617a7779cad865c7f69eb50111243113 Merged heads. diff -r c4c5d1123f07 -r f29d9014e1fc #symbolics.rst# --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/#symbolics.rst# Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,343 @@ +Symbolics with Sage +------------------- + +Hello friends and welcome to this tutorial on symbolics with sage. + + +.. #[Madhu: Sounds more or less like an ad!] + +{{{ Part of Notebook with title }}} + +.. #[Madhu: Please make your instructions, instructional. While + recording if I have to read this, think what you are actually + meaning it will take a lot of time] + +We would be using simple mathematical functions on the sage notebook +for this tutorial. + +.. #[Madhu: What is this line doing here. I don't see much use of it] + +During the course of the tutorial we will learn + +{{{ Part of Notebook with outline }}} + +To define symbolic expressions in sage. Use built-in costants and +function. Integration, differentiation using sage. Defining +matrices. Defining Symbolic functions. Simplifying and solving +symbolic expressions and functions. + +.. #[Nishanth]: The formatting is all messed up + First fix the formatting and compile the rst + The I shall review +.. #[Madhu: Please make the above items full english sentences, not + the slides like points. The person recording should be able to + read your script as is. It can read something like "we will learn + how to define symbolic expressions in Sage, using built-in ..."] + +Using sage we can perform mathematical operations on symbols. + +.. #[Madhu: Same mistake with period symbols! Please get the + punctuation right. Also you may have to rephrase the above + sentence as "We can use Sage to perform sybmolic mathematical + operations" or such] + +On the sage notebook type:: + + sin(y) + +It raises a name error saying that y is not defined. But in sage we +can declare y as a symbol using var function. + +.. #[Madhu: But is not required] +:: + var('y') + +Now if you type:: + + sin(y) + + sage simply returns the expression . + +.. #[Madhu: Why is this line indented? Also full stop. When will you + learn? Yes we can correct you. But corrections are for you to + learn. If you don't learn from your mistakes, I don't know what + to say] + +thus now sage treats sin(y) as a symbolic expression . You can use +this to do a lot of symbolic maths using sage's built-in constants and +expressions . + +.. #[Madhu: "Thus now"? It sounds like Dus and Nou, i.e 10 and 9 in + Hindi! Full stop again. "a lot" doesn't mean anything until you + quantify it or give examples.] + +Try out + +.. #[Madhu: "So let us try" sounds better] + :: + + var('x,alpha,y,beta') x^2/alpha^2+y^2/beta^2 + +Similarly , we can define many algebraic and trigonometric expressions +using sage . + +.. #[Madhu: comma again. Show some more examples?] + + +Sage also provides a few built-in constants which are commonly used in +mathematics . + +example : pi,e,oo , Function n gives the numerical values of all these + constants. + +.. #[Madhu: This doesn't sound like scripts. How will I read this + while recording. Also if I were recording I would have read your + third constant as Oh-Oh i.e. double O. It took me at least 30 + seconds to figure out it is infinity] + +For instance:: + + n(e) + + 2.71828182845905 + +gives numerical value of e. + +If you look into the documentation of n by doing + +.. #[Madhu: "documentation of the function "n"?] + +:: + n( + +You will see what all arguments it can take etc .. It will be very +helpful if you look at the documentation of all functions introduced + +.. #[Madhu: What does etc .. mean in a script?] + +Also we can define the no of digits we wish to use in the numerical +value . For this we have to pass an argument digits. Type + +.. #[Madhu: "no of digits"? Also "We wish to obtain" than "we wish to + use"?] +:: + + n(pi, digits = 10) + +Apart from the constants sage also has a lot of builtin functions like +sin,cos,sinh,cosh,log,factorial,gamma,exp,arcsin,arccos,arctan etc ... +lets try some out on the sage notebook. + +.. #[Madhu: Here "a lot" makes sense] +:: + + sin(pi/2) + + arctan(oo) + + log(e,e) + + +Given that we have defined variables like x,y etc .. , We can define +an arbitrary function with desired name in the following way.:: + + var('x') function( {{{ Just to show the documentation + extend this line }}} function('f',x) + +.. #[Madhu: What will the person recording show in the documentation + without a script for it? Please don't assume recorder can cook up + things while recording. It is impractical] + +Here f is the name of the function and x is the independent variable . +Now we can define f(x) to be :: + + f(x) = x/2 + sin(x) + +Evaluating this function f for the value x=pi returns pi/2.:: + + f(pi) + +We can also define functions that are not continuous but defined +piecewise. We will be using a function which is a parabola between 0 +to 1 and a constant from 1 to 2 . type the following as given on the +screen + +.. #[Madhu: Instead of "We will be using ..." how about "Let us define + a function ..."] +:: + + + var('x') h(x)=x^2 g(x)=1 f=Piecewise( {{{ Just to show the + documentation extend this line }}} + f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f + +Checking f at 0.4, 1.4 and 3 :: f(0.4) f(1.4) f(3) + +.. #[Madhu: Again this doesn't sound like a script] + +for f(3) it raises a value not defined in domain error . + + +Apart from operations on expressions and functions one can also use +them for series . + +.. #[Madhu: I am not able to understand this line. "Use them as +.. series". Use what as series?] + +We first define a function f(n) in the way discussed above.:: + + var('n') function('f', n) + +.. #[Madhu: Shouldn't this be on 2 separate lines?] + +To sum the function for a range of discrete values of n, we use the +sage function sum. + +For a convergent series , f(n)=1/n^2 we can say :: + + var('n') function('f', n) + + f(n) = 1/n^2 + + sum(f(n), n, 1, oo) + +For the famous Madhava series :: var('n') function('f', n) + +.. #[Madhu: What is this? your double colon says it must be code block + but where is the indentation and other things. How will the + recorder know about it?] + + f(n) = (-1)^(n-1)*1/(2*n - 1) + +This series converges to pi/4. It was used by ancient Indians to +interpret pi. + +.. #[Madhu: I am losing the context. Please add something to bring + this thing to the context] + +For a divergent series, sum would raise a an error 'Sum is +divergent' :: + + var('n') + function('f', n) + f(n) = 1/n sum(f(n), n,1, oo) + + + + +We can perform simple calculus operation using sage + +.. #[Madhu: When you switch to irrelevant topics make sure you use + some connectors in English like "Moving on let us see how to + perform simple calculus operations using Sage" or something like + that] +For example lets try an expression first :: + + diff(x**2+sin(x),x) 2x+cos(x) + +The diff function differentiates an expression or a function . Its +first argument is expression or function and second argument is the +independent variable . + +.. #[Madhu: Full stop, Full stop, Full stop] + +We have already tried an expression now lets try a function :: + + f=exp(x^2)+arcsin(x) diff(f(x),x) + +To get a higher order differentiation we need to add an extra argument +for order :: + + diff( diff(f(x),x,3) + +.. #[Madhu: Please try to be more explicit saying third argument] + +in this case it is 3. + + +Just like differentiation of expression you can also integrate them :: + + x = var('x') s = integral(1/(1 + (tan(x))**2),x) s + +.. #[Madhu: Two separate lines.] + +To find the factors of an expression use the "factor" function + +.. #[Madhu: See the diff] + +:: + factor( y = (x^100 - x^70)*(cos(x)^2 + cos(x)^2*tan(x)^2) f = + factor(y) + +One can also simplify complicated expression using sage :: + f.simplify_full() + +This simplifies the expression fully . You can also do simplification +of just the algebraic part and the trigonometric part :: + + f.simplify_exp() f.simplify_trig() + +.. #[Madhu: Separate lines?] + +One can also find roots of an equation by using find_root function:: + + phi = var('phi') find_root(cos(phi)==sin(phi),0,pi/2) + +.. #[Madhu: Separate lines?] + +Lets substitute this solution into the equation and see we were +correct :: + + var('phi') f(phi)=cos(phi)-sin(phi) + root=find_root(f(phi)==0,0,pi/2) f.substitute(phi=root) + +.. #[Madhu: Separate lines?] + +as we can see the solution is almost equal to zero . + +.. #[Madhu: So what?] + +We can also define symbolic matrices :: + + + + var('a,b,c,d') A=matrix([[a,1,0],[0,b,0],[0,c,d]]) A + +.. #[Madhu: Why don't you break the lines?] + +Now lets do some of the matrix operations on this matrix + +.. #[Madhu: Why don't you break the lines? Also how do you connect + this up? Use some transformation keywords in English] +:: + A.det() A.inverse() + +.. #[Madhu: Why don't you break the lines?] + +You can do :: + + A. + +To see what all operations are available + +.. #[Madhu: Sounds very abrupt] + +{{{ Part of the notebook with summary }}} + +So in this tutorial we learnt how to + + +We learnt about defining symbolic expression and functions . +And some built-in constants and functions . +Getting value of built-in constants using n function. +Using Tab to see the documentation. +Also we learnt how to sum a series using sum function. +diff() and integrate() for calculus operations . +Finding roots , factors and simplifying expression using find_root(), +factor() , simplify_full, simplify_exp , simplify_trig . +Substituting values in expression using substitute function. +And finally creating symbolic matrices and performing operation on them . + +.. #[Madhu: See what Nishanth is doing. He has written this as + points. So easy to read out while recording. You may want to + reorganize like that] diff -r c4c5d1123f07 -r f29d9014e1fc accessing-pieces-arrays/slides.org.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accessing-pieces-arrays/slides.org.orig Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,123 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: Accessing parts of arrays +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* Outline + - Manipulating one and multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slicing and striding on arrays to access chunks + - Read images into arrays and manipulations +* Sample Arrays + #+begin_src python + In []: A = array([12, 23, 34, 45, 56]) + + In []: C = array([[11, 12, 13, 14, 15], + [21, 22, 23, 24, 25], + [31, 32, 33, 34, 35], + [41, 42, 43, 44, 45], + [51, 52, 53, 54, 55]]) + + #+end_src +* Question 1 + Change the last column of ~C~ to zeroes. +* Solution 1 + #+begin_src python + In []: C[:, -1] = 0 + #+end_src +* Question 2 + Change ~A~ to ~[11, 12, 13, 14, 15]~. +* Solution 2 + #+begin_src python + In []: A[:] = [11, 12, 13, 14, 15] + #+end_src +* squares.png + #+begin_latex + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} + #+end_latex +* Question 3 + - obtain ~[22, 23]~ from ~C~. + - obtain ~[11, 21, 31, 41]~ from ~C~. + - obtain ~[21, 31, 41, 0]~. +* Solution 3 + #+begin_src python + In []: C[1, 1:3] + In []: C[0:4, 0] + In []: C[1:5, 0] + #+end_src +* Question 4 + Obtain ~[[23, 24], [33, -34]]~ from ~C~ +* Solution 4 + #+begin_src python + In []: C[1:3, 2:4] + #+end_src +* Question 5 + Obtain the square in the center of the image +* Solution 5 + #+begin_src python + In []: imshow(I[75:225, 75:225]) + #+end_src +* Question 6 + Obtain the following + #+begin_src python + [[12, 0], [42, 0]] + [[12, 13, 14], [0, 0, 0]] + #+end_src + +* Solution 6 + #+begin_src python + In []: C[::3, 1::3] + In []: C[::4, 1:4] + #+end_src +* Summary + You should now be able to -- + - Manipulate single \& multi dimensional arrays + - Access and change individual elements + - Access and change rows and columns + - Slice and stride on arrays + - Read images into arrays and manipulate them. +* Thank you! +#+begin_latex + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +#+end_latex + + diff -r c4c5d1123f07 -r f29d9014e1fc accessing-pieces-arrays/slides.tex.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/accessing-pieces-arrays/slides.tex.orig Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,199 @@ +% Created 2010-11-03 Wed 15:37 +\documentclass[presentation]{beamer} +\usetheme{Antibes}\usecolortheme{lily}\useoutertheme{infolines}\setbeamercovered{transparent} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\usepackage{amssymb} +\usepackage{hyperref} +\usepackage[english]{babel} \usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} +\usepackage{listings} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +\title{Accessing parts of arrays} +\author{FOSSEE} +\date{} + +\begin{document} + +\maketitle + + + + + + + + + +\begin{frame} +\frametitle{Outline} +\label{sec-1} + +\begin{itemize} +\item Manipulating one and multi dimensional arrays +\item Access and change individual elements +\item Access and change rows and columns +\item Slicing and striding on arrays to access chunks +\item Read images into arrays and manipulations +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Sample Arrays} +\label{sec-2} + +\begin{verbatim} +In []: A = array([12, 23, 34, 45, 56]) + +In []: C = array([[11, 12, 13, 14, 15], + [21, 22, 23, 24, 25], + [31, 32, 33, 34, 35], + [41, 42, 43, 44, 45], + [51, 52, 53, 54, 55]]) +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-3} + + Change the last column of \texttt{C} to zeroes. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-4} + +\begin{verbatim} +In []: C[:, -1] = 0 +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-5} + + Change \texttt{A} to \texttt{[11, 12, 13, 14, 15]}. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-6} + +\begin{verbatim} +In []: A[:] = [11, 12, 13, 14, 15] +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{squares.png} +\label{sec-7} + + \begin{center} + \includegraphics[scale=0.6]{squares} + \end{center} +\end{frame} +\begin{frame} +\frametitle{Question 3} +\label{sec-8} + +\begin{itemize} +\item obtain \texttt{[22, 23]} from \texttt{C}. +\item obtain \texttt{[11, 21, 31, 41]} from \texttt{C}. +\item obtain \texttt{[21, 31, 41, 0]}. +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 3} +\label{sec-9} + +\begin{verbatim} +In []: C[1, 1:3] +In []: C[0:4, 0] +In []: C[1:5, 0] +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-10} + + Obtain \texttt{[[23, 24], [33, -34]]} from \texttt{C} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 4} +\label{sec-11} + +\begin{verbatim} +In []: C[1:3, 2:4] +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Question 5} +\label{sec-12} + + Obtain the square in the center of the image +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 5} +\label{sec-13} + +\begin{verbatim} +In []: imshow(I[75:225, 75:225]) +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Question 6} +\label{sec-14} + + Obtain the following +\begin{verbatim} +[[12, 0], [42, 0]] +[[12, 13, 14], [0, 0, 0]] +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 6} +\label{sec-15} + +\begin{verbatim} +In []: C[::3, 1::3] +In []: C[::4, 1:4] +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-16} + + You should now be able to -- +\begin{itemize} +\item Manipulate single \& multi dimensional arrays + +\begin{itemize} +\item Access and change individual elements +\item Access and change rows and columns +\item Slice and stride on arrays +\end{itemize} + +\item Read images into arrays and manipulate them. +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-17} + + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +\end{frame} + +\end{document} diff -r c4c5d1123f07 -r f29d9014e1fc additional_ipython/questions.rst --- a/additional_ipython/questions.rst Tue Nov 09 16:07:33 2010 +0530 +++ b/additional_ipython/questions.rst Tue Nov 09 16:08:26 2010 +0530 @@ -20,6 +20,8 @@ Answer: 21 +.. #[Amit: I really don't get the question below] + 3. is ``%hist`` considered as a command a. True @@ -45,8 +47,10 @@ Answer: raises an error - 6. How many commands are displayed when lot of coomands were typed and + 6. How many commands are displayed when lot of commands were typed and ``%hist`` is used. +.. #[Amit: Ok something wrong with the question. +.. Recommend : What is the default maximum number of commands %hist can show ] a. 20 #. 10 @@ -82,7 +86,9 @@ #. 2 5 7 1 #. 1 2 5 7 - 10. What happens when ``%save filepath line_numbers`` is used and a file + Answer: a + +10. What happens when ``%save filepath line_numbers`` is used and a file already exists in that path. a. It is overwritten @@ -116,3 +122,13 @@ #. Does nothing Answer: increments the value of x by 1 + + +Long Answer questions : +----------------------- + +1. Question 1 +2. Question 2 + +.. #[Amit: I think long answer questions for this script are +.. not possible. Please add if someone comes up with any] diff -r c4c5d1123f07 -r f29d9014e1fc additional_ipython/script.rst --- a/additional_ipython/script.rst Tue Nov 09 16:07:33 2010 +0530 +++ b/additional_ipython/script.rst Tue Nov 09 16:08:26 2010 +0530 @@ -39,7 +39,7 @@ on the terminal -{{{ shit to terminal and type ipython -pylab }}} +{{{ shift to terminal and type ipython -pylab }}} We shall first make a plot and then view the history and save it. :: @@ -66,14 +66,14 @@ command has a number in front, to specify in which order and when it was typed. Please note that there is a % sign before the hist command. This implies that -%hist is a command that is specific to IPython and not available in vannila +%hist is a command that is specific to IPython and not available in the vannila Python interpreter. These type of commands are called as magic commands. Also note that, the =%hist= itself is a command and is displayed as the most -recent command. This implies that anything we type in is stored as history, +recent command. We should not that anything we type in is stored as history, irrespective of whether it is command or an error or IPython magic command. -If we want only the recent 5 to be displayed, we pass the number as an argument +If we want only the recent 5 commands to be displayed, we pass the number as an argument to =%hist= command. Hence :: @@ -99,8 +99,7 @@ Now that we have the history, we would like to save the required line of code from history. This is possible by using the =%save= command. -Before we do that, let us first look at history and identify what lines of code -we require.Type +Before we do that, let us first look at history and identify what lines of code we require.Type :: %hist @@ -109,7 +108,7 @@ {{{ point to the lines }}} The first command is linspace. But second command is a command that gave us an -error. Hence we do not need seconf. The commands from third to sixth are +error. Hence we do not need second command. The commands from third to sixth are required. The seventh command although is correct, we do not need it since we are setting the title correctly in the eigthth command. @@ -154,7 +153,7 @@ %run -i /home/fossee/plot_script.py -The script runs but we do not see the plot. This happens because we are running +The script runs but we do not see the plot. This happens because when we are running a script and we are not in interactive mode anymore. Hence on your terminal type @@ -169,6 +168,7 @@ %% 3 %% Use %hist and %save and create a script that has show in it and run it to produce and show the plot. + {{{ continue from paused state }}} We first look at the history using @@ -181,6 +181,7 @@ %save /home/fossee/show_included.py 1 3-6 8 10 13 %run -i /home/fossee/show_included.py + show() We get the desired plot. @@ -195,7 +196,7 @@ {{{ continue from paused state }}} -We see that it raises nameerror saying the name linspace is not found. +We see that it raises NameError saying that the name linspace is not found. {{{ Show summary slide }}} @@ -209,9 +210,9 @@ {{{ Show the "sponsored by FOSSEE" slide }}} -#[Nishanth]: Will add this line after all of us fix on one. + This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thank you! +Thank You! diff -r c4c5d1123f07 -r f29d9014e1fc basic-data-type/slides.org diff -r c4c5d1123f07 -r f29d9014e1fc basic-data-type/slides.org.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/basic-data-type/slides.org.orig Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,158 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: Plotting Data +#+AUTHOR: FOSSEE +#+DATE: 2010-09-14 Tue +#+EMAIL: info@fossee.in + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:1 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc +#+STARTUP: align fold nodlcheck hidestars oddeven lognotestate + +* Outline +** Datatypes in Python +*** Numbers +*** Boolean +*** Sequence +** Operators in Python +*** Arithmetic Operators +*** Boolean Operators +** Python Sequence Datatypes +*** list +*** string +*** tuple + +* Numbers + - int + - float + - complex +* Question 1 + - Find the absolute value of 3+4j +* Solution 1 + #+begin_src python + abs(3+4j) + #+end_src python +* Question 2 + - What is the datatype of number 999999999999999999? Is it +not int? + +* Solution 2 + - Long + - Large integers numbers are internally stored in python as Long + datatype. + + +* Boolean + #+begin_src python + In []: t=True + In []: f=False + #+end_src + +* Question 3 + - Using python find sqaure root of 3? + +* Solution 3 + + - 3**0.5 + +* Question 4 + - Is 3**1/2 and 3**0.5 same +* Solution 4 + - No,One gives an int answer and the other float + +* Sequence Data types +** Properties + - Data in Sequence + - Accessed using Index +** Type + - list + - String + - Tuple + +* All are Strings + #+begin_src python + k = 'Single quote' + l = "Double quote contain's single quote" + m = '''"Contain's both"''' + + #+end_src +* Immutabilty Error + #+begin_src python + In []: greeting_string[1]='k' + ------------------------------------------------------- + TypeError Traceback (most recent call last) + + /home/fossee/ in () + + TypeError: 'str' object does not support item assignment + #+end_src + +* Question 5 + Check if 3 is an element of the list [1,7,5,3,4]. In case it is +change it to 21. + +* Solution 5 + #+begin_src python + l=[1,7,5,3,4] + 3 in l + l[3]=21 + l + #+end_src +* Question 6 + Convert the string ~"Elizabeth is queen of england"~ to ~"Elizabeth is +queen"~ + +* Solution 6 + #+begin_src python + s = "Elizabeth is queen of england" + stemp = s.split() + ' '.join(stemp[:3]) + #+end_src +* Summary + - Number Datatypes -- integer,float and complex + - Boolean and datatype and operators + - Sequence data types -- List, String and Tuple + - Accesing sequence + - Slicing sequences + - Finding length, sorting and reversing operations on sequences + - Immutability +* Thank you! +#+begin_latex + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +#+end_latex + + + + + diff -r c4c5d1123f07 -r f29d9014e1fc basic-data-type/slides.tex --- a/basic-data-type/slides.tex Tue Nov 09 16:07:33 2010 +0530 +++ b/basic-data-type/slides.tex Tue Nov 09 16:08:26 2010 +0530 @@ -1,4 +1,4 @@ -% Created 2010-11-09 Tue 14:56 +% Created 2010-11-09 Tue 15:26 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,6 +8,7 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} +\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -102,10 +103,9 @@ \frametitle{Solution 1} \label{sec-4} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} abs(3+4j) -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 2} @@ -121,7 +121,6 @@ \frametitle{Solution 2} \label{sec-6} - \begin{itemize} \item Long \item Large integers numbers are internally stored in python as Long @@ -132,11 +131,10 @@ \frametitle{Boolean} \label{sec-7} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: t=True In []: f=False -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 3} @@ -199,19 +197,17 @@ \frametitle{All are Strings} \label{sec-13} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} k = 'Single quote' l = "Double quote contain's single quote" m = '''"Contain's both"''' -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame}[fragile] \frametitle{Immutabilty Error} \label{sec-14} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} In []: greeting_string[1]='k' ------------------------------------------------------- TypeError Traceback (most recent call last) @@ -219,7 +215,7 @@ /home/fossee/ in () TypeError: 'str' object does not support item assignment -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 5} @@ -232,13 +228,12 @@ \frametitle{Solution 5} \label{sec-16} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} l=[1,7,5,3,4] 3 in l l[3]=21 l -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Question 6} @@ -251,12 +246,11 @@ \frametitle{Solution 6} \label{sec-18} -\lstset{language=Python} -\begin{lstlisting} +\begin{verbatim} s = "Elizabeth is queen of england" stemp = s.split() ' '.join(stemp[:3]) -\end{lstlisting} +\end{verbatim} \end{frame} \begin{frame} \frametitle{Summary} diff -r c4c5d1123f07 -r f29d9014e1fc getting-started-with-lists/questions.rst.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-with-lists/questions.rst.orig Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,56 @@ +Objective Questions +------------------- + +.. A mininum of 8 questions here (along with answers) + +1. How do you create an empty list? :: + + empty=[] + +2. What is the most important property of sequence data types like lists? + + The elements are in order and can be accessed by index numbers. + +3. Can you have a list inside a list ? + + Yes,List can contain all the other data types, including list. + + Example: + list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there'] + +4. What is the index number of the first element in a list? + + 0 + nonempty = ['spam', 'eggs', 100, 1.234] + nonempty[0] + +5. How would you access the end of a list without finding its length? + + Using negative indices. We can the list from the end using negative indices. + + :: + nonempty = ['spam', 'eggs', 100, 1.234] + nonempty[-1] + +6. What is the function to find the length of a list? + + len + +7. Delete the last element from list sq=[5,4,3,2,1,0] + + del(sq[-1]) + +8. How many will you have to use remove function to remove all 6's from the given list sq=[2,5,6,7,6,4,6]? + + 3 + +Larger Questions +---------------- + +.. A minimum of 2 questions here (along with answers) + +1. Add all elemets of seq1=['e','f','g','h'] +to the sequence seq=['a','b','c','d'] + +2. Delete all elements of seq1=[3,5,6] from sequence + seq=[1,2,3,4,5,6,7,8,9] diff -r c4c5d1123f07 -r f29d9014e1fc getting-started-with-lists/script.rst --- a/getting-started-with-lists/script.rst Tue Nov 09 16:07:33 2010 +0530 +++ b/getting-started-with-lists/script.rst Tue Nov 09 16:08:26 2010 +0530 @@ -19,8 +19,8 @@ .. #. getting started with lists .. #. basic datatypes -.. Author : Puneeth - Internal Reviewer : Amit +.. Author : Amit + Internal Reviewer : External Reviewer : Checklist OK? : [2010-10-05] diff -r c4c5d1123f07 -r f29d9014e1fc getting-started-with-lists/script.rst.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-with-lists/script.rst.orig Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,361 @@ + + + + + + + + + + +
+ + +
+

Objective Questions

+ +
    +
  1. How do you create an empty list?

    +
    +empty=[]
    +
    +
  2. +
  3. What is the most important property of sequence data types like lists?

    +

    The elements are in order and can be accessed by index numbers.

    +
  4. +
  5. Can you have a list inside a list ?

    +

    Yes,List can contain all the other data types, including list.

    +

    Example: +list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']

    +
  6. +
  7. What is the index number of the first element in a list?

    +

    0 +nonempty = ['spam', 'eggs', 100, 1.234] +nonempty[0]

    +
  8. +
  9. How would you access the end of a list without finding its length?

    +

    Using negative indices. We can the list from the end using negative indices.

    +

    :: +nonempty = ['spam', 'eggs', 100, 1.234] +nonempty[-1]

    +
  10. +
  11. What is the function to find the length of a list?

    +

    len

    +
  12. +
  13. Delete the last element from list sq=[5,4,3,2,1,0]

    +

    del(sq[-1])

    +
  14. +
  15. How many will you have to use remove function to remove all 6's from the given list sq=[2,5,6,7,6,4,6]?

    +

    3

    +
  16. +
+
+
+

Larger Questions

+ +

1. Add all elemets of seq1=['e','f','g','h'] +to the sequence seq=['a','b','c','d']

+
    +
  1. Delete all elements of seq1=[3,5,6] from sequence +seq=[1,2,3,4,5,6,7,8,9]
  2. +
+
+
+ + diff -r c4c5d1123f07 -r f29d9014e1fc input_output/script.rst --- a/input_output/script.rst Tue Nov 09 16:07:33 2010 +0530 +++ b/input_output/script.rst Tue Nov 09 16:08:26 2010 +0530 @@ -19,7 +19,7 @@ Script ------ -Hello friends and welcome to the tutorial on Input/Output +Hello friends and welcome to this tutorial on Input/Output {{{ Show the slide containing title }}} @@ -38,10 +38,14 @@ a print a + ``print a``, obviously, is printing the value of ``a``. + As you can see, even when you type just a, the value of a is shown. But there is a difference. +.. #[Amit: The next sentence does seem to be clear enough] + Typing a shows the value of a while print a prints the string. This difference becomes more evident when we use strings with newlines in them. type @@ -61,8 +65,13 @@ We shall look at different ways of outputting the data. -``print`` statement also accepts the syntax of C's ``printf`` statement. -Various arguments can be passed to ``print`` using modifiers. + +.. #[Amit: C's printf syntax ?? i think its better to elaborate the + idea] + +print statement in python supports string formatting. +Various arguments can be passed to print using modifiers. + type :: @@ -171,24 +180,27 @@ {{{ Pause here and try out the following exercises }}} -%% 4 %% How do you display a prompt and let the user enter input in a new line +%% 4 %% How do you display a prompt and let the user enter input in next line {{{ continue from paused state }}} .. #[Puneeth: We didn't talk of new-line character till now, did we?] .. #[Puneeth: non-programmers might not know?] +.. #[Amit: Well there is a discussion earlier about new lines, I think its good +.. as a slight trick question. But may be next line is a more easier lexicon] + The trick is to include a newline character at the end of the prompt string. :: ip = raw_input("Please enter a number in the next line\n> ") -prints the newline character and hence the user enters input in the new line +prints the newline character and hence the user enters input in the next line {{{ Show summary slide }}} This brings us to the end of the tutorial. -we have learnt +In this totorial we have learnt * How to print some value * How to print using modifiers @@ -197,9 +209,9 @@ {{{ Show the "sponsored by FOSSEE" slide }}} -#[Nishanth]: Will add this line after all of us fix on one. + This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thankyou +Thank You. diff -r c4c5d1123f07 -r f29d9014e1fc input_output/script.rst.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/input_output/script.rst.orig Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,222 @@ +.. Objectives +.. ---------- + +.. #. How to print some value +.. #. How to print using modifiers +.. #. How to take input from user +.. #. How to display a prompt to the user before taking the input + +.. Prerequisites +.. ------------- + +.. 1. Loops + +.. Author : Nishanth Amuluru + Internal Reviewer : Puneeth + External Reviewer : + Checklist OK? : [2010-10-05] + +Script +------ + +Hello friends and welcome to this tutorial on Input/Output + +{{{ Show the slide containing title }}} + +{{{ Show the slide containing the outline slide }}} + +Input and Output are used in almost every program we use. +In this tutorial, we shall learn how to + + * Output data + * Take input from the user + +type +:: + + a = "This is a string" + a + print a + +<<<<<<< local +print a, prints the value of a. +======= +``print a``, obviously, is printing the value of ``a``. +>>>>>>> other +As you can see, even when you type just a, the value of a is shown. +But there is a difference. + +.. #[Amit: The next sentence does seem to be clear enough] + +Typing a shows the value of a while print a prints the string. This difference +becomes more evident when we use strings with newlines in them. +type +:: + + b = "A line \n New line" + b + print b + +As you can see, just typing b shows that b contains a newline character. +While typing print b prints the string and hence the newline. + +Moreover when we type just a, the value a is shown only in interactive mode and +does not have any effect on the program while running it as a script. + +.. #[punch: I think we could show that?] + +We shall look at different ways of outputting the data. + +<<<<<<< local +.. #[Amit: C's printf syntax ?? i think its better to elaborate the + idea] + +print statement in python supports string formatting. +Various arguments can be passed to print using modifiers. +======= +``print`` statement also accepts the syntax of C's ``printf`` statement. +Various arguments can be passed to ``print`` using modifiers. +>>>>>>> other +type +:: + + x = 1.5 + y = 2 + z = "zed" + print "x is %2.1f y is %d z is %s"%(x,y) + +As you can see, the values of x and y are substituted in place of +``%2.1f`` and ``%d`` + +{{{ Pause here and try out the following exercises }}} + +%% 1 %% What happens when you do ``print "x is %d y is %f" %(x, y)`` + +{{{ continue from paused state }}} + +We see that the ``int`` value of x and ``float`` value of y are +printed corresponding to the modifiers used in the print statement. + +We can also see that ``print`` statement prints a new line character +at the end of the line, everytime it is called. This can be suppressed +by using a "," at the end ``print`` statement. + +Let us see this by typing out following code on an editor as print_example.py + +{{{ open an editor }}} +type +:: + + print "Hello" + print "World" + + print "Hello", + print "World" + +Now we run the script using %run /home/fossee/print_example.py + +As we can see, the print statement when used with comma in the end, prints a +space instead of a new line. + +Now we shall look at taking input from the user. +We will use the ~~raw_input~~ for this. +type +:: + + ip = raw_input() + +The cursor is blinking indicating that it is waiting for input +type +:: + + an input + +and hit enter. +Now let us see what is the value of ip by typing. +:: + + ip + +We can see that it contains the string "an input" + +{{{ Pause here and try out the following exercises }}} + +%% 2 %% enter the number 5.6 as input and store it in a variable called c. + +{{{ continue from paused state }}} + +We have to use the raw_input command with variable c. +type +:: + + c = raw_input() + 5.6 + c + +Now let us see the type of c. + +:: + + type(c) + +We see that c is a string. This implies that anything you enter as input, will +be taken as a string no matter what you enter. + +{{{ Pause here and try out the following exercises }}} + +%% 3 %% What happens when you do not enter anything and hit enter + +{{{ continue from paused state }}} + +:: + + d = raw_input() + + d + +We see that when nothing is entered, an empty string is considered as input. + +raw_input also can display a prompt to assist the user. +:: + + name = raw_input("Please enter your name: ") + +prints the string given as argument and then waits for the user input. + +{{{ Pause here and try out the following exercises }}} + +%% 4 %% How do you display a prompt and let the user enter input in next line + +{{{ continue from paused state }}} + +.. #[Puneeth: We didn't talk of new-line character till now, did we?] +.. #[Puneeth: non-programmers might not know?] + +.. #[Amit: Well there is a discussion earlier about new lines, I think its good +.. as a slight trick question. But may be next line is a more easier lexicon] + +The trick is to include a newline character at the end of the prompt string. +:: + + ip = raw_input("Please enter a number in the next line\n> ") + +prints the newline character and hence the user enters input in the next line + +{{{ Show summary slide }}} + +This brings us to the end of the tutorial. +In this totorial we have learnt + + * How to print some value + * How to print using modifiers + * How to take input from user + * How to display a prompt to the user before taking the input + +{{{ Show the "sponsored by FOSSEE" slide }}} + + +This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India + +Hope you have enjoyed and found it useful. +Thank You. + diff -r c4c5d1123f07 -r f29d9014e1fc plotting-data/questions.rst --- a/plotting-data/questions.rst Tue Nov 09 16:07:33 2010 +0530 +++ b/plotting-data/questions.rst Tue Nov 09 16:08:26 2010 +0530 @@ -19,14 +19,16 @@ -3. How do you plot points ? +3. How do you plot the data as points using plot function? By passing an extra parameter '.'. .. #[[Anoop: It can better if asked as, How do you plot the data as points using plot function?]] -4. What does the parameter 'o' do ? +4. Can you comment about the result of this plot command . + plot(x, y,'o') + It plots large points. diff -r c4c5d1123f07 -r f29d9014e1fc plotting-data/script.rst --- a/plotting-data/script.rst Tue Nov 09 16:07:33 2010 +0530 +++ b/plotting-data/script.rst Tue Nov 09 16:08:26 2010 +0530 @@ -44,13 +44,14 @@ 2. We will also become familiar with elementwise squaring of such a sequence. -3. We will also see how we can use our graph to indicate Error. +3. How to plot data points using python. + +4. We will also see how we can use our graph to indicate Error. One needs to be familiar with the concepts of plotting mathematical functions in Python. -We will use data from a Simple Pendulum Experiment to illustrate our -points. +We will use data from a Simple Pendulum Experiment to illustrate. .. #[[Anoop: what do you mean by points here? if you mean the points/numbered list in outline slide, then remove the usage point @@ -67,29 +68,28 @@ First we will have to initiate L and T values. We initiate them as sequence -of values. To tell ipython a sequence of values we write the sequence in -comma seperated values inside two square brackets. This is also called List -so to create two sequences +of values. We define a sequence by comma seperated values inside two square brackets. +This is also called List.Lets create two sequences L and t. .. #[[Anoop: instead of saying "to tell ipython a sequence of values" and make it complicated, we can tell, we define a sequence as]] -L,t type in ipython shell. - .. #[[Anoop: sentence is incomplete, can be removed]] -:: +{{{ Show the initializing L&T slide }}} + +Type in ipython shell :: - In []: L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9] + L = [0.1, 0.2, 0.3, 0.4, 0.5,0.6, 0.7, 0.8, 0.9] - In []: t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94] + t= [0.69, 0.90, 1.19,1.30, 1.47, 1.58, 1.77, 1.83, 1.94] -To obtain the square of sequence t we will use the function square +To obtain the square of sequence t we will use the function square with argument t.This is saved into the variable tsquare.:: - In []: tsquare=square(t) - + tsquare=square(t) + tsqaure array([ 0.4761, 0.81 , 1.4161, 1.69 , 2.1609, 2.4964, 3.1329, 3.3489, 3.7636]) @@ -98,49 +98,51 @@ Now to plot L vs T^2 we will simply type :: - In []: plot(L,t,'.') + plot(L,tsquare,'.') .. #[[Anoop: be consistent with the spacing and all.]] '.' here represents to plot use small dots for the point. :: - In []: clf() + clf() You can also specify 'o' for big dots.:: - In []: plot(L,t,'o') + plot(L,tsquare,'o') - In []: clf() + clf() .. #[[Anoop: Make sure code is correct, corrected plot(L,t,o) to plot(L,t,'o')]] -{{{ Slide with Error data included }}} + .. #[[Anoop: again slides are incomplete.]] -Now we shall try and take into account error into our plots . The -Error values for L and T are on your screen.We shall again intialize -the sequence values in the same manner as we did for L and t +For any experimental there is always an error in measurements due to +instrumental and human constaraints.Now we shall try and take into +account error into our plots . The Error values for L and T are on +your screen.We shall again intialize the sequence values in the same +manner as we did for L and t +The error data we will use is on your screen. + +{{{ Show the Adding Error Slide }}} .. #[[Anoop: give introduction to error and say what we are going to do]] :: - In []: delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01] - - In []: delta_T= [0.04,0.08,0.11,0.05,0.03,0.03,0.01,0.07,0.01] - - + delta_L= [0.08,0.09,0.07,0.05,0.06,0.00,0.06,0.06,0.01] + delta_T= [0.04,0.08,0.03,0.05,0.03,0.03,0.04,0.07,0.08] Now to plot L vs T^2 with an error bar we use the function errorbar() The syntax of the command is as given on the screen. :: - In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') + errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') This gives a plot with error bar for x and y axis. The dots are of blue color. The parameters xerr and yerr are error on x and y axis and @@ -150,18 +152,18 @@ similarly we can draw the same error bar with big red dots just change the parameters to fmt to 'ro'. :: - In []: clf() - In []: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='ro') + clf() + errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='ro') thats it. you can explore other options to errorbar using the documentation of errorbar.:: - In []: errorbar? + errorbar? -{{{ Summary Slides }}} +{{{ Show Summary Slide }}} In this tutorial we have learnt : @@ -182,5 +184,5 @@ Hope you have enjoyed and found it useful. - Thankyou +Thank You! diff -r c4c5d1123f07 -r f29d9014e1fc plotting-data/slides.org --- a/plotting-data/slides.org Tue Nov 09 16:07:33 2010 +0530 +++ b/plotting-data/slides.org Tue Nov 09 16:08:26 2010 +0530 @@ -2,26 +2,40 @@ #+LaTeX_CLASS_OPTIONS: [presentation] #+BEAMER_FRAME_LEVEL: 1 -#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC -#+OPTIONS: H:5 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} #+TITLE: Plotting Experimental Data #+AUTHOR: FOSSEE #+DATE: 2010-09-14 Tue #+EMAIL: info@fossee.in -# \author[FOSSEE] {FOSSEE} - -# \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -# \date{} +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc -* Tutorial Plan -** Plotting Experiment Data and Error Bars -* Pre-requisites -** Plotting simple analytical Functions -* plot L vs. T^2 +* Outline + - Defining sequence of numbers + - Squaring sequence of numbers + - Plotting Data Points + - Indicating Error through Errorbars + +* Simple Pendulum Data #+ORGTBL: L vs T^2 orgtbl-to-latex @@ -36,41 +50,27 @@ | 0.8 | 1.83 | | 0.9 | 1.94 | - - * Initializing L & T - : In []: L = [0.1, 0.2, 0.3, 0.4, 0.5, - : 0.6, 0.7, 0.8, 0.9] - : In []: t = [0.69, 0.90, 1.19, - : 1.30, 1.47, 1.58, - : 1.77, 1.83, 1.94] -* square() - : In []: tsquare=square(t) - - : array([ 0.4761, 0.81 , 1.4161, 1.69 , 2.1609, 2.4964, 3.1329, - : 3.3489, 3.7636]) - - -* Plotting - : In[]: plot(L,t,.) - - - : In[]: plot(L,t,o) + : L = [0.1, 0.2, 0.3, 0.4, 0.5, + : 0.6, 0.7, 0.8, 0.9] + : t = [0.69, 0.90, 1.19, + : 1.30, 1.47, 1.58, + : 1.77, 1.83, 1.94] * Adding Error - | L | T | /Delta L | /Delta T | + | L | T | \delta L | \delta T | | 0.1 | 0.69 | 0.08 | 0.04 | | 0.2 | 0.90 | 0.09 | 0.08 | - | 0.3 | 1.19 | 0.07 | 0.11 | + | 0.3 | 1.19 | 0.07 | 0.03 | | 0.4 | 1.30 | 0.05 | 0.05 | | 0.5 | 1.47 | 0.06 | 0.03 | | 0.6 | 1.58 | 0.00 | 0.03 | - | 0.7 | 1.77 | 0.06 | 0.01 | + | 0.7 | 1.77 | 0.06 | 0.04 | | 0.8 | 1.83 | 0.06 | 0.07 | - | 0.9 | 1.94 | 0.01 | 0.01 | + | 0.9 | 1.94 | 0.01 | 0.08 | * Plotting Error bar @@ -78,4 +78,9 @@ : In[]: errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, : fmt='b.') - +* Summary + : L = [0.1, 0.2, 0.3, 0.4, 0.5, | + : 0.6, 0.7, 0.8, 0.9] + : plot(x,y,'o') + : plot(x,y,'.') + : errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') diff -r c4c5d1123f07 -r f29d9014e1fc plotting-data/slides.tex --- a/plotting-data/slides.tex Tue Nov 09 16:07:33 2010 +0530 +++ b/plotting-data/slides.tex Tue Nov 09 16:08:26 2010 +0530 @@ -1,4 +1,4 @@ -% Created 2010-11-07 Sun 18:57 +% Created 2010-11-09 Tue 15:09 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -16,13 +16,19 @@ \usepackage{amssymb} \usepackage{hyperref} \tolerance=1000 +\usepackage[english]{babel} \usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} +\usepackage{listings} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} \providecommand{\alert}[1]{\textbf{#1}} \title{Plotting Experimental Data} \author{FOSSEE} \date{2010-09-14 Tue} -\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} \maketitle @@ -32,27 +38,23 @@ + + + \begin{frame} -\frametitle{Tutorial Plan} +\frametitle{Outline} \label{sec-1} + \begin{itemize} - -\item Plotting Experiment Data and Error Bars\\ -\label{sec-1_1}% -\end{itemize} % ends low level +\item Defining sequence of numbers +\item Squaring sequence of numbers +\item Plotting Data Points +\item Indicating Error through Errorbars +\end{itemize} \end{frame} \begin{frame} -\frametitle{Pre-requisites} +\frametitle{Simple Pendulum Data} \label{sec-2} -\begin{itemize} - -\item Plotting simple analytical Functions\\ -\label{sec-2_1}% -\end{itemize} % ends low level -\end{frame} -\begin{frame} -\frametitle{plot L vs. T$^2$} -\label{sec-3} @@ -74,70 +76,38 @@ - \end{frame} \begin{frame}[fragile] \frametitle{Initializing L \& T} -\label{sec-4} - -\begin{verbatim} - In []: L = [0.1, 0.2, 0.3, 0.4, 0.5, - 0.6, 0.7, 0.8, 0.9] - In []: t = [0.69, 0.90, 1.19, - 1.30, 1.47, 1.58, - 1.77, 1.83, 1.94] -\end{verbatim} -\end{frame} -\begin{frame}[fragile] -\frametitle{square()} -\label{sec-5} +\label{sec-3} \begin{verbatim} - In []: tsquare=square(t) -\end{verbatim} - - -\begin{verbatim} - array([ 0.4761, 0.81 , 1.4161, 1.69 , 2.1609, 2.4964, 3.1329, - 3.3489, 3.7636]) -\end{verbatim} - - - -\end{frame} -\begin{frame}[fragile] -\frametitle{Plotting} -\label{sec-6} - -\begin{verbatim} - In[]: plot(L,t,.) -\end{verbatim} - - - -\begin{verbatim} - In[]: plot(L,t,o) + L = [0.1, 0.2, 0.3, 0.4, 0.5, + 0.6, 0.7, 0.8, 0.9] + t = [0.69, 0.90, 1.19, + 1.30, 1.47, 1.58, + 1.77, 1.83, 1.94] \end{verbatim} \end{frame} \begin{frame} \frametitle{Adding Error} -\label{sec-7} +\label{sec-4} \begin{center} \begin{tabular}{rrrr} - L & T & /Delta L & /Delta T \\ - 0.1 & 0.69 & 0.08 & 0.04 \\ - 0.2 & 0.90 & 0.09 & 0.08 \\ - 0.3 & 1.19 & 0.07 & 0.11 \\ - 0.4 & 1.30 & 0.05 & 0.05 \\ - 0.5 & 1.47 & 0.06 & 0.03 \\ - 0.6 & 1.58 & 0.00 & 0.03 \\ - 0.7 & 1.77 & 0.06 & 0.01 \\ - 0.8 & 1.83 & 0.06 & 0.07 \\ - 0.9 & 1.94 & 0.01 & 0.01 \\ + L & T & $\delta$ L & $\delta$ T \\ + 0.1 & 0.69 & 0.08 & 0.04 \\ + 0.2 & 0.90 & 0.09 & 0.08 \\ + 0.3 & 1.19 & 0.07 & 0.03 \\ + 0.4 & 1.30 & 0.05 & 0.05 \\ + 0.5 & 1.47 & 0.06 & 0.03 \\ + 0.6 & 1.58 & 0.00 & 0.03 \\ + 0.7 & 1.77 & 0.06 & 0.04 \\ + 0.8 & 1.83 & 0.06 & 0.07 \\ + 0.9 & 1.94 & 0.01 & 0.08 \\ \end{tabular} \end{center} @@ -147,7 +117,7 @@ \end{frame} \begin{frame}[fragile] \frametitle{Plotting Error bar} -\label{sec-8} +\label{sec-5} \begin{verbatim} @@ -155,5 +125,17 @@ fmt='b.') \end{verbatim} \end{frame} +\begin{frame}[fragile] +\frametitle{Summary} +\label{sec-6} + +\begin{verbatim} + L = [0.1, 0.2, 0.3, 0.4, 0.5, | + 0.6, 0.7, 0.8, 0.9] + plot(x,y,'o') + plot(x,y,'.') + errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') +\end{verbatim} +\end{frame} \end{document} diff -r c4c5d1123f07 -r f29d9014e1fc progress.org --- a/progress.org Tue Nov 09 16:07:33 2010 +0530 +++ b/progress.org Tue Nov 09 16:08:26 2010 +0530 @@ -5,7 +5,7 @@ | 1.4 LO: | embellishing a plot | 2 | Nishanth | Anoop (Done) | | | 1.5 LO: | saving plots | 2 | Anoop | Punch (Done) | | | 1.6 LO: | multiple plots | 3 | Madhu | Nishanth (Done) | | -| 1.7 LO: | additional features of IPython | 2 | Nishanth | Amit (Pending) | | +| 1.7 LO: | additional features of IPython | 2 | Nishanth | Amit (Done) | | | 1.8 LO: | module level assessment | 3 | Madhu | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| | 2.2 LO: | loading data from files | 3 | Punch | Nishanth (Done) | | @@ -34,7 +34,7 @@ | 5.5 LO: | Assessment | 3 | Anoop | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| | 6.1 LO: | basic datatypes & operators | 4 | Amit | Punch (Done) | | -| 6.2 LO: | I/O | 1 | Nishanth | | | +| 6.2 LO: | I/O | 1 | Nishanth | Amit(Done) | | | 6.3 LO: | conditionals | 2 | Madhu | | | | 6.4 LO: | loops | 2 | Punch | Anoop (Done) | | | 6.5 LO: | Assessment | 3 | Anoop | | | diff -r c4c5d1123f07 -r f29d9014e1fc progress.org.orig --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/progress.org.orig Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,55 @@ +| S.No | Name | Units | Author | Review | Checklist | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 1.2 LO: | getting started with =ipython= | 2 | Punch | Anoop (Done) | | +| 1.3 LO: | using the =plot= command interactively | 2 | Amit | | | +| 1.4 LO: | embellishing a plot | 2 | Nishanth | Anoop (Done) | | +| 1.5 LO: | saving plots | 2 | Anoop | | | +| 1.6 LO: | multiple plots | 3 | Madhu | Nishanth (Done) | | +| 1.7 LO: | additional features of IPython | 2 | Nishanth | Amit (Pending) | | +| 1.8 LO: | module level assessment | 3 | Madhu | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 2.2 LO: | loading data from files | 3 | Punch | Nishanth (Done) | | +| 2.3 LO: | plotting the data | 3 | Amit | | | +| 2.4 LO: | other types of plots | 3 | Anoop | Pending | | +| 2.5 LO: | module level assessment | 3 | Nishanth | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 3.1 LO: | getting started with lists | 2 | Amit | | | +| 3.2 LO: | getting started with =for= | 2 | Anoop | Nishanth (Done) | | +| 3.3 LO: | getting started with strings | 2 | Madhu | | | +| 3.4 LO: | getting started with files | 3 | Punch | Anoop(Done) | | +| 3.5 LO: | parsing data | 3 | Nishanth | Amit (Done) | | +| 3.6 LO: | statistics | 2 | Amit | | | +| 3.7 LO: | module level assessment | 3 | Madhu | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 4.1 LO: | getting started with arrays | 2 | Anoop | Punch (Done) | | +| 4.2 LO: | accessing parts of arrays | 4 | Punch | Anoop (Done) | | +| 4.3 LO: | Matrices | 3 | Anoop | Punch (changes before further review) | | +| 4.4 LO: | Least square fit | 2 | Nishanth | Punch (Done) | | +| 4.5 LO: | Assessment | 3 | Punch | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 5.1 LO: | getting started with sage notebook | 3 | Madhu | | | +| 5.2 LO: | getting started with symbolics | 3 | Amit | | | +| 5.3 LO: | using Sage | 4 | Punch | Anoop (Pending) | | +| 5.4 LO: | using sage to teach | 3 | Nishanth | | | +| 5.5 LO: | Assessment | 3 | Anoop | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 6.1 LO: | basic datatypes & operators | 4 | Amit | Punch (Done) | | +| 6.2 LO: | I/O | 1 | Nishanth | | | +| 6.3 LO: | conditionals | 2 | Madhu | | | +| 6.4 LO: | loops | 2 | Puneeth | Anoop(Pending) | | +| 6.5 LO: | Assessment | 3 | Anoop | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 7.1 LO: | manipulating lists | 3 | Madhu | | | +| 7.2 LO: | manipulating strings | 2 | Punch | Anoop | Amit | +| 7.3 LO: | getting started with tuples | 2 | Nishanth | | | +| 7.4 LO: | dictionaries | 2 | Anoop | Pending | | +| 7.5 LO: | sets | 2 | Nishanth | | | +| 7.6 LO: | Assessment | 3 | Amit | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| +| 8.1 LO: | getting started with functions | 3 | Nishanth | | | +| 8.2 LO: | advanced features of functions | 3 | Punch | Anoop (Pending) | | +| 8.3 LO: | using python modules | 3 | Anoop | Pending | | +| 8.4 LO: | writing python scripts | 2 | Nishanth | | | +| 8.5 LO: | testing and debugging | 2 | Amit | | | +| 8.6 LO: | Assessment | 3 | Madhu | | | +|---------+----------------------------------------+-------+----------+---------------------------------------+-----------| diff -r c4c5d1123f07 -r f29d9014e1fc symbolics/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/symbolics/slides.org Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,33 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC +#+OPTIONS: H:5 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t + +#+TITLE: Plotting Data +#+AUTHOR: FOSSEE +#+DATE: 2010-09-14 Tue +#+EMAIL: info@fossee.in + +# \author[FOSSEE] {FOSSEE} + +# \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +# \date{} + +* Tutorial Plan +** Defining symbolic expressions in sage. +** Using built-in costants and functions. +** Performing Integration, differentiation using sage. +** Defining matrices. +** Defining Symbolic functions. +** Simplifying and solving symbolic expressions and functions. +* Summary +** We learnt about defining symbolic expression and functions. +** Using built-in constants and functions. +** Using to see the documentation of a function. +** Simple calculus operations . +** Substituting values in expression using substitute function. +** Creating symbolic matrices and performing operation on them . diff -r c4c5d1123f07 -r f29d9014e1fc using-plot-interactively/home.png Binary file using-plot-interactively/home.png has changed diff -r c4c5d1123f07 -r f29d9014e1fc using-plot-interactively/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/using-plot-interactively/slides.org Tue Nov 09 16:08:26 2010 +0530 @@ -0,0 +1,37 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC +#+OPTIONS: H:5 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t + +#+TITLE: Plotting Data +#+AUTHOR: FOSSEE +#+DATE: 2010-09-14 Tue +#+EMAIL: info@fossee.in + +# \author[FOSSEE] {FOSSEE} + +# \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +# \date{} + +* Tutorial Plan +** Creating a simple plot +** Use the buttons on window to study the plot + +* Error if Ipython not installed + +** `ERROR: matplotlib could NOT be imported! Starting normal IPython.` + +* Plot UI + +* Summary + +** Start Ipython with pylab +** Using linspace +** Finding length of sequnces using len. +** Plotting mathematical functions using plot. +** Clearing drawing area using clf +** Using the UI of plot