1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
|
.. Objectives
.. ----------
.. By the end of this tutorial you will --
.. 1. Get an idea of the range of things for which Sage can be used.
.. #. Know some of the functions for Calculus
.. #. Get some insight into Graphs in Sage.
.. Prerequisites
.. -------------
.. Getting Started -- Sage
Script
------
.. L1
{{{ Show the title slide }}}
.. R1
Hello Friends and Welcome to the tutorial on 'Using Sage for Calculus'.
.. L2
{{{ show the 'objectives' slide }}}
.. R2
At the end of this tutorial, you will be able to,
1. Learn the range of things for which Sage can be used.
#. Perform integrations & other Calculus in Sage.
#. Perform matrix algebra in sage.
.. L3
{{{ show the 'pre-requisite' slide }}}
.. R3
Before beginning this tutorial,we would suggest you to complete the
tutorial on "Getting started with Sage".
Let us begin with Calculus. We shall be looking at limits,
differentiation, integration, and Taylor polynomial.
.. L4
{{{ open sage notebook }}}
.. R4
We have our Sage notebook running. In case, you don't have it running,
start is using the command, ``sage --notebook``.
.. R5
To begin with, let us find the limit of the function x*sin(1/x), at x=0.
To do this we say
.. L5
::
lim(x*sin(1/x), x=0)
.. R6
As expected, we get the limit to be 0.
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.
.. L6
::
lim(1/x, x=0, dir='right')
.. R7
We get the limit from positive side.
To find the limit from the negative side, we say,
.. L7
::
lim(1/x, x=0, dir='left')
.. L8
{{{ Show the 'differential expression' slide }}}
.. R8
Let us now see how to perform differentiation, using Sage. We shall
find the differential of the expression ``exp(sin(x^2))/x`` w.r.t ``x``.
For this, we shall first define the expression, and then use the ``diff``
function to obtain the differential of the expression. So, switch to the sage
notebook and type
.. L9
::
var('x')
f = exp(sin(x^2))/x
diff(f, x)
.. R9
And we get the expected differential of the expression.
.. L10
{{{ Show the slide 'Partial Differentiation' }}}
.. R10
We can also obtain the partial differentiation of an expression with one of the
vriables. Let us differentiate the expression
``exp(sin(y - x^2))/x`` w.r.t x and y. Switch to sage notebook and type
.. L11
::
var('x y')
f = exp(sin(y - x^2))/x
diff(f, x)
diff(f, y)
.. R11
Thus we get our partial differential solution.
.. L12
{{{ Show the 'integration' slide }}}
.. R12
Now, let us look at integration. We shall use the expression obtained
from the differentiation that we calculated before, ``diff(f, y)``
which gave us the expression ---``cos(-x^2 + y)*e^(sin(-x^2 + y))/x``.
The ``integrate`` command is used to obtain the integral of an
expression or function. So, switch to sage notebook and type.
.. L13
{{{ Switch to sage }}}
::
integrate(cos(-x^2 + y)*e^(sin(-x^2 + y))/x, y)
.. R13
As we can see, we get back the correct expression. The minus sign being
inside or outside the ``sin`` function doesn't change much.
Now, let us find the value of the integral between the limits 0 and
pi/2.
.. L14
::
integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2)
.. R14
Hence we get our solution for the definite integration.
Let us now see how to obtain the Taylor expansion of an expression
using sage. We will obtain the Taylor expansion of ``(x + 1)^n`` up to
degree 4 about 0.
.. L15
::
var('x n')
taylor((x+1)^n, x, 0, 4)
.. R15
We easily got the Taylor expansion,using the function ``taylor()``.
This brings us to the end of the features of Sage for Calculus, that
we will be looking at.
.. L16
{{{ Show the 'More on Calculus' slide }}}
.. R16
For more on calculus you may look at the Calculus quick-ref from the Sage
documentation at the given link.
.. L17
{{{ show the 'Equation' slide }}}
.. R17
Next let us move on to Matrix Algebra.
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])``.
.. R18
To solve the equation, ``Ax = v`` we simply say
.. L18
{{{ Switch back to sage notebook page }}}
::
A = matrix([[1,2],
[3,4]])
v = vector([1,2])
x = A.solve_right(v)
x
.. R19
To solve the equation, ``xA = v`` we simply say.
The left and right here, denote the position of ``A``, relative to x.
.. L19
::
x = A.solve_left(v)
x
.. L20
{{{ show the 'Summary' slide }}}
.. R20
This brings us to the end of this tutorial. In this tutorial we have learned to
1. Use functions like lim(), integrate(), integral(), solve()
#. Use sage for performing matrix algebra, integrations & other calculus
operations using the above mentioned functions.
.. L21
{{{ Show the 'Evaluation' slide }}}
.. R21
Here are some self assessment questions for you to solve.
1. How do you find the limit of the function x/sin(x) as x tends to 0 from the
negative side.
#. Solve the system of linear equations
x-2y+3z = 7
2x+3y-z = 5
x+2y+4z = 9
Try the xercises and switch to next slide for solutions.
.. L22
{{{ Show the 'Solutions' slide }}}
.. R22
1. To find the limit of the function x/sin(x) as x tends to 0 from negative
side, use the lim function as: lim(x/sin(x), x=0, dir'left')
#. A = Matrix([1, -2, 3], [2, 3, -1], [1, 2, 4]])
b = vector([7, 5, 9])
x = A.solve_right(b)
x
.. L23
{{{ Show the 'FOSSEE' slide }}}
.. R23
FOSSEE is Free and Open-source Software for Science and Engineering Education.
The goal of this project is to enable all to use open source software tools.
For more details, please visit the given link.
.. L24
{{{ Show the 'About the Spoken Tutorial Project' slide }}}
.. R24
Watch the video available at the following link. It summarizes the Spoken
Tutorial project. If you do not have good bandwidth, you can download and
watch it.
.. L25
{{{ Show the 'Spoken Tutorial Workshops' slide }}}
.. R25
The Spoken Tutorial Project Team conducts workshops using spoken tutorials,
gives certificates to those who pass an online test.
For more details, please write to contact@spoken-tutorial.org
.. L26
{{{ Show the 'Acknowledgements' slide }}}
.. R26
Spoken Tutorial Project is a part of the "Talk to a Teacher" project.
It is supported by the National Mission on Education through ICT, MHRD,
Government of India. More information on this mission is available at the
given link.
.. L27
{{{Show the 'Thank you' slide }}}
.. R27
Hope you have enjoyed this tutorial and found it useful.
Thank you!
|