using_sage_to_teach/script.rst
changeset 256 a3aa223c1662
child 334 4b1e81da1c80
equal deleted inserted replaced
255:75fd106303dc 256:a3aa223c1662
       
     1 .. Objectives
       
     2 .. ----------
       
     3 
       
     4 .. A - Students and teachers from Science and engineering backgrounds
       
     5    B - 
       
     6    C - 
       
     7    D - 
       
     8 
       
     9 .. Prerequisites
       
    10 .. -------------
       
    11 
       
    12 ..   1. Getting started with lists
       
    13      
       
    14 .. Author              : Nishanth Amuluru
       
    15    Internal Reviewer   : 
       
    16    External Reviewer   :
       
    17    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
       
    18 
       
    19 Script
       
    20 ------
       
    21 
       
    22 Hello friends and welcome to the tutorial on "Using SAGE to teach"
       
    23 
       
    24 {{{ Show the slide containing title }}}
       
    25 
       
    26 {{{ Show the slide containing the outline slide }}}
       
    27 
       
    28 In this tutorial, we shall learn
       
    29 
       
    30  * How to use the "@interact" feature of SAGE for better demonstration
       
    31  * How to use SAGE for collaborative learning
       
    32 
       
    33 Let us look at a typical example of demonstrating a damped oscillation.
       
    34 ::
       
    35 
       
    36     t = var('t')
       
    37     p1 = plot( e^(-t) * sin(2*t), (t, 0, 15))
       
    38     show(p1)
       
    39 
       
    40 Now let us reduce the damping factor
       
    41 ::
       
    42 
       
    43     t = var('t')
       
    44     p1 = plot( e^(-t/2) * sin(2*t), (t, 0, 15))
       
    45     show(p1)
       
    46 
       
    47 Now if we want to reduce the damping factor even more, we would be using
       
    48 e^(-t/3). We can observe that every time we have to change, all we do is change
       
    49 something very small and re evaluate the cell.
       
    50 
       
    51 This process can be automated using the ``@interact`` feature of SAGE.
       
    52 
       
    53 ::
       
    54 
       
    55     @interact
       
    56     def plot_damped(n=1):
       
    57         t = var('t')
       
    58         p1 = plot( e^(-t/n) * sin(2*t), (t, 0, 20))
       
    59         show(p1)
       
    60 
       
    61 We can see that the function is evaluated and the plot is shown. We can also
       
    62 see that there is a field to enter the value of ``n`` and it is currently set
       
    63 to ``1``. Let us change it to 2 and hit enter.
       
    64 
       
    65 We see that the new plot with reduced damping factor is shown. Similarly we can
       
    66 change ``n`` to any desired value and hit enter and the function will be
       
    67 evaluated. 
       
    68 
       
    69 This is a very handy tool while demonstrating or teaching.
       
    70 
       
    71 {{{ Pause here and try out the following exercises }}}
       
    72 
       
    73 %% 1 %% Plot the sine curve and vary its frequency using the ``@interact``
       
    74 
       
    75 {{{ continue from paused state }}}
       
    76 
       
    77 ::
       
    78 
       
    79     @interact
       
    80     def sine_plot(n=1):
       
    81         x = var('x')
       
    82         p2 = plot(sin(n*x), (x, 0, 2*pi))
       
    83         show(p2)
       
    84 
       
    85 Often we would want to vary a parameter over range instead of taking it as an
       
    86 input from the user. For instance we do not want the user to give ``n`` as 0
       
    87 for the damping oscillation we discussed. In such cases we use a range of
       
    88 values as the default argument.
       
    89 ::
       
    90 
       
    91     @interact
       
    92     def plot_damped(n=(1..10)):
       
    93         t = var('t')
       
    94         p1 = plot( e^(-t/n) * sin(2*t), (t, 0, 20))
       
    95         show(p1)
       
    96 
       
    97 We get similar plot but the only difference is the input widget. Here it is a
       
    98 slider unlike an input field. We can see that as the slider is moved, the
       
    99 function is evaluated and plotted accordingly.
       
   100 
       
   101 {{{ Pause here and try out the following exercises }}}
       
   102 
       
   103 %% 2 %% Take a string as input from user and circular shift it to the left and
       
   104         vary the shift length using a slider
       
   105 
       
   106 {{{ continue from paused state }}}
       
   107 
       
   108 ::
       
   109 
       
   110     @interact
       
   111     def str_shift(s="MADAM", shift=(0..8)):
       
   112         shift_len = shift % len(s)
       
   113         chars = list(s)
       
   114         shifted_chars = chars[shift_len:] + chars[:shift_len]
       
   115         print "Actual String:", s
       
   116         print "Shifted String:", "".join(shifted_chars)
       
   117 
       
   118 Sometimes we want the user to have only a given set of options. We use a list
       
   119 of items as the default argument in such situations.
       
   120 ::
       
   121 
       
   122     @interact
       
   123     def str_shift(s="STRING", shift=(0..8), direction=["Left", "Right"]):
       
   124         shift_len = shift % len(s)
       
   125         chars = list(s)
       
   126         if direction == "Right":
       
   127             shifted_chars = chars[-shift_len:] + chars[:-shift_len]
       
   128         else:
       
   129             shifted_chars = chars[shift_len:] + chars[:shift_len]
       
   130         print "Actual String:", s
       
   131         print "Shifted String:", "".join(shifted_chars)
       
   132 
       
   133 We can see that buttons are displayed which enables us to select from a given
       
   134 set of options.
       
   135 
       
   136 We have learnt how to use the ``@interact`` feature of SAGE for better
       
   137 demonstration. We shall look at how to use SAGE worksheets for collaborative
       
   138 learning.
       
   139 
       
   140 The first feature we shall see is the ``publish`` feature. Open a worksheet and
       
   141 in the top right, we can see a button called ``publish``. Click on that and we
       
   142 get a confirmation page with an option for re publishing.
       
   143 
       
   144 For now lets forget that opion and simply publish by cliking ``yes``. The
       
   145 worksheet is now published. 
       
   146 
       
   147 Now lets signout and go to the sage notebook home. We see link to browse
       
   148 published worksheets. Lets click on it and we can see the worksheet. This does
       
   149 not require login and anyone can view the worksheet.
       
   150 
       
   151 Alternatively, if one wants to edit the sheet, there is a link on top left
       
   152 corner that enables the user to download a copy of the sheet onto their home.
       
   153 This way they can edit a copy of the worksheet.
       
   154 
       
   155 We have learnt how to publish the worksheets to enable users to edit a copy.
       
   156 Next, we shall look at how to enable users to edit the actual worksheet itself.
       
   157 
       
   158 Let us open the worksheet and we see a link called ``share`` on the top right
       
   159 corner of the worksheet. Click the link and we get a box where we can type the
       
   160 usernames of users whom we want to share the worksheet with. We can even
       
   161 specify multiple users by seperating their names using commas. Once we have
       
   162 shared the worksheet, the worksheet appears on the home of shared users.
       
   163 
       
   164 {{{ Show summary slide }}}
       
   165 
       
   166 This brings us to the end of the tutorial.
       
   167 we have learnt
       
   168 
       
   169  * How to user interactive feaures of SAGE
       
   170  * How to publish our work
       
   171  * How to edit a copy of one of the published worksheets
       
   172  * How to share the worksheets with fellow users
       
   173 
       
   174 {{{ Show the "sponsored by FOSSEE" slide }}}
       
   175 
       
   176 #[Nishanth]: Will add this line after all of us fix on one.
       
   177 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
       
   178 
       
   179 Hope you have enjoyed and found it useful.
       
   180 Thankyou
       
   181