20 {{{ show sage notebook }}} |
20 {{{ show sage notebook }}} |
21 |
21 |
22 We have our Sage notebook running. In case, you don't have it running, |
22 We have our Sage notebook running. In case, you don't have it running, |
23 start is using the command, ``sage --notebook``. |
23 start is using the command, ``sage --notebook``. |
24 |
24 |
25 To find the limit of the function x*sin(1/x), at x=0, we say:: |
25 To find the limit of the function x*sin(1/x), at x=0, we say |
|
26 :: |
26 |
27 |
27 lim(x*sin(1/x), x=0) |
28 lim(x*sin(1/x), x=0) |
28 |
29 |
29 We get the limit to be 0, as expected. |
30 We get the limit to be 0, as expected. |
30 |
31 |
31 It is also possible to the limit at a point from one direction. For |
32 It is also possible to the limit at a point from one direction. For |
32 example, let us find the limit of 1/x at x=0, when approaching from |
33 example, let us find the limit of 1/x at x=0, when approaching from |
33 the positive side.:: |
34 the positive side. |
|
35 :: |
34 |
36 |
35 lim(1/x, x=0, dir='above') |
37 lim(1/x, x=0, dir='above') |
36 |
38 |
37 To find the limit from the negative side, we say,:: |
39 To find the limit from the negative side, we say, |
|
40 :: |
38 |
41 |
39 lim(1/x, x=0, dir='above') |
42 lim(1/x, x=0, dir='above') |
40 |
43 |
41 Let us now see how to differentiate, using Sage. We shall find the |
44 Let us now see how to differentiate, using Sage. We shall find the |
42 differential of the expression ``exp(sin(x^2))/x`` w.r.t ``x``. We |
45 differential of the expression ``exp(sin(x^2))/x`` w.r.t ``x``. We |
43 shall first define the expression, and then use the ``diff`` function |
46 shall first define the expression, and then use the ``diff`` function |
44 to obtain the differential of the expression.:: |
47 to obtain the differential of the expression. |
|
48 :: |
45 |
49 |
46 var('x') |
50 var('x') |
47 f = exp(sin(x^2))/x |
51 f = exp(sin(x^2))/x |
48 |
52 |
49 diff(f, x) |
53 diff(f, x) |
50 |
54 |
51 We can also obtain the partial differentiation of an expression w.r.t |
55 We can also obtain the partial differentiation of an expression w.r.t |
52 one of the variables. Let us differentiate the expression |
56 one of the variables. Let us differentiate the expression |
53 ``exp(sin(y - x^2))/x`` w.r.t x and y.:: |
57 ``exp(sin(y - x^2))/x`` w.r.t x and y. |
|
58 :: |
54 |
59 |
55 var('x y') |
60 var('x y') |
56 f = exp(sin(y - x^2))/x |
61 f = exp(sin(y - x^2))/x |
57 |
62 |
58 diff(f, x) |
63 diff(f, x) |
60 diff(f, y) |
65 diff(f, y) |
61 |
66 |
62 Now, let us look at integration. We shall use the expression obtained |
67 Now, let us look at integration. We shall use the expression obtained |
63 from the differentiation that we did before, ``diff(f, y)`` --- |
68 from the differentiation that we did before, ``diff(f, y)`` --- |
64 ``e^(sin(-x^2 + y))*cos(-x^2 + y)/x``. The ``integrate`` command is |
69 ``e^(sin(-x^2 + y))*cos(-x^2 + y)/x``. The ``integrate`` command is |
65 used to obtain the integral of an expression or function.:: |
70 used to obtain the integral of an expression or function. |
|
71 :: |
66 |
72 |
67 integrate(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y) |
73 integrate(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y) |
68 |
74 |
69 We get back the correct expression. The minus sign being inside or |
75 We get back the correct expression. The minus sign being inside or |
70 outside the ``sin`` function doesn't change much. |
76 outside the ``sin`` function doesn't change much. |
71 |
77 |
72 Now, let us find the value of the integral between the limits 0 and |
78 Now, let us find the value of the integral between the limits 0 and |
73 pi/2. :: |
79 pi/2. |
|
80 :: |
74 |
81 |
75 integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2) |
82 integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2) |
76 |
83 |
77 Let us now see how to obtain the Taylor expansion of an expression |
84 Let us now see how to obtain the Taylor expansion of an expression |
78 using sage. Let us obtain the Taylor expansion of ``(x + 1)^n`` up to |
85 using sage. Let us obtain the Taylor expansion of ``(x + 1)^n`` up to |
79 degree 4 about 0.:: |
86 degree 4 about 0. |
|
87 :: |
80 |
88 |
81 var('x n') |
89 var('x n') |
82 taylor((x+1)^n, x, 0, 4) |
90 taylor((x+1)^n, x, 0, 4) |
83 |
91 |
84 This brings us to the end of the features of Sage for Calculus, that |
92 This brings us to the end of the features of Sage for Calculus, that |
91 |
99 |
92 Let us begin with solving the equation ``Ax = v``, where A is the |
100 Let us begin with solving the equation ``Ax = v``, where A is the |
93 matrix ``matrix([[1,2],[3,4]])`` and v is the vector |
101 matrix ``matrix([[1,2],[3,4]])`` and v is the vector |
94 ``vector([1,2])``. |
102 ``vector([1,2])``. |
95 |
103 |
96 To solve the equation, ``Ax = v`` we simply say:: |
104 To solve the equation, ``Ax = v`` we simply say |
|
105 :: |
97 |
106 |
98 x = solve_right(A, v) |
107 x = solve_right(A, v) |
99 |
108 |
100 To solve the equation, ``xA = v`` we simply say:: |
109 To solve the equation, ``xA = v`` we simply say |
|
110 :: |
101 |
111 |
102 x = solve_left(A, v) |
112 x = solve_left(A, v) |
103 |
113 |
104 The left and right here, denote the position of ``A``, relative to x. |
114 The left and right here, denote the position of ``A``, relative to x. |
105 |
115 |
106 |
116 #[Puneeth]: any suggestions on what more to add? |
107 |
117 |
108 Now, let us look at Graph Theory in Sage. |
118 Now, let us look at Graph Theory in Sage. |
109 |
119 |
110 Graph: G = Graph({0:[1,2,3], 2:[4]}) |
120 We shall look at some ways to create graphs and some of the graph |
111 Directed Graph: DiGraph(dictionary) |
121 families available in Sage. |
112 Graph families: graphs. tab |
|
113 Invariants: G.chromatic polynomial(), G.is planar() |
|
114 Paths: G.shortest path() |
|
115 Visualize: G.plot(), G.plot3d() |
|
116 Automorphisms: G.automorphism group(), G1.is isomorphic(G2), G1.is subgraph(G2) |
|
117 |
122 |
118 Now let us look at bits and pieces of Number theory, combinatorics, |
123 The simplest way to define an arbitrary graph is to use a dictionary |
|
124 of lists. We create a simple graph by |
|
125 :: |
119 |
126 |
|
127 G = Graph({0:[1,2,3], 2:[4]}) |
|
128 |
|
129 We say |
|
130 :: |
|
131 |
|
132 G.show() |
|
133 |
|
134 to view the visualization of the graph. |
|
135 |
|
136 Similarly, we can obtain a directed graph using the ``DiGraph`` |
|
137 function. |
|
138 :: |
|
139 |
|
140 G = DiGraph({0:[1,2,3], 2:[4]}) |
|
141 |
|
142 |
|
143 Sage also provides a lot of graph families which can be viewed by |
|
144 typing ``graph.<tab>``. Let us obtain a complete graph with 5 vertices |
|
145 and then show the graph. |
|
146 :: |
|
147 |
|
148 G = graphs.CompleteGraph(5) |
|
149 |
|
150 G.show() |
|
151 |
|
152 |
|
153 Sage provides other functions for Number theory and |
|
154 Combinatorics. Let's have a glimpse of a few of them. |
|
155 |
|
156 |
|
157 :: |
|
158 |
|
159 prime_range(100, 200) |
|
160 |
|
161 gives primes in the range 100 to 200. |
|
162 |
|
163 :: |
|
164 |
|
165 is_prime(1999) |
|
166 |
|
167 checks if 1999 is a prime number or not. |
|
168 |
|
169 :: |
|
170 |
|
171 factor(2001) |
|
172 |
|
173 gives the factorized form of 2001. |
|
174 |
|
175 :: |
|
176 |
|
177 C = Permutations([1, 2, 3, 4]) |
|
178 C.list() |
|
179 |
|
180 gives the permutations of ``[1, 2, 3, 4]`` |
|
181 |
|
182 :: |
|
183 |
|
184 C = Combinations([1, 2, 3, 4]) |
|
185 C.list() |
|
186 |
|
187 gives all the combinations of ``[1, 2, 3, 4]`` |
|
188 |
|
189 That brings us to the end of this session showing various features |
|
190 available in Sage. |
|
191 |
|
192 {{{ Show summary slide }}} |
|
193 |
|
194 We have looked at some of the functions available for Linear Algebra, |
|
195 Calculus, Graph Theory and Number theory. |
|
196 |
|
197 Thank You! |