Python/C2/Using-sage-to-teach/English-timed
From Script | Spoken-Tutorial
Time | Narration |
00:02 | Hello friends and welcome to the tutorial on 'Using SAGE to teach'. |
00:07 | At the end of this tutorial, you will be able to,
Use @interact feature of SAGE for better demonstration. Share, publish and edit SAGE worksheets for collaborative learning. |
00:19 | Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with Sage" and "Getting started with Symbolics." |
00:30 | Let us start by looking at a typical example of demonstrating a damped oscillation. |
00: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)) |
01:06 | then third line you can type show(p1) |
01:17 | Now let us reduce the damping factor by half |
01:23 | so for that you have to type t=var('t') |
01:33 | then p1=plot(e raised to (-t by 2) * sin(2 into t),(t,0,15)) |
01:48 | then third line you can type show(p1) |
01:53 | Now, if we want to reduce the damping factor even more, we would be using e charat to (-t by 3). |
02:04 | We can observe that every time we have to change, all we do is change something very small and re-evaluate the cell. |
02:10 | This process can be simplified, using the @interact feature of SAGE. |
02:17 | So you can type @interact ,then def plot_damped(n-1): |
02:32 | Then, t=var('t') |
02:49 | p1=plot (e raised to(-t/n) * sin(2*t),(t,0,20)) |
03:01 | then type show(p1) |
03:11 | We can see that the function is evaluated and the plot is shown. |
03:15 | We can also see that there is a field to enter the value of n and it is currently set to 1 . |
03:21 | Let us change it to 2 and hit enter. |
03:23 | So you type 2 and hit enter. |
03:29 | We see that the new plot with reduced damping factor is shown. |
03:33 | Similarly we can change n to any desired value and hit enter and the function will be evaluated. |
03:41 | This is a very handy tool while demonstrating or teaching. |
03:45 | Pause the video here, try out the following exercise and resume the video. |
03:50 | 'Plot the sine curve and vary its frequency using the @interact feature. |
03:57 | Now, switch to your worksheet for solution. |
04:03 | You can type @interact |
04:08 | then def sine_plot(n=1): |
04:12 | then x=var('x') |
04:18 | then p2=plot (sin(n*x),(x,0,2*pi)) |
04:27 | then finally you can type show(p2) |
04:43 | So often we would want to vary a parameter over range instead of taking it as an input from the user. |
04:51 | For instance we would not want the user to give n as 0 for the damping oscillation we discussed. |
04:56 | In such cases we use a range of values as the default argument. |
05:02 | at the rate interact |
05:10 | should be typed in the worksheet so in the worksheet you can type |
05:14 | @interact then def plot underscore damped(n=(1..10)): |
05:28 | then next line you can type t=var('t') |
05:36 | then p1=plot(e raised to (-t/n) * sin(2*t)),(t,0,20)) |
05:52 | then you can type show(p1) |
06:08 | Now we had seen an error |
06:12 | So the error that we have rectified is after sin(2*t) we have accidentally placed an extra bracket. |
06:25 | So we get similar plot but the only difference is the input widget. |
06:30 | Here it is a slider unlike an input field. |
06:35 | We can see that the slider is moved, the function is evaluated and plotted accordingly. |
06:48 | Pause the video here,and try out the following exercise and resume the video. |
06:52 | Take a string as input from user and circular shift it to the left and vary the shift length using a slider. |
07:03 | For this problem, again we will use the @interact feature of sage. |
07:09 | We shall first assign a string say 'MADAM' to a variable and then shift the alphabets one by one. |
07:17 | So we can type @interact |
07:21 | def str_shift(s="MADAM", shift=(0..8)) colon |
07:33 | then you can type shift_len=shift modulus len(s) |
07:40 | then chars=list(s) |
07:46 | then shifted_chars=chars[shift_len:]+chars[: shift_len] |
08:03 | then print "Actual String:",s |
08:11 | then print "Shifted String:", "".join(shifted_chars) |
08:28 | As we move the slider, we see that shifting is taking place. |
08:40 | Sometimes we want the user to have only a given set of options. |
08:44 | We use a list of items as the default argument in such situations. |
08:50 | So we can type @interact |
08:57 | then def str_shift(s="STRING",shift=(0..8), direction=["Left","Right"]): |
09:10 | then next line shift_len=shift modulus len(s) |
09:24 | then chars=list(s) |
09:26 | if direction=="Right" colon |
09: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. 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, 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 | 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), Then [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] separated by comma |
14:01 | then in brackets (0..10) |
14:05 | 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 | The default argument, used with @interact which gives a slider starting at 0 and ending in 10 is (0..10). |
14:42 | 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! |