Difference between revisions of "Python/C2/Using-Sage/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
Line 1: Line 1:
 
{| border=1
 
{| border=1
!Timing
+
|'''Time'''
!Narration
+
|'''Narration'''
 +
 
 
|-
 
|-
| 0:00
+
| 00:00
 
| Welcome to the tutorial on 'Using Sage'.
 
| Welcome to the tutorial on 'Using Sage'.
  
 
|-
 
|-
| 0:02
+
| 00:02
 
| At the end of this tutorial, you will be able to,
 
| At the end of this tutorial, you will be able to,
  
Line 15: Line 16:
  
 
|-
 
|-
|0:16
+
|00:16
 
| Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with Sage".
 
| Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with Sage".
  
 
|-
 
|-
|0:22
+
|00:22
 
|Let us begin with Calculus.  
 
|Let us begin with Calculus.  
  
 
|-
 
|-
|0:24
+
|00:24
 
|We shall be looking at limits, differentiation, integration, and Taylor polynomial.
 
|We shall be looking at limits, differentiation, integration, and Taylor polynomial.
  
 
|-
 
|-
| 0:30
+
| 00:30
 
| We have our Sage notebook running.
 
| We have our Sage notebook running.
  
 
|-
 
|-
|0:32
+
|00:32
 
| In case, you don't have it running, start is using the command,sage --notebook
 
| In case, you don't have it running, start is using the command,sage --notebook
  
 
|-
 
|-
|0:39
+
|00:39
 
|So type sage and specify notebook.
 
|So type sage and specify notebook.
  
 
|-
 
|-
0:45
+
00:45
 
|So to find the limit of the function x into sin(1/x), at x=0, we say by typing it lim(x*sin(1/x),x=0)
 
|So to find the limit of the function x into sin(1/x), at x=0, we say by typing it lim(x*sin(1/x),x=0)
  
 
|-
 
|-
|1:07
+
|01:07
 
| We get the limit to be 0, as expected.
 
| We get the limit to be 0, as expected.
  
 
|-
 
|-
|1:11
+
|01:11
 
|It is also possible to limit a point from one direction. For example, let us find the limit of 1/x at x=0, when approaching from the positive side.
 
|It is also possible to limit a point from one direction. For example, let us find the limit of 1/x at x=0, when approaching from the positive side.
  
 
|-
 
|-
|1:23
+
|01:23
 
|lim within brackets (1/x, x=0, dir='right')
 
|lim within brackets (1/x, x=0, dir='right')
  
  
 
|-
 
|-
1:32
+
01:32
 
| To find the limit from the negative side, we say,
 
| To find the limit from the negative side, we say,
  
 
|-
 
|-
|1:36
+
|01:36
 
|lim(1/x, x=0, dir='left')  
 
|lim(1/x, x=0, dir='left')  
  
 
|-
 
|-
| 1:45
+
| 01:45
 
| Let us see how to perform differentiation, using Sage.
 
| Let us see how to perform differentiation, using Sage.
  
 
|-
 
|-
|1:51
+
|01:51
 
| We shall find the differential of the expression exp of (sin(x squared)) by x with respect to x.
 
| We shall find the differential of the expression exp of (sin(x squared)) by x with respect to x.
  
 
|-
 
|-
|2:11
+
|02:11
 
| For this, we shall first define the expression, and then use the diff function to obtain the differential of the expression.
 
| For this, we shall first define the expression, and then use the diff function to obtain the differential of the expression.
  
 
|-
 
|-
|2:21
+
|02:21
 
|So we can type var('x)
 
|So we can type var('x)
 
  f=exp of (sin x squared)/x and then third line you can type
 
  f=exp of (sin x squared)/x and then third line you can type
Line 82: Line 83:
  
 
|-
 
|-
2:44
+
02:44
 
| We can also obtain the partial differentiation of an expression w.r.t one of the variables.
 
| We can also obtain the partial differentiation of an expression w.r.t one of the variables.
  
 
|-
 
|-
|2:51
+
|02:51
 
| Let us differentiate the expression exp(sin (y - x squared))/x w.r.t x and y.
 
| Let us differentiate the expression exp(sin (y - x squared))/x w.r.t x and y.
  
 
|-
 
|-
|3:07
+
|03:07
 
|that is with respect to x and y.
 
|that is with respect to x and y.
  
 
|-
 
|-
|3:10
+
|03:10
 
|so you can type var('x y')
 
|so you can type var('x y')
  
 
|-
 
|-
|3:15
+
|03:15
 
|second line you can type f=exp(sin(y - x squared))by x
 
|second line you can type f=exp(sin(y - x squared))by x
  
 
|-
 
|-
|3:26
+
|03:26
 
|then you can type diff(f,x) then next line you can type diff(f,y)
 
|then you can type diff(f,x) then next line you can type diff(f,y)
  
 
|-
 
|-
3:43
+
03:43
 
| Thus we get our partial differential solution.  
 
| Thus we get our partial differential solution.  
  
 
|-
 
|-
|3:51
+
|03:51
 
|Now, let us look at integration.
 
|Now, let us look at integration.
  
 
|-
 
|-
|3:53
+
|03:53
 
| We shall use the expression obtained from the differentiation that we did before, diff(f, y)which gave us the expression ---e^(sin(-x squared + y)) multiplied by cos(-x squared plus y) by x
 
| We shall use the expression obtained from the differentiation that we did before, diff(f, y)which gave us the expression ---e^(sin(-x squared + y)) multiplied by cos(-x squared plus y) by x
  
 
|-
 
|-
|4:15
+
|04:15
 
| The integrate command is used to obtain the integral of an expression or function.
 
| The integrate command is used to obtain the integral of an expression or function.
  
 
|-
 
|-
|4:21
+
|04:21
 
|So you can type integrate(e^(sin(-x squared plus y))multiplied by cos(-x squared +y)by x,y)
 
|So you can type integrate(e^(sin(-x squared plus y))multiplied by cos(-x squared +y)by x,y)
  
 
|-
 
|-
4:39
+
04:39
 
| As we can see,we get back the correct expression.
 
| As we can see,we get back the correct expression.
  
 
|-
 
|-
|4:44
+
|04:44
 
| The minus sign being inside or outside the sin function doesn't change much.
 
| The minus sign being inside or outside the sin function doesn't change much.
  
 
|-
 
|-
|4:48
+
|04:48
 
|Now, let us find the value of the integral between the limits 0 and pi/2.
 
|Now, let us find the value of the integral between the limits 0 and pi/2.
  
 
|-
 
|-
|4:55
+
|04:55
 
|So for that you can type integral(e^(sin(-x squared plus y))multiplied by cos(-x squared plus y) by x,y,0,pi/2)
 
|So for that you can type integral(e^(sin(-x squared plus y))multiplied by cos(-x squared plus y) by x,y,0,pi/2)
  
 
|-
 
|-
5:11
+
05:11
 
| Hence we got our solution for definite integration.  
 
| Hence we got our solution for definite integration.  
  
 
|-
 
|-
|5:15
+
|05:15
 
|Now, let us see how to obtain the Taylor expansion of an expression using sage.  
 
|Now, let us see how to obtain the Taylor expansion of an expression using sage.  
  
 
|-
 
|-
|5:20
+
|05:20
 
|Let us obtain the Taylor expansion of (x + 1) raised to n up to degree 4 about 0.
 
|Let us obtain the Taylor expansion of (x + 1) raised to n up to degree 4 about 0.
  
 
|-
 
|-
|5:27
+
|05:27
 
|So for that you can type var of ('x n') then type taylor within brackets((x+1) raised to n,x,0,4)
 
|So for that you can type var of ('x n') then type taylor within brackets((x+1) raised to n,x,0,4)
  
 
|-
 
|-
| 5:42
+
| 05:42
 
| We easily got the Taylor expansion,using the taylor function taylor() function.
 
| We easily got the Taylor expansion,using the taylor function taylor() function.
  
 
|-
 
|-
| 5:49
+
| 05:49
 
| So this brings us to the end of the features of Sage for Calculus, that we will be looking at.
 
| So this brings us to the end of the features of Sage for Calculus, that we will be looking at.
  
 
|-
 
|-
|5:56
+
|05:56
 
| For more, look at the Calculus quick-ref from the Sage Wiki.
 
| For more, look at the Calculus quick-ref from the Sage Wiki.
  
 
|-
 
|-
| 6:03
+
| 06:03
 
| Next let us move on to Matrix Algebra.
 
| Next let us move on to Matrix Algebra.
  
 
|-
 
|-
|6:07
+
|06:07
 
| Let us begin with solving the equation Ax = v, where A is the matrix matrix ([[1,2], [3,4]]) and v is the vector vector ([1,2]).
 
| Let us begin with solving the equation Ax = v, where A is the matrix matrix ([[1,2], [3,4]]) and v is the vector vector ([1,2]).
  
 
|-
 
|-
| 6:19
+
| 06:19
 
| So, to solve the equation,Ax = v we simply say
 
| So, to solve the equation,Ax = v we simply say
  
 
|-
 
|-
|6:23
+
|06:23
 
|A=matrix ([1,2] comma [3,4]) then v is equal to vector([1,2])   
 
|A=matrix ([1,2] comma [3,4]) then v is equal to vector([1,2])   
  
 
|-
 
|-
|6:35
+
|06:35
 
|then x=A dot solve underscore right(v)
 
|then x=A dot solve underscore right(v)
  
 
|-
 
|-
|6:50
+
|06:50
 
|then you have to type
 
|then you have to type
  
 
|-
 
|-
|7:01
+
|07:01
 
|then type x
 
|then type x
  
 
|-
 
|-
| 7:07
+
| 07:07
 
| To solve an equation, xA = v we simply say
 
| To solve an equation, xA = v we simply say
  
 
|-
 
|-
|7:14
+
|07:14
 
|x=A dot solve underscore left(v)
 
|x=A dot solve underscore left(v)
  
 
|-
 
|-
|7:25
+
|07:25
 
|then type x
 
|then type x
  
 
|-
 
|-
7:32
+
07:32
 
| The left and right here, denote the position of A, relative to x.
 
| The left and right here, denote the position of A, relative to x.
  
 
|-
 
|-
|7:36
+
|07:36
 
|Now, let us look at Graph Theory in Sage.
 
|Now, let us look at Graph Theory in Sage.
  
 
|-
 
|-
|7:39
+
|07:39
 
|We shall look at some ways to create graphs and some of the graph families available in Sage.
 
|We shall look at some ways to create graphs and some of the graph families available in Sage.
  
 
|-
 
|-
|7:45
+
|07:45
 
|The simplest way to define an arbitrary graph is to use a dictionary of lists.
 
|The simplest way to define an arbitrary graph is to use a dictionary of lists.
  
 
|-
 
|-
|7:49
+
|07:49
 
| We create a simple graph by using the Graph() function.
 
| We create a simple graph by using the Graph() function.
  
 
|-
 
|-
|7:53
+
|07:53
 
|So G=Graph({0:[1,2,3], 2:[4]}) and hit shift enter
 
|So G=Graph({0:[1,2,3], 2:[4]}) and hit shift enter
  
 
|-
 
|-
| 8:13
+
| 08:13
 
| To view the visualization of the graph, we say
 
| To view the visualization of the graph, we say
  
 
|-
 
|-
|8:17
+
|08:17
 
|G.show()
 
|G.show()
  
 
|-
 
|-
| 8:24
+
| 08:24
 
| Similarly, we can obtain a directed graph using the DiGraph function.
 
| Similarly, we can obtain a directed graph using the DiGraph function.
  
 
|-
 
|-
| 8:31
+
| 08:31
 
| So ,you have to type G=DiGraph that is D and G are capital ({0 colon [1,2,3],2 colon[4]}) and hit shift enter.
 
| So ,you have to type G=DiGraph that is D and G are capital ({0 colon [1,2,3],2 colon[4]}) and hit shift enter.
  
 
|-
 
|-
8:59
+
08:59
 
| Sage also provides a lot of graph families which can be viewed by typing graph.tab.
 
| Sage also provides a lot of graph families which can be viewed by typing graph.tab.
  
 
|-
 
|-
| 9:04
+
| 09:04
 
| Let us obtain a complete graph with 5 vertices and then show the graph.
 
| Let us obtain a complete graph with 5 vertices and then show the graph.
  
 
|-
 
|-
| 9:09
+
| 09:09
 
| So you can type there G=graphs dot Complete Graph(5) then type G dot show()
 
| So you can type there G=graphs dot Complete Graph(5) then type G dot show()
  
 
|-
 
|-
9:28
+
09:28
 
| Sage provides other functions for Number theory and Combinatorics.  
 
| Sage provides other functions for Number theory and Combinatorics.  
  
 
|-
 
|-
|9:35
+
|09:35
 
|Let's have a glimpse of a few of them.
 
|Let's have a glimpse of a few of them.
  
 
|-
 
|-
|9:42
+
|09:42
 
| So prime_range gives primes in the range 100 to 200.
 
| So prime_range gives primes in the range 100 to 200.
  
 
|-
 
|-
|9:46
+
|09:46
 
|So you can type there prime_range within brackets 100,200.
 
|So you can type there prime_range within brackets 100,200.
  
 
|-
 
|-
| 9:58
+
| 09:58
 
| is_prime checks if 1999 is a prime number or not.
 
| is_prime checks if 1999 is a prime number or not.
  

Revision as of 12:49, 10 July 2014

Time Narration
00:00 Welcome to the tutorial on 'Using Sage'.
00:02 At the end of this tutorial, you will be able to,
  1. Learn the range of things for which Sage can be used.
  2. Know the functions used for Calculus in Sage.
  3. Learn about graph theory and number theory using Sage.
00:16 Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with Sage".
00:22 Let us begin with Calculus.
00:24 We shall be looking at limits, differentiation, integration, and Taylor polynomial.
00:30 We have our Sage notebook running.
00:32 In case, you don't have it running, start is using the command,sage --notebook
00:39 So type sage and specify notebook.
00:45 So to find the limit of the function x into sin(1/x), at x=0, we say by typing it lim(x*sin(1/x),x=0)
01:07 We get the limit to be 0, as expected.
01:11 It is also possible to limit a point from one direction. For example, let us find the limit of 1/x at x=0, when approaching from the positive side.
01:23 lim within brackets (1/x, x=0, dir='right')


01:32 To find the limit from the negative side, we say,
01:36 lim(1/x, x=0, dir='left')
01:45 Let us see how to perform differentiation, using Sage.
01:51 We shall find the differential of the expression exp of (sin(x squared)) by x with respect to x.
02:11 For this, we shall first define the expression, and then use the diff function to obtain the differential of the expression.
02:21 So we can type var('x)
f=exp of (sin x squared)/x and then third line you can type
diff(f,x)
02:44 We can also obtain the partial differentiation of an expression w.r.t one of the variables.
02:51 Let us differentiate the expression exp(sin (y - x squared))/x w.r.t x and y.
03:07 that is with respect to x and y.
03:10 so you can type var('x y')
03:15 second line you can type f=exp(sin(y - x squared))by x
03:26 then you can type diff(f,x) then next line you can type diff(f,y)
03:43 Thus we get our partial differential solution.
03:51 Now, let us look at integration.
03:53 We shall use the expression obtained from the differentiation that we did before, diff(f, y)which gave us the expression ---e^(sin(-x squared + y)) multiplied by cos(-x squared plus y) by x
04:15 The integrate command is used to obtain the integral of an expression or function.
04:21 So you can type integrate(e^(sin(-x squared plus y))multiplied by cos(-x squared +y)by x,y)
04:39 As we can see,we get back the correct expression.
04:44 The minus sign being inside or outside the sin function doesn't change much.
04:48 Now, let us find the value of the integral between the limits 0 and pi/2.
04:55 So for that you can type integral(e^(sin(-x squared plus y))multiplied by cos(-x squared plus y) by x,y,0,pi/2)
05:11 Hence we got our solution for definite integration.
05:15 Now, let us see how to obtain the Taylor expansion of an expression using sage.
05:20 Let us obtain the Taylor expansion of (x + 1) raised to n up to degree 4 about 0.
05:27 So for that you can type var of ('x n') then type taylor within brackets((x+1) raised to n,x,0,4)
05:42 We easily got the Taylor expansion,using the taylor function taylor() function.
05:49 So this brings us to the end of the features of Sage for Calculus, that we will be looking at.
05:56 For more, look at the Calculus quick-ref from the Sage Wiki.
06:03 Next let us move on to Matrix Algebra.
06:07 Let us begin with solving the equation Ax = v, where A is the matrix matrix ([[1,2], [3,4]]) and v is the vector vector ([1,2]).
06:19 So, to solve the equation,Ax = v we simply say
06:23 A=matrix ([1,2] comma [3,4]) then v is equal to vector([1,2])
06:35 then x=A dot solve underscore right(v)
06:50 then you have to type
07:01 then type x
07:07 To solve an equation, xA = v we simply say
07:14 x=A dot solve underscore left(v)
07:25 then type x
07:32 The left and right here, denote the position of A, relative to x.
07:36 Now, let us look at Graph Theory in Sage.
07:39 We shall look at some ways to create graphs and some of the graph families available in Sage.
07:45 The simplest way to define an arbitrary graph is to use a dictionary of lists.
07:49 We create a simple graph by using the Graph() function.
07:53 So G=Graph({0:[1,2,3], 2:[4]}) and hit shift enter
08:13 To view the visualization of the graph, we say
08:17 G.show()
08:24 Similarly, we can obtain a directed graph using the DiGraph function.
08:31 So ,you have to type G=DiGraph that is D and G are capital ({0 colon [1,2,3],2 colon[4]}) and hit shift enter.
08:59 Sage also provides a lot of graph families which can be viewed by typing graph.tab.
09:04 Let us obtain a complete graph with 5 vertices and then show the graph.
09:09 So you can type there G=graphs dot Complete Graph(5) then type G dot show()
09:28 Sage provides other functions for Number theory and Combinatorics.
09:35 Let's have a glimpse of a few of them.
09:42 So prime_range gives primes in the range 100 to 200.
09:46 So you can type there prime_range within brackets 100,200.
09:58 is_prime checks if 1999 is a prime number or not.
10:05 So for that you can type if_prime of (1999) and hit shift enter.
10:13 So you will get the answer.
10:15 factor(2001) gives the factorized form of 2001.
10:20 So to see that you can type factor(2001) and hit shift enter.
10:33 So you can see the value in the output.
10:36 So the Permutations() gives the permutations of [1, 2, 3, 4]
10:43 So for that you can type C=Permutations([1,2,3,4]) and next you can type C.list()
10:57 And the Combinations() gives all the combinations of [1, 2, 3, 4]
11:02 For that you can type C= Combinations([1,2,3,4]) and type C dot list()
11:17 So now you can see the solution displayed
11:26 This brings us to the end of the tutorial.
11:29 So In this tutorial, we have learnt to,
11:32 1. Use functions for calculus like -- - lim()-- to find out the limit of a function - diff()-- to find out the differentiation of an expression - integrate()-- to integrate over an expression - integral()-- to find out the definite integral of an expression by specifying the limits br
11:52 solve()-- to solve a function, relative to it's position.
11:56 then create both a simple graph and a directed graph, using the functions graph and digraph respectively.
12:02 then use functions for number theory.
12:04 So for eg: - primes_range()-- function to find out the prime numbers within the specified range.
12:11 then factor()-- function to find out the factorized form of the specified number.
12:15 Permutations(), Combinations()-- to obtain the required permutation and combinations for the given set of values.
12:22 So here are some self assessment questions for you to solve
12:25 1. How do you find the limit of the function x/sin(x) as x tends to 0 from the negative side.
12:32 2. List all the primes between 2009 and 2900
12:37 3. Solve the system of linear equations x-2y+3z = 7 2x+3y-z = 5 x+2y+4z = 9
12:57 So now we can look at the answers,
13:02 1. To find out the limit of an expression from the negative side,we add an argument dir="left" as
13:09 lim of(x/sin(x), x=0, dir="left")
13:19 2. The prime numbers from 2009 and 2900 can be obtained as,
prime_range(2009, 2901)
13:32 3. We shall first write the equations in matrix form and then use the solve() function
13:39 So you can type A = Matrix of within brackets([[1, -2, 3] comma [2, 3, -1] comma [1, 2, 4]])
13:48 b = vector within brackets([7, 5, 9])
13:52 then x = A dot solve_right(b)
13:58 Then type x so that you can view the output of x.
14:03 So we hope that you have enjoyed this tutorial and found it useful.
14:06 Thank you!

Contributors and Content Editors

Gaurav, Minal, PoojaMoolya, Sneha