Learn the range of things for which Sage can be used. Know the functions used for Calculus in Sage. Learn about graph theory and number theory using Sage.

3 00:00:16 --> 00:00:21 Before beginning this tutorial,we would suggest you to complete the tutorial on "Getting started with Sage". 4 00:00:22 --> 00:00:23 Let us begin with Calculus. 5 00:00:24 --> 00:00:29 We shall be looking at limits, differentiation, integration, and Taylor polynomial. 6 00:00:30 --> 00:00:31 We have our Sage notebook running. 7 00:00:32 --> 00:00:38 In case, you don't have it running, start is using the command,sage --notebook 8 00:00:39 --> 00:00:44 So type sage and specify notebook. 9 00:00:45 --> 00:01:06 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) 10 00:01:07 --> 00:01:10 We get the limit to be 0, as expected. 11 00:01:11 --> 00:01:22 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. 12 00:01:23 --> 00:01:31 lim within brackets (1/x, x=0, dir='right') 13 00:01:32 --> 00:01:35 To find the limit from the negative side, we say, 14 00:01:36 --> 00:01:44 lim(1/x, x=0, dir='left') 15 00:01:45 --> 00:01:50 Let us see how to perform differentiation, using Sage. 16 00:01:51 --> 00:02:10 We shall find the differential of the expression exp of (sin(x squared)) by x with respect to x. 17 00:02:11 --> 00:02:20 For this, we shall first define the expression, and then use the diff function to obtain the differential of the expression. 18 00:02:21 --> 00:02:43 So we can type var('x) f=exp of (sin x squared)/x and then third line you can type diff(f,x) 19 00:02:44 --> 00:02:50 We can also obtain the partial differentiation of an expression w.r.t one of the variables. 20 00:02:51 --> 00:03:06 Let us differentiate the expression exp(sin (y - x squared))/x w.r.t x and y. 21 00:03:07 --> 00:03:09 that is with respect to x and y. 22 00:03:10 --> 00:03:14 so you can type var('x y') 23 00:03:15 --> 00:03:25 second line you can type f=exp(sin(y - x squared))by x 24 00:03:26 --> 00:03:42 then you can type diff(f,x) then next line you can type diff(f,y) 25 00:03:43 --> 00:03:50 Thus we get our partial differential solution. 26 00:03:51 --> 00:03:52 Now, let us look at integration. 27 00:03:53 --> 00:04:14 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 28 00:04:15 --> 00:04:20 The integrate command is used to obtain the integral of an expression or function. 29 00:04:21 --> 00:04:38 So you can type integrate(e^(sin(-x squared plus y))multiplied by cos(-x squared +y)by x,y) 30 00:04:39 --> 00:04:43 As we can see,we get back the correct expression. 31 00:04:44 --> 00:04:47 The minus sign being inside or outside the sin function doesn't change much. 32 00:04:48 --> 00:04:54 Now, let us find the value of the integral between the limits 0 and pi/2. 33 00:04:55 --> 00:05:10 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) 34 00:05:11 --> 00:05:14 Hence we got our solution for definite integration. 35 00:05:15 --> 00:05:19 Now, let us see how to obtain the Taylor expansion of an expression using sage. 36 00:05:20 --> 00:05:26 Let us obtain the Taylor expansion of (x + 1) raised to n up to degree 4 about 0. 37 00:05:27 --> 00:05:41 So for that you can type var of ('x n') then type taylor within brackets((x+1) raised to n,x,0,4) 38 00:05:42 --> 00:05:48 We easily got the Taylor expansion,using the taylor function taylor() function. 39 00:05:49 --> 00:05:55 So this brings us to the end of the features of Sage for Calculus, that we will be looking at. 40 00:05:56 --> 00:06:02 For more, look at the Calculus quick-ref from the Sage Wiki. 41 00:06:03 --> 00:06:06 Next let us move on to Matrix Algebra. 42 00:06:07 --> 00:06:18 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]). 43 00:06:19 --> 00:06:22 So, to solve the equation,Ax = v we simply say 44 00:06:23 --> 00:06:34 A=matrix ([1,2] comma [3,4]) then v is equal to vector([1,2]) 45 00:06:35 --> 00:06:49 then x=A dot solve underscore right(v) 46 00:06:50 --> 00:07:00 then you have to type 47 00:07:01 --> 00:07:06 then type x 48 00:07:07 --> 00:07:13 To solve an equation, xA = v we simply say 49 00:07:14 --> 00:07:24 x=A dot solve underscore left(v) 50 00:07:25 --> 00:07:31 then type x 51 00:07:32 --> 00:07:35 The left and right here, denote the position of A, relative to x. 52 00:07:36 --> 00:07:38 Now, let us look at Graph Theory in Sage. 53 00:07:39 --> 00:07:44 We shall look at some ways to create graphs and some of the graph families available in Sage. 54 00:07:45 --> 00:07:48 The simplest way to define an arbitrary graph is to use a dictionary of lists. 55 00:07:49 --> 00:07:52 We create a simple graph by using the Graph() function. 56 00:07:53 --> 00:08:12 So G=Graph({0:[1,2,3], 2:[4]}) and hit shift enter 57 00:08:13 --> 00:08:16 To view the visualization of the graph, we say 58 00:08:17 --> 00:08:23 G.show() 59 00:08:24 --> 00:08:30 Similarly, we can obtain a directed graph using the DiGraph function. 60 00:08:31 --> 00:08:58 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. 61 00:08:59 --> 00:09:03 Sage also provides a lot of graph families which can be viewed by typing graph.tab. 62 00:09:04 --> 00:09:08 Let us obtain a complete graph with 5 vertices and then show the graph. 63 00:09:09 --> 00:09:27 So you can type there G=graphs dot Complete Graph(5) then type G dot show() 64 00:09:28 --> 00:09:34 Sage provides other functions for Number theory and Combinatorics. 65 00:09:35 --> 00:09:41 Let's have a glimpse of a few of them. 66 00:09:42 --> 00:09:45 So prime_range gives primes in the range 100 to 200. 67 00:09:46 --> 00:09:57 So you can type there prime_range within brackets 100,200. 68 00:09:58 --> 00:10:04 is_prime checks if 1999 is a prime number or not. 69 00:10:05 --> 00:10:12 So for that you can type if_prime of (1999) and hit shift enter. 70 00:10:13 --> 00:10:14 So you will get the answer. 71 00:10:15 --> 00:10:19 factor(2001) gives the factorized form of 2001. 72 00:10:20 --> 00:10:32 So to see that you can type factor(2001) and hit shift enter. 73 00:10:33 --> 00:10:35 So you can see the value in the output. 74 00:10:36 --> 00:10:42 So the Permutations() gives the permutations of [1, 2, 3, 4] 75 00:10:43 --> 00:10:56 So for that you can type C=Permutations([1,2,3,4]) and next you can type C.list() 76 00:10:57 --> 00:11:01 And the Combinations() gives all the combinations of [1, 2, 3, 4] 77 00:11:02 --> 00:11:16 For that you can type C= Combinations([1,2,3,4]) and type C dot list() 78 00:11:17 --> 00:11:25 So now you can see the solution displayed 79 00:11:26 --> 00:11:28 This brings us to the end of the tutorial. 80 00:11:29 --> 00:11:31 So In this tutorial, we have learnt to, 81 00:11:32 --> 00:11:51 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 82 00:11:52 --> 00:11:55 solve()-- to solve a function, relative to it's position. 83 00:11:56 --> 00:12:01 then create both a simple graph and a directed graph, using the functions graph and digraph respectively. 84 00:12:02 --> 00:12:03 then use functions for number theory. 85 00:12:04 --> 00:12:10 So for eg: - primes_range()-- function to find out the prime numbers within the specified range. 86 00:12:11 --> 00:12:14 then factor()-- function to find out the factorized form of the specified number. 87 00:12:15 --> 00:12:21 Permutations(), Combinations()-- to obtain the required permutation and combinations for the given set of values. 88 00:12:22 --> 00:12:24 So here are some self assessment questions for you to solve 89 00:12:25 --> 00:12:31 How do you find the limit of the function x/sin(x) as x tends to 0 from the negative side. 90 00:12:32 --> 00:12:36 List all the primes between 2009 and 2900 91 00:12:37 --> 00:12:56 Solve the system of linear equations x-2y+3z = 7 2x+3y-z = 5 x+2y+4z = 9 92 00:12:57 --> 00:13:01 So now we can look at the answers, 93 00:13:02 --> 00:13:08 To find out the limit of an expression from the negative side,we add an argument dir="left" as 94 00:13:09 --> 00:13:18 lim of(x/sin(x), x=0, dir="left") 95 00:13:19 --> 00:13:31 The prime numbers from 2009 and 2900 can be obtained as, prime_range(2009, 2901) 96 00:13:32 --> 00:13:38 We shall first write the equations in matrix form and then use the solve() function 97 00:13:39 --> 00:13:47 So you can type A = Matrix of within brackets([[1, -2, 3] comma [2, 3, -1] comma [1, 2, 4]]) 98 00:13:48 --> 00:13:51 b = vector within brackets([7, 5, 9]) 99 00:13:52 --> 00:13:57 then x = A dot solve_right(b) 100 00:13:58 --> 00:14:02 Then type x so that you can view the output of x. 101 00:14:03 --> 00:14:05 So we hope that you have enjoyed this tutorial and found it useful. 102 00:14:06 --> 00:14:11 Thank you!