Merge with the main branch.
authorPuneeth Chaganti <punchagan@fossee.in>
Fri, 17 Sep 2010 18:06:34 +0530
changeset 158 b459053192f1
parent 157 a1111c1815f6 (current diff)
parent 154 0094e5b93fe6 (diff)
child 161 b7c47307e510
Merge with the main branch.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/arrays.txt	Fri Sep 17 18:06:34 2010 +0530
@@ -0,0 +1,27 @@
+Hello friends and welcome to the second tutorial in the series of spoken tutorials on Python for Scientific computing. 
+
+In the previous tutorial we learnt about arrays and we told you that numpy arrays are faster and more efficient . In this tutorial we shall look at creating arrays, accessing elements and changing them. 
+
+
+Let's start with creating simple arrays. We've already seen how to convert lists to arrays. Inputting a new array is similarto that. 
+
+On your Ipython terminal type a = array open parenthesis and then open square brackets 5,8,10,13 ,close square brackets and close parenthesis . This create an array a . You can see what a is by typing a on the terminal .
+Now we will try to create a multi-dimensional array type in your ipython terminal
+c= array open parenthesis , then open square brackets 11,12,13 close square bracket 'comma' start square bracket 21 , 22 ,23close square bracket 'comma' open 31,32,33 close square bracket another close square bracket which closes the first sqaure bracket and parenthesis which closes the first parenthesis . Now to see the dimensions of the array c we will do c.shape . We can see that c is a 3 by 3 matrix .
+
+There are other special methods of creating arrays as well we will now look at them .
+The first one is the command arange which is similar to range except that it returns an array.
+We will type on our Ipython interpreter a = arange(10). We will see what a is now . Type a . As we can see This returns us an array of one dimension and has 10 elements .  
+Ones can be use to get all entries as ones . We can pass it the shape of the array as required .
+type b=ones open parenthesis , another open parenthesis , 3,4 , close second parenthesis and close first parenthesis . Look at b , by printing it out .
+To create an array with all entries as ones, with it's shape similar to an already existing array, we use the ones_like
+command.  type b= ones_like in parenthesis a . 
+
+ 
+
+ 
+     
+   
+
+
+  
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/module_assesment_plotting_exp_data.rst	Fri Sep 17 18:06:34 2010 +0530
@@ -0,0 +1,35 @@
+Hello friends.
+
+This tutorial is a self-assessment tutorial and you will be able to assess 
+yourself on the concepts learnt in the Module "Plotting Expetimental data"
+
+As with all other assessments we will first start with a few short questions 
+that will not take you more that 15 to 20 seconds to answer. Then we shall move
+on to a bigger problems that should take you about 5 mins.
+
+{{{ Always show slide and explain the problem }}} 
+
+ * What is the shape of plot resulting from the following piece of code::
+
+       x = linspace(0, 2*pi, 4)
+       plot(x, sin(x))
+
+ * #[Nishanth]: Hav to add a simple question on scatter plot
+
+ * #[Nishanth]: Hav to add a simple question on pie chart
+
+ * Input file contains 25 lines of data, each containing 5 values seperated by
+   spaces. What is the shape of the resulting matrix from the command::
+
+       loadtxt("input-file.txt", unpack=True)
+
+{{{ Big problem - 5 mins }}} 
+
+The input file ``pos.txt`` contains two columns of data. The first column 
+contains x position and second column contains y position of a particle in
+flight. Plot the trajectory of the particle. What kind of motion is it? 
+
+.. Author              : Nishanth
+   Internal Reviewer 1 : 
+   Internal Reviewer 2 : 
+   External Reviewer   :
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plotting-data.rst	Fri Sep 17 18:06:34 2010 +0530
@@ -0,0 +1,137 @@
+Plotting   Experimental  Data  
+=============================   
+Hello  and welcome , this tutorial on  Plotting Experimental data is 
+presented by the fossee  team.  
+
+{{{ Show the slide containing title }}}
+
+
+{{{ Show the Outline Slide }}}
+
+Here  we will discuss plotting  Experimental data. 
+
+1.We will see how we can represent a sequence of numbers in Python. 
+
+2.We will also become fimiliar with  elementwise squaring of such a
+sequence. 
+
+3. We will also see how we can use our graph to indicate Error.
+
+One needs   to  be  fimiliar  with  the   concepts  of  plotting
+mathematical functions in Python.
+
+We will use  data from a Simple Pendulum  Experiment to illustrate our
+points. 
+
+{{{ Simple Pendulum data Slide }}} 
+
+  
+  
+  
+As we know for a simple pendulum length,L is directly  proportional to 
+the square of time,T. We shall be plotting L and T^2 values.
+
+
+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
+
+L,t type in ipython shell. ::
+
+    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]
+
+
+  
+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)
+  
+   array([  0.4761, 0.81 , 1.4161,  1.69 , 2.1609,  2.4964, 3.1329, 
+   3.3489, 3.7636])
+
+  
+Now to plot L vs T^2 we will simply type ::
+
+  In []: plot(L,t,.)
+
+'.' here represents to plot use small dots for the point. ::
+
+  In []: clf()
+
+You can also specify 'o' for big dots.::
+ 
+  In []: plot(L,t,o)
+
+  In []: clf()
+
+
+{{{ Slide with Error data included }}}
+
+
+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 ::
+
+  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]
+
+
+  
+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.')
+
+This gives a  plot with error bar for  x and y axis. The  dots are of
+blue color.
+
+
+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')
+
+
+
+thats it. you can explore other options to errorbar using the documentation 
+of errorbar.::
+
+   In []: errorbar?
+
+
+{{{ Summary Slides }}}
+
+In this tutorial we have learnt : 
+
+1. How to declare a sequence of number , specifically the kind of sequence we learned was a list.
+
+2. Plotting experimental data extending our knowledge from mathematical functions. 
+
+3. The various options available for plotting dots instead of lines.
+
+4. Plotting experimental data such that we can also represent error. We did this using the errorbar() function.
+
+
+ {{{ Show the "sponsored by FOSSEE" slide }}}
+
+
+
+This tutorial was created as a part of FOSSEE project.
+
+Hope you have enjoyed and found it useful.
+
+ Thankyou
+
+ 
+
+Author              : Amit Sethi
+Internal Reviewer   :
+Internal Reviewer 2 : 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/plotui.rst	Fri Sep 17 18:06:34 2010 +0530
@@ -0,0 +1,177 @@
+Hello and welcome to the tutorial on creating simple plots using
+Python.This tutorial is presented by the Fossee group.  
+{{{ Show the Title Slide }}} 
+
+I hope you have IPython running on your computer.
+
+In this tutorial we will look at plot command and also how to study
+the plot using the UI.
+
+{{{ Show Outline Slide }}}
+
+Lets start ipython on your shell, type :: 
+
+      $ipython -pylab
+
+
+Pylab is a python library which provides plotting functionality.It
+also provides many other important mathematical and scientific
+functions. After running IPython -pylab in your shell if at the top of
+the result of this command, you see something like ::
+ 
+
+   `ERROR: matplotlib could NOT be imported!  Starting normal
+      IPython.`
+
+
+{{{ Slide with Error written on it }}}
+
+Then you have to install matplotlib and run this command again.
+
+Now type in your ipython shell ::
+
+             In[]: linpace?
+
+
+
+as the documentation says, it returns `num` evenly spaced samples,
+calculated over the interval start and stop.  To illustrate this, lets
+do it form 1 to 100 and try 100 points.  ::
+
+           In[]: linspace(1,100,100)
+
+As you can see a sequence of numbers from 1 to 100 appears.
+
+Now lets try 200 points between 0 and 1 you do this by typing ::
+
+
+            In[]: linspace(0,1,200)
+
+0 for start , 1 for stop and 200 for no of points.  In linspace 
+the start and stop points can be integers, decimals , or
+constants. Let's try and get 100 points between -pi to pi. Type ::
+           
+            In[]: p = linspace(-pi,pi,100)
+
+
+'pi' here is constant defined by pylab. Save this to the variable, p
+.
+
+If you now ::
+     
+	   In[]: len(p)
+
+You will get the no. of points. len function gives the no of elements
+of a sequence.
+
+
+Let's try and plot a cosine curve between -pi and pi using these
+points.  Simply type :: 
+
+
+       	  In[]: plot(p,cos(points))
+
+Here cos(points) gets the cosine value at every corresponding point to
+p.
+
+
+We can also save cos(points) to variable cosine and plot it using
+plot.::
+
+           In[]: cosine=cos(points) 
+
+	   In[]: plot(p,cosine)
+
+ 
+
+Now do ::
+       	 
+	   In[]: clf()
+
+this will clear the plot.
+
+This is done because any other plot we try to make shall come on the
+same drawing area. As we do not wish to clutter the area with
+overlaid plots , we just clear it with clf().  Now lets try a sine
+plot. ::
+
+
+    	 In []: plot(p,sin(p))
+
+
+
+ 
+The Window on which the plot appears can be used to study it better.
+
+First of all moving the mouse around gives us the point where mouse
+points at.  
+
+Also we have some buttons the right most among them is
+for saving the file. 
+
+Just click on it specifying the name of the file.  We will save the plot 
+by the name sin_curve in pdf format.
+
+{{{ Action corelating with the words }}}
+
+As you can see I can specify format of file.  
+Left to the save button is the slider button to specify the margins.  
+
+{{{ Action corelating with the words  }}}
+
+Left to this is zoom button to zoom into the plot. Just specify the 
+region to zoom into.  
+The button left to it can be used to move the axes of the plot.  
+
+{{{ Action corelating with the words }}}
+ 
+The next two buttons with a left and right arrow icons change the state of the 
+plot and take it to the previous state it was in. It more or less acts like a
+back and forward button in the browser.  
+
+{{{ Action corelating with the words }}}
+
+The last one is 'home' referring to the initial plot.
+
+{{{ Action corelating with the words}}}
+
+
+
+{{{ Summary Slide }}}
+
+
+In this tutorial we have looked at 
+
+1. Starting Ipython with pylab 
+
+2. Using linspace function to create `num` equaly spaced points in a region.
+
+3. Finding length of sequnces using  len.
+ 
+4. Plotting mathematical functions using plot.
+
+4. Clearing drawing area using clf 
+ 
+5. Using the UI of plot for studying it better . Using functionalities like save , zoom , moving the plots on x and y axis 
+
+etc ..
+ 
+
+
+{{{ 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.
+
+ Thankyou
+
+ 
+
+Author              : Amit Sethi
+Internal Reviewer   :
+Internal Reviewer 2 : 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/symbolics.rst	Fri Sep 17 18:06:34 2010 +0530
@@ -0,0 +1,248 @@
+Symbolics with Sage
+-------------------
+
+This tutorial on using Sage for symbolic calculation is brought to you
+by Fossee group.
+
+{{{ Part of Notebook with title }}}
+
+We would be using simple mathematical functions on the sage notebook
+for this tutorial .
+
+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
+    
+
+
+Using sage we can perform mathematical operations on symbols .
+
+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. ::
+   
+    var('y')
+   
+Now if you type::
+
+    sin(y)
+
+     sage simply returns the expression .
+
+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 .
+
+Try out ::
+   
+   var('x,alpha,y,beta') x^2/alpha^2+y^2/beta^2
+ 
+Similarly , we can define many algebraic and trigonometric expressions
+using sage .
+
+
+
+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.
+
+For instance::
+
+   n(e)
+   
+   2.71828182845905
+
+gives numerical value of e.
+
+If you look into the documentation of n by doing ::
+
+   n(<Tab>
+
+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
+      
+
+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::
+  
+   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. ::
+     
+   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(<tab> {{{ Just to show the documentation
+       extend this line }}} function('f',x)
+
+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 function 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::
+      
+
+      var('x') h(x)=x^2 g(x)=1 f=Piecewise(<Tab> {{{ 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)
+
+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 .
+
+We first define a function f(n) in the way discussed above.::
+
+   var('n') function('f', n)
+
+
+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)
+
+    f(n) = (-1)^(n-1)*1/(2*n - 1)
+
+This series converges to pi/4. It was used by ancient Indians to
+interpret pi.
+
+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
+
+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 .
+
+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(<tab> diff(f(x),x,3)
+
+
+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
+
+
+
+To find factors of an expression use the function factor
+
+    factor(<tab> 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()
+    
+
+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)
+
+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)
+
+
+as we can see the solution is almost equal to zero .
+
+
+We can also define symbolic matrices ::
+
+
+
+   var('a,b,c,d') A=matrix([[a,1,0],[0,b,0],[0,c,d]]) A
+
+
+Now lets do some of the matrix operations on this matrix ::
+
+
+    A.det() A.inverse()
+
+You can do ::
+    
+    A.<Tab>
+
+To see what all operations are available
+
+
+{{{ 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 .
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tuples.rst	Fri Sep 17 18:06:34 2010 +0530
@@ -0,0 +1,150 @@
+Hello friends and welcome to the tutorial on Tuples
+
+{{{ Show the slide containing title }}}
+
+{{{ Show the slide containing the outline slide }}}
+
+In this tutorial, we shall learn
+
+ * what are tuples
+ * their similarities and dissimilarities with lists
+ * why are they needed
+
+Let`s get started by defining a tuple. A tuple is defined by enclosing
+parantheses around a sequence of items seperated by commas. It is similar to
+defining a list except that parantheses are used instead of square brackets.
+::
+
+    t = (1, 2.5, "hello", -4, "world", 1.24, 5)
+    t
+
+defines a tuple. The items in the tuple are indexed using numbers and can be 
+accessed by using their position.
+::
+
+    t[3]
+
+prints -4 which is the fourth item of the tuple.
+
+::
+
+    t[1:5:2]
+
+prints the corresponding slice
+
+This is the behaviour similar as to lists. But the difference can be seen when
+we try to change an element in the tuple.
+::
+
+    t[2] = "Hello"
+
+We can see that, it raises an error saying tuple does not support item
+assignment. It only implies that tuples are immutable or in simple words,
+tuples cannot be changed.
+
+But what is the use of tuples!!!
+
+We shall understand that soon. But let us look at a simple problem of swapping
+values.
+
+{{{ Pause here and try out the following exercises }}}
+
+%% 1 %% a = 5 and b = 7. swap the values of a and b
+
+{{{ continue from paused state }}}
+::
+
+    a = 5
+    b = 7
+
+    a
+    b
+
+We define the two values
+::
+
+    temp = a
+    a = b
+    b = temp
+
+    a
+    b
+
+This is the traditional approach
+
+Now let us do it the python way
+::
+
+    a
+    b
+
+    a, b = b, a
+
+    a
+    b
+
+We see that the values are swapped.
+This idiom works for different datatypes also.
+::
+
+    a = 2.5
+    b = "hello"
+
+    a
+    b
+
+Moreover this type of behaviour is straight forward and what you would expect
+should happen naturally.
+
+This is possible because of the immutability of tuples. This process is called
+tuple packing and unpacking.
+
+Let us first see what is tuple packing. Type
+::
+
+    5,
+
+What we see is a tuple with one element.
+::
+
+    5, "hello", 2.5
+
+Now it is a tuple with two elements.
+
+So when we are actually typing two or more elements seperated by commas, those
+elements are packed and a tuple is made from them.
+
+When you type
+::
+
+    a, b = b, a
+
+First the values of b and a are packed into a tuple on the right side and then
+unpacked into the variables a and b.
+
+Immutability of tuples ensures that the values are not changed during the
+packing and unpacking.
+
+{{{ Show summary slide }}}
+
+This brings us to the end of the tutorial.
+we have learnt
+
+ * How to define tuples
+ * The similarities of tuples with lists, like indexing and iterability
+ * The immutability of tuples
+ * The value swapping idiom in Python
+ * packing and unpacking of tuples
+
+{{{ 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
+ 
+.. Author              : Nishanth
+   Internal Reviewer 1 : 
+   Internal Reviewer 2 : 
+   External Reviewer   :