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