Python/C2/Using-sage-to-teach/Gujarati

From Script | Spoken-Tutorial
Revision as of 12:12, 28 October 2013 by Krupali (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Timing Narration
0:02 Hello friends and welcome to the tutorial on 'Using SAGE to teach'.
0:07 At the end of this tutorial, you will be able to,
  1. Use @interact feature of SAGE for better demonstration.
  2. Share, publish and edit SAGE worksheets for collaborative learning.
0:19 Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with Sage" and "Getting started with Symbolics."
0:30 Let us start by looking at a typical example of demonstrating a damped oscillation.
0:40 So you can type t=var('t') ,then next line you can type p1=plot (e raised to minus (-t)into sin of (2 into t),(t,0,15))
1:06 then third line you can type show(p1)
1:17 Now let us reduce the damping factor by half
1:23 so for that you have to type t=var('t')
1:33 then p1=plot(e raised to (-t by 2) * sin(2 into t),(t,0,15))
1:48 then third line you can type show(p1)
1:53 Now, if we want to reduce the damping factor even more, we would be using e charat to (-t by 3).
2:04 We can observe that every time we have to change, all we do is change something very small and re-evaluate the cell.
2:10 This process can be simplified, using the @interact feature of SAGE.
2:17 So you can type @interact ,then def plot_damped(n-1):
2:32 Then, t=var('t')
2:49 p1=plot (e raised to(-t/n) * sin(2*t),(t,0,20))
3:01 then type show(p1)
3:11 We can see that the function is evaluated and the plot is shown.
3:15 We can also see that there is a field to enter the value of n and it is currently set to 1 .
3:21 Let us change it to 2 and hit enter.
3:23 So you type 2 and hit enter.
3:29 We see that the new plot with reduced damping factor is shown.
3:33 Similarly we can change n to any desired value and hit enter and the function will be evaluated.
3:41 This is a very handy tool while demonstrating or teaching.
3:45 Pause the video here, try out the following exercise and resume the video.
3:50 'Plot the sine curve and vary its frequency using the @interact feature.
3:57 Now, switch to your worksheet for solution.
4:03 You can type @interact
4:08 then def sine_plot(n=1):
4:12 then x=var('x')
4:18 then p2=plot (sin(n*x),(x,0,2*pi))
4:27 then finally you can type show(p2)
4:43 So often we would want to vary a parameter over range instead of taking it as an input from the user.
4:51 For instance we would not want the user to give n as 0 for the damping oscillation we discussed.
4:56 In such cases we use a range of values as the default argument.
5:02 at the rate interact
5:10 should be typed in the worksheet so in the worksheet you can type
5:14 @interact then def plot underscore damped(n=(1..10)):
5:28 then next line you can type t=var('t')
5:36 then p1=plot(e raised to (-t/n) * sin(2*t)),(t,0,20))
5:52 then you can type show(p1)
6:08 Now we had seen an error
6:12 So the error that we have rectified is after sin(2*t) we have accidentally placed an extra bracket.
6:25 So we get similar plot but the only difference is the input widget.
6:30 Here it is a slider unlike an input field.
6:35 We can see that the slider is moved, the function is evaluated and plotted accordingly.
6:48 Pause the video here,and try out the following exercise and resume the video.
6:52 Take a string as input from user and circular shift it to the left and vary the shift length using a slider.
7:03 For this problem, again we will use the @interact feature of sage.
7:09 We shall first assign a string say 'MADAM' to a variable and then shift the alphabets one by one.
7:17 So we can type @interact
7:21 def str_shift(s="MADAM", shift=(0..8)) colon
7:33 then you can type shift_len=shift modulus len(s)
7:40 then chars=list(s)
7:46 then shifted_chars=chars[shift_len:]+chars[: shift_len]
8:03 then print "Actual String:",s
8:11 then print "Shifted String:", "".join(shifted_chars)
8:28 As we move the slider, we see that shifting is taking place.
8:40 Sometimes we want the user to have only a given set of options.
8:44 We use a list of items as the default argument in such situations.
8:50 So we can type @interact
8:57 then def str_shift(s="STRING",shift=(0..8), direction=["Left","Right"]):
9:10 then next line shift_len=shift modulus len(s)
9:24 then chars=list(s)
9:26 if direction=="Right" colon
9:32 then shifted_chars=chars[-shift_len colon]+chars[colon -shift_len]
10:01 else colon shifted_chars=chars[shift_len colon]+chars[colon shift_len]
10:26 then type print "Actual String:",s
10:32 then print "Shifted String:", ""
10:52 then dot join(shifted_chars)
11:01 We can see that buttons are displayed which enables us to select from a given set of options.
11:11 We see that, as we select left or right button, the shifting takes place appropriately.
11:18 Thus, we have learnt how to use the @interact feature of SAGE for better demonstration.
11:24 Now we shall look at how to use SAGE worksheets for collaborative learning.
11:30 The first feature we shall see is the publish feature.
11:34 Open a worksheet and in the top right, we can see a button called publish
11:40 Click on that and we get a confirmation page with an option for re-publishing.
11:52 For now lets forget that option and simply publish by clicking yes .
11:58 The worksheet is now published.
11:59 Now lets sign out and go to the sage notebook home.
12:04 We see link to browse published worksheets.
12:08 Lets click on it and we can see the worksheet.
12:12 This does not require login and anyone can view the worksheet.
12:17 Alternatively, if one wants to edit the sheet, there is a link on top left corner that enables the user to download a copy of the sheet onto their home.
12:36 This way they can edit a copy of the worksheet.
12:41 We have learnt how to publish the worksheets to enable users to edit a copy.
12:45 Next, we shall look at how to enable users to edit the actual worksheet itself.
12:51 Let us open the worksheet and we see a link called share on the top right corner of the worksheet.
13:03 Click the link and we get a box where we can type the usernames of users whom we want to share the worksheet with.
13:10 We can even specify multiple users by separating their names using commas.
13:15 Once we have shared the worksheet, the worksheet appears on the home of shared users.
13:22 This brings us to the end of this tutorial.
13:24 In this tutorial, we have learnt to,
13:25 Use interactive features of SAGE using @interact .
13:30 then publishing our work.
13:32 then edit a copy of one of the published worksheets.
13:35 then share the worksheets with fellow users.
13:39 Here are some self assessment questions for you to solve
13:44 1. Which default argument, when used with @interact gives a slider starting at 0 and ending in 10.
13:52 options are (0..11)
13:54 then range(0, 11)
13:55 Then [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] separated by comma
14:01 then in brackets (0..10)
14:05 2. What is the input widget resulted by using n = [2, 4, 5, 9]\ in the default arguments along with @interact.
14:23 options are input field, set of buttons, slider, None
14:29 Now we will look at the answers,
14:31 1.The default argument, used with @interact which gives a slider starting at 0 and ending in 10 is (0..10).
14:42 2. The input widget resulted by using n = [2, 4, 5, 9] in the default arguments along with @interact will be a set of buttons that is the second one.


14:57 Hope you have enjoyed this tutorial and found it useful.
15:01 Thank you!

Contributors and Content Editors

Krupali