Merged
authorNishanth <nishanth@fossee.in>
Mon, 18 Oct 2010 21:11:34 +0530
changeset 336 c77f7f5850dd
parent 326 c4cb18752ade (current diff)
parent 335 d5248a15274c (diff)
child 341 9f7eb1ed0e08
Merged
--- a/additional_ipython/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/additional_ipython/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,6 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B - 
-   C - 
-   D - 
-
 .. By the end of this tutorial you will be able to
 
 .. #. Retrieve your ipython history 
--- a/embellishing_a_plot/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/embellishing_a_plot/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,34 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
+Plot with a specific color. Ex: RED :\\
+{\ex \lstinline|    plot(x, f(x), "r")|}
+
+Plot with a specific style. Ex: DASHED :\\
+{\ex \lstinline|    plot(x, f(x), "--")|}
 
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+Plot with specific color and style. Ex: RED DASHED :\\
+{\ex \lstinline|    plot(x, f(x), "r--")|}
+
+Plot with a specific line thickness:\\
+{\ex \lstinline|    plot(x, f(x), linewidth=3)|}
+
+Adding title:\\
+{\ex \lstinline|    title("Plot of sin(x)")|}
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+labelling the axes:\\
+{\ex \lstinline|    xlabel("x")|}
+{\ex \lstinline|    ylabel("f(x)")|}
+
+Adding annotations:\\
+{\ex \lstinline|    annotate("localmax", xy=(1, 2))|}
+
+Using LaTeX typesetting on any text:\\
+{\ex \lstinline|    title("Plot of $sin(x)$")|}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Getting the axes limits:\\
+{\ex \lstinline|    xlim()|}
+{\ex \lstinline|    ylim()|}
+
+Setting the axes limits:\\
+{\ex \lstinline|    xlim(x_min, x_max)|}
+{\ex \lstinline|    ylim(y_min, y_max)|}
+
+
--- a/embellishing_a_plot/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/embellishing_a_plot/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,6 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B - 
-   C - 
-   D - 
-
 .. By the end of this tutorial you will be able to 
 
 ..  * Modify the attributes of the plot -- color, line style, linewidth
--- a/input_output/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/input_output/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,15 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
+Printing a variable:\\
+{\ex \lstinline|    print x|}
 
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+Printing with out a new line:\\
+{\ex \lstinline|    print x, |}
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+Using modifiers while printing:\\
+{\ex \lstinline|    print "a is \%d b is \%f"\%(a, b)|}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Taking input from user:\\
+{\ex \lstinline|    x = raw_input()|}
+
+Display a prompt while taking input:\\
+{\ex \lstinline|    x = raw_input("Type a number: ")|}
+
--- a/input_output/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/input_output/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,17 +1,11 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B - 
-   C - 
-   D - 
-
 .. #. 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
 .. -------------
 
--- a/lstsq/questions.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/lstsq/questions.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -8,6 +8,8 @@
    #. [1.0, 1.0, 1.0]
    #. Error
    
+   Answer: array([1, 1, 1])
+   
  2. What does ones_like([1.2, 3, 4, 5]) produce
 
    a. [1.2, 3, 4, 5]
@@ -15,4 +17,16 @@
    #. array([1, 1, 1, 1])
    #. array([1.2, 3, 4, 5])
 
+   Answer: array([1.0, 1.0, 1.0, 1.0])
 
+ 3. The plot of ``u`` vs ``v`` is a bunch of scattered points that show a
+    linear trend. How do you find the least square fit line of ``u`` vs ``v``.
+
+   Answer::
+
+      A = array(u, ones_like(u)).T
+      result = lstsq(A, v)
+      m, c = result[0]
+
+      lst_line = m * u + c
+
--- a/lstsq/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/lstsq/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,15 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
+Creating a matrix with all ones:\\
+{\ex \lstinline|    o = ones_like(l)|}
 
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+Creating the A matrix:\\
+{\ex \lstinline|    A = array(l, ones_like(l)).T|}
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+Computing least square:\\
+{\ex \lstinline|    result = lstsq(A, tsq)|}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Obtaining the m and c values:\\
+{\ex \lstinline|    m, c = result[0]|}
+
+Computing the least square fit line:\\
+{\ex \lstinline|    lst_line = m * l + c|}
+
--- a/lstsq/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/lstsq/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,6 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B - 
-   C - 
-   D - 
-
 .. Plotting a least square fit line
 
 .. Prerequisites
@@ -13,6 +8,7 @@
 
 ..   1. Basic Plotting
 ..   2. Arrays
+..   3. Loading data from files 
      
 .. Author              : Nishanth Amuluru
    Internal Reviewer   : 
--- a/parsing_data/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/parsing_data/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,15 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
+Splitting a string on whitespace:\\
+{\ex \lstinline|    str_var.split()|}
 
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+Splitting a string using a delimiter. Ex: ";" :\\
+{\ex \lstinline|    str_var.split(";")|}
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+Stripping the whitespace around a string:\\
+{\ex \lstinline|    str_var.strip()|}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Converting a string or float to int:\\
+{\ex \lstinline|    int(var_name)|}
+
+Converting a string or int into float:\\
+{\ex \lstinline|    float(var_name)|}
+
--- a/parsing_data/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/parsing_data/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,10 +1,11 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B - 
-   C - 
-   D - 
+.. By the end of this tutorial you will be able to
+
+..  * Split a string using a delimiter
+..  * remove the whitespace around the string
+..  * convert the variables from one type to other
 
 .. Prerequisites
 .. -------------
--- a/plotting_using_sage/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/plotting_using_sage/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,30 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
+Plot simple 2D functions on a linear range of x:\\
+{\ex \lstinline|    plot(f(x), (x, 0, 2*pi)|}
+
+Plot 2D plots where x and y are functions of another variable:\\
+{\ex \lstinline|    parametric_plot((f_x, f_y), (x, 0, 2*pi), (y, 0, 2*pi))|}
 
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+Generate a sequence of points with a given seperation:\\
+{\ex \lstinline|    points = srange(2.5, 5.5, 0.25)|}
+
+Plot a line joining a list of pairs of points:\\
+{\ex \lstinline|    line(list_pairs)|}
+
+Show the plots:\\
+{\ex \lstinline|    show(plot_name)|}
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+Show multiple plots:\\
+{\ex \lstinline|    show(p1+p2+p3)|}
+
+Set x-axis limits:\\
+{\ex \lstinline|    show(p1+p2, xmim=0, xmax=2*pi)|}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Set y-axis limits:\\
+{\ex \lstinline|    show(p1+p2, ymim=-1.2, ymax=1.2)|}
+
+Plot 3D functions:\\
+{\ex \lstinline|    plot3d(f(x, y), (x, 0, 2*pi), (y, -1, 1))|}
+
+Plot 3D functions where x, y, z are functions of another variable:\\
+{\ex \lstinline|    parametric_plot3d((f_x, f_y, f_z), (t, 0, 10))|}
+
--- a/plotting_using_sage/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/plotting_using_sage/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,10 +1,10 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B -
-   C - 
-   D - 
+.. By the end of this tutorial you will be able to 
+
+..  * Use SAGE for 2D plotting
+..  * Use SAGE for 3D plotting
 
 .. Prerequisites
 .. -------------
--- a/sets/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/sets/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,23 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
+Creating a set:\\
+{\ex \lstinline|   p10 = set([2, 3, 5, 7]) |t}
 
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+Creating set from a tuple or list:\\
+{\ex \lstinline|   s = set(var_name)|}
+
+Operations on sets. Ex: UNION:\\
+{\ex \lstinline|   s1 \| s2 |}
+
+Other operations available:\\
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+\begin{lstlising}
+\item "\&" -- Intersection
+\item "-" -- Difference
+\item "\^" -- Symmetric Difference
+\item "<" -- Subset
+\end{lstlisting}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Checking for containership:\\
+{\ex \lstinline|    x in p10|}
+
+Finding the no.of elements:\\
+{\ex \lstinline|    len(p10)|}
--- a/sets/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/sets/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,13 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B - Will learn what are tuples and why they are needed
-       Will learn the various methods of accessing elements in tuples
-   C - 
-   D - 
+.. By the end of this tutorial, you will be able to 
+
+.. * Create sets from lists
+.. * Perform union, intersection and symmetric difference operations
+.. * Check if a set is a subset of other
+.. * understand various similarities with lists like length and containership
+
 
 .. Prerequisites
 .. -------------
--- a/using_sage_to_teach/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/using_sage_to_teach/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,26 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
+using @interact:\\
+{\ex \lstinline|    @interact
+                    def f(a=5,b=[1,2],c=(0..3))|}
 
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+Default argument for a field input:\\
+{\ex \lstinline|    def f(a="hello")|}
+
+Default argument for slider:\\
+{\ex \lstinline|    def f(a=(1..8))|}
+
+Default argument for buttons:\\
+{\ex \lstinline|    def f(a=[1, 2, 3])|}
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+Publish worksheets:\\
+{\ex \lstinline|    Use Publish option on top right corner|}
+
+Re-Publish worksheets:\\
+{\ex \lstinline|    Check the auto re-publish option while publishing or click
+on publish and click on the re-publish option on the page.|}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Share the worksheets:\\
+{\ex \lstinline|    Click on the share button and enter the usernames|}
+
+Editing a published worksheet:\\
+{\ex \lstinline|    Open the worksheet and click on the edit button on top left
+corner|}
--- a/using_sage_to_teach/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/using_sage_to_teach/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,10 +1,10 @@
 .. Objectives
 .. ----------
 
-.. A - Students and teachers from Science and engineering backgrounds
-   B - 
-   C - 
-   D - 
+.. By the end of this tutorial you will be able to
+
+..  * use ``@interact`` feature of SAGE
+..  * learn to share, publish and edit SAGE worksheets
 
 .. Prerequisites
 .. -------------
--- a/writing_python_scripts/questions.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/writing_python_scripts/questions.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,90 +1,120 @@
 Objective Questions
 -------------------
 
- 1. If ``a = [1, 1, 2, 3, 3, 5, 5, 8]``. What is set(a)
+ 1. Which of the following variables contains the locations to search for
+    python modules
 
-   a. set([1, 1, 2, 3, 3, 5, 5, 8])
-   #. set([1, 2, 3, 5, 8])
-   #. set([1, 2, 3, 3, 5, 5])
-   #. Error
+   a. sys.pythonpath
+   #. sys.path
+   #. os.pythonpath
+   #. os.path
+
+   Answer: sys.path
 
-   Answer: set([1, 2, 3, 5, 8])
-
- 2. ``a = set([1, 3, 5])``. How do you find the length of a?
+ 2. What is the type of ``sys.path``
 
-   Answer: len(a)
+   a. list of strings
+   #. list of int
+   #. string
+   #. tuple of strings
 
- 3. ``a = set([1, 3, 5])``. What does a[2] produce?
+   Answer: list of strings
+
+ 3. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
+    the following code:
 
-   a. 1
-   #. 3
-   #. 5
-   #. Error
+      def show(x):
+          print x
+
+      show("Hello World")
 
-   Answer: Error
+      if __name__ == "__main__":
 
- 4. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
-    is the value of ``odd | squares``?
+          show("Hello Test")
+
+    How do you import the file.
 
-   Answer: set([1, 3, 4, 5, 7, 9, 16])
+   a. import utils
+   #. import utils.py
+   #. import /home/user/utils
+   #. import /home/user/utils.py
 
- 5. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
-    is the value of ``odd - squares``?
+   Answer: import utils
 
-   Answer: set([3, 5, 7])
+ 4. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
+    the following code:
 
- 6. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
-    is the value of ``odd ^ squares``?
+      def show(x):
+          print x
+
+      show("Hello World")
 
-   Answer: set([3, 4, 5, 7, 16])
+      if __name__ == "__main__":
+
+          show("Hello Test")
 
- 7. ``odd = set([1, 3, 5, 7, 9])`` and ``squares = set([1, 4, 9, 16])``. What
-    does ``odd * squares`` give?
+    How do you use the ``show`` function after doing ``import utils``
+
+   a. utils.show("hey")
+   #. show("hey")
+   #. utils.py.show("hey")
+   #. utils.py.show.py("hey")
 
-   a. set([1, 12, 45, 112, 9])
-   #. set([1, 3, 4, 5, 7, 9, 16])
-   #. set([])
-   #. Error
+   Answer: utils.show("hey")
+
+ 5. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
+    the following code:
 
-   Answer: Error
+      def show(x):
+          print x
 
- 8. ``a = set([1, 2, 3, 4])`` and ``b = set([5, 6, 7, 8])``. What is ``a + b``
+      show("Hello World")
+
+      if __name__ == "__main__":
 
-   a. set([1, 2, 3, 4, 5, 6, 7, 8])
-   #. set([6, 8, 10, 12])
-   #. set([5, 12, 21, 32])
-   #. Error
+          show("Hello Test")
+
+    How do you use the ``show`` function after doing ``from utils import show``
 
- 9. ``a`` is a set. how do you check if if a varaible ``b`` exists in ``a``?
+   a. utils.show("hey")
+   #. show("hey")
+   #. utils.py.show("hey")
+   #. utils.py.show.py("hey")
 
-   Answer: b in a
-
- 10. ``a`` and ``b`` are two sets. What is ``a ^ b == (a - b) | (b - a)``?
+   Answer: show("hey")
 
-   a. True
-   #. False
+ 5. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
+    the following code:
 
-   Answer: False
-
+      def show(x):
+          print x
 
-Larger Questions
-----------------
+      show("Hello World")
+
+      if __name__ == "__main__":
 
- 1. Given that mat_marks is a list of maths marks of a class. Find out the
-    no.of duplicates marks in the list.
+          show("Hello Test")
+
+    What is printed when you do ``import utils``
 
    Answer::
+      Hello World
 
-     unique_marks = set(mat_marks)
-     no_of_duplicates = len(mat_marks) - len(unique_marks)
+ 6. The script ``utils.py`` is in one of locations of PYTHONPATH and contains
+    the following code:
+
+      def show(x):
+          print x
 
- 2. Given that mat_marks is a list of maths marks of a class. Find how many
-    duplicates of each mark exist.
+      show("Hello World")
+
+      if __name__ == "__main__":
+
+          show("Hello Test")
+
+    What is printed when the script is executed.
 
    Answer::
+      Hello World
+      Hello Test
 
-     marks_set = set(mat_marks)
-     for mark in marks_set:
-         occurences = mat_marks.count(mark)
-         print occurences - 1, "duplicates of", mark, "exist"
-
--- a/writing_python_scripts/quickref.tex	Thu Oct 14 14:11:54 2010 +0530
+++ b/writing_python_scripts/quickref.tex	Mon Oct 18 21:11:34 2010 +0530
@@ -1,11 +1,9 @@
-Creating a tuple:\\
-{\ex \lstinline|    t = (1, "hello", 2.5)|}
-
-Accessing elements of tuples:\\
-{\ex \lstinline|    t[index] Ex: t[2]|}
+See where python searches for modules:\\
+{\ex \lstinline|    sys.path|}
 
-Accessing slices of tuples:\\
-{\ex \lstinline|    t[start:stop:step]|}
+Include our own path in PYTHONPATH:\\
+{\ex \lstinline|    sys.path.append(our_path)|}
 
-Swapping values:\\
-{\ex \lstinline|    a, b = b, a|}
+Run certian code only if executed and not if imported:\\
+{\ex \lstinline|    if __name__=="__main__": #do something|}
+
--- a/writing_python_scripts/script.rst	Thu Oct 14 14:11:54 2010 +0530
+++ b/writing_python_scripts/script.rst	Mon Oct 18 21:11:34 2010 +0530
@@ -1,8 +1,15 @@
 .. Objectives
 .. ----------
 
+.. By the end of this tutorial, you will be able to 
+
+..  * Understand what is importing
+..  * Write your own Python modules
+..  * Understand the ``__name__=="__main__"`` idiom
+
 .. Prerequisites
 .. -------------
+.. 1. Using Python modules
      
 .. Author              : Nishanth Amuluru
    Internal Reviewer   :