diff options
-rw-r--r-- | images/fossee-logo.png | bin | 13587 -> 10564 bytes | |||
-rw-r--r-- | images/iitb-logo.png | bin | 13756 -> 0 bytes | |||
-rw-r--r-- | script2col.rst | 267 | ||||
-rw-r--r-- | using_sage_for_calculus/folder.png | bin | 0 -> 45829 bytes | |||
-rw-r--r-- | using_sage_for_calculus/quickref.tex | 8 | ||||
-rw-r--r-- | using_sage_for_calculus/script.odt | bin | 0 -> 35167 bytes | |||
-rw-r--r-- | using_sage_for_calculus/script.rst | 327 | ||||
-rw-r--r-- | using_sage_for_calculus/script.txt | 269 | ||||
-rw-r--r-- | using_sage_for_calculus/script2col.rst | 166 | ||||
-rw-r--r-- | using_sage_for_calculus/slides.org | 117 | ||||
-rw-r--r-- | using_sage_for_calculus/slides.tex | 200 | ||||
-rw-r--r-- | using_sage_for_graphs/part2.rst | 178 | ||||
-rw-r--r-- | using_sage_for_graphs/script.odt | bin | 0 -> 33593 bytes | |||
-rw-r--r-- | using_sage_for_graphs/slides.tex | 149 |
14 files changed, 1681 insertions, 0 deletions
diff --git a/images/fossee-logo.png b/images/fossee-logo.png Binary files differindex 49d1797..c0ea381 100644 --- a/images/fossee-logo.png +++ b/images/fossee-logo.png diff --git a/images/iitb-logo.png b/images/iitb-logo.png Binary files differdeleted file mode 100644 index 38ec17e..0000000 --- a/images/iitb-logo.png +++ /dev/null diff --git a/script2col.rst b/script2col.rst new file mode 100644 index 0000000..3e820d6 --- /dev/null +++ b/script2col.rst @@ -0,0 +1,267 @@ +.. Objectives +.. ---------- + +.. At the end of this tutorial, you will be able to + +.. 1. Execute python scripts from command line. +.. #. Use import in scripts. +.. #. Import scipy and pylab modules +.. #. Use python standard modules and 3rd party modules. + + +.. Prerequisites +.. ------------- + +.. 1. should have ``pylab`` installed. +.. #. using plot command interactively. +.. #. embellishing a plot. +.. #. saving plots. + +.. Author : Anoop Jacob Thomas <anoop@fossee.in> + Internal Reviewer : Puneeth + External Reviewer : + Language Reviewer : Bhanukiran + Checklist OK? : <11-11-2010, Anand, OK> [2010-10-05] + + +==================== +Using Python modules +==================== + + + ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the first slide containing title, name of the production | Hello Friends and Welcome to the spoken tutorial on | +| team along with the logo of MHRD }}} | 'Using Python Modules'. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to objectives slide }}} | At the end of this tutorial, you will be able to , | +| | | +| | 1. Execute python scripts from command line. | +| | #. Use import in scripts. | +| | #. Import scipy and pylab modules. | +| | #. Use python standard modules and 3rd party modules. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to the pre-requisite slide }}} | Before beginning this tutorial,we would suggest you to complete the | +| | tutorial on "Using plot interactively", "Embellishing a plot" and | +| | "Saving plots". | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide on running python scripts from | | +| command line }}} | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | Let us create a simple python script to print hello world. Open your | +| | text editor and type the following, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ open the text editor and type the following }}} | | +| :: | | +| | | +| print "Hello world!" | | +| print | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ save the script as hello.py }}} | Now save this script as ``hello.py``, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Open the terminal }}} | Start the ipython interpreter | +| :: | | +| | | +| ipython | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | In the previous tutorials,we have seen how to run a script using | +| | the IPython interpreter using ``%run`` | +| %run -i hello.py | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Close the terminal }}} | but this is not the correct way of running a python | +| | script. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ open terminal and navigate to directory where hello.py was saved }}} | The correct method is to run it using the Python interpreter. Open the | +| | terminal and navigate to the directory where hello.py is, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | now run the Python script as, | +| | | +| python hello.py | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | It executed the script and we got the output ``Hello World!``. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide }}} | The syntax is ``python space filename``. | +| {{{ highlight ``python filename`` syntax on slide while narrating }}} | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, four plot problem }}} | Now, we have a four plot problem where we have plotted four plots in a | +| | single figure. Let us run that script from command line. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ open the four_plot.py file in text editor and show }}} | If you don't have the script, then make one with the following set of | +| {{{ Pause for some time and then continue }}} | commands | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Now let us run four_plot.py as a python script. | +| | | +| python four_plot.py | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | Oops! even though it was supposed to work, it didn't. It gave an error | +| | ``linspace()`` is not defined, which means that the function | +| | ``linspace()`` is not available in the current name-space. | +| | | +| | But if you try to run the same script using ``%run -i four_plot.py`` | +| | in your IPython interpreter started with the option ``-pylab`` it will | +| | work, because the ``-pylab`` option does some work for us by importing | +| | the required modules to our name-space when ipython interpreter | +| | starts. And thus we don't have to explicitly import modules. | +| | | +| | So now let us try to fix the problem and run the script in command | +| | line, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, fix ``linspace`` problem }}} | add this line as the first line in the script, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ add the line as first line in four_plot.py and save }}} | | +| :: | | +| | | +| from scipy import * | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Now let us run the script again, | +| | | +| python four_plot.py | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | Now it gave another error -- plot not defined, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, thank you slide }}} | let us edit the file again and add this line as the | +| | second line in our script and save it, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ add the line as second line in four_plot.py and save }}} | | +| :: | | +| | | +| from pylab import * | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to the terminal }}} | And now, run the script, | +| :: | | +| | | +| python four_plot.py | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | Yes! it worked. So what did we do? | +| | | +| | We actually imported the required modules using the keyword ``import``. | +| | It could also be done as by using, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, better way of fixing }}} | from scipy import linspace | +| {{{ highlight the required line while narrating }}} | | +| | instead of, | +| | | +| | from scipy import * | +| | | +| | So in practice it is always good to use function names instead of | +| | asterisk or star. If we use asterisk to import from a particular | +| | module then it will replace any existing functions with the same name | +| | in our name-space. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, Instead of ``*`` }}} | So let us modify four_plot.py as, | +| | Hence we delete the first two lines of our code which we had added | +| | and add these lines | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to script 'four_plot.py' }}} | | +| {{{ delete the first two lines and add the following }}} | | +| :: | | +| | | +| from scipy import linspace, pi, sin | | +| from pylab import plot, legend, annotate | | +| from pylab import xlim, ylim, title, show | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Now let us try running the code again as, | +| | | +| python four_plot.py | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | It works! In this method we actually imported the functions to the | +| | current name-space.There is one more way of doing it. And that | +| | is, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to slide 'another fix' }}} | Notice that we use ``scipy.pi`` instead of just ``pi`` as in the | +| {{{ highlight the required line while narrating }}} | previous method, and the functions are called as ``pylab.plot()`` and | +| | ``pylab.annotate()`` and not as ``plot()`` and ``annotate()``. | +| | | +| | Pause the video here, try out the following exercise and resume the video. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show slide with exercise 1 }}} | Write a script to plot a sine wave from minus two pi to two pi. | +| | <Pause> | +| | It can solved as, | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ open sine.py and show it }}} | The first line we import the required functions ``linspace()`` , | +| | ``sin()`` and constant ``pi`` from the module scipy. The second and | +| | third line we import the functions ``plot()``, ``legend()``, | +| | ``show()``, ``title()``, ``xlabel()`` and ``ylabel()``. And the rest | +| | the code to generate the plot. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Pause for sometime and then continue }}} | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to the terminal }}} | We can run it as, | +| :: | | +| | | +| python sine.py | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | As we can see, we our sine plot.Let us move further in our topic. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, What is a module? }}} | Until now we have been learning about importing modules, now what is a | +| | module? | +| | | +| | A module is simply a file containing Python definitions and | +| | statements. Definitions from a module can be imported into other | +| | modules or into the main module. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, Python standard library }}} | Python has a very rich standard library of modules. It is very | +| | extensive, offering a wide range of facilities. Some of the standard | +| | modules are, | +| | | +| | for Math: math, random | +| | for Internet access: urllib2, smtplib | +| | for System, Command line arguments: sys | +| | for Operating system interface: os | +| | for regular expressions: re | +| | for compression: gzip, zipfile, tarfile | +| | And there are lot more. | +| | | +| | Find more information at Python Library reference, | +| | ``http://docs.python.org/library/`` | +| | | +| | There are a lot of other modules like pylab, scipy, Mayavi, etc which | +| | are not part of the standard python library. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ switch to next slide, summary }}} | This brings us to the end of this tutorial. In this tutorial, we have | +| | learnt to, | +| | | +| | 1. Run scripts from command line, | +| | #. Import modules by specifying the module name followed by | +| | an asterisk. | +| | #. Import only the required functions from modules by specifying | +| | the function name. | +| | #. Use python standard library. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{Show self assessment questions slide}}} | Here are some self assessment questions for you to solve | +| | | +| | 1. Which among this is correct ? | +| | | +| | - from scipy import plot | +| | - from numpy import plot | +| | - from matplotlib import plot | +| | - from pylab import plot | +| | | +| | 2. Which among these libraries is part of python standard library ? | +| | | +| | - Mayavi | +| | - scipy | +| | - matplotlib | +| | - urllib2 | +| | | +| | 3. Functions ``xlim()`` and ``ylim()`` can be imported to the current | +| | name-space as, | +| | | +| | - from pylab import xlim, ylim | +| | - import pylab | +| | - from scipy import xlim, ylim | +| | - import scipy | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{solution of self assessment questions on slide}}} | And the answers, | +| | | +| | 1. The option ``from pylab import plot`` is the correct one, since plot | +| | is a function of module module. | +| | | +| | 2. ``urllib2`` is a part of the python standard library. | +| | | +| | 3. Functions ``xlim()`` and ``ylim()`` can be imported to the current | +| | name-space as, ``from pylab import xlim, ylim``. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| | Hope you have enjoyed this tutorial and found it useful. | +| | Thank you! | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ diff --git a/using_sage_for_calculus/folder.png b/using_sage_for_calculus/folder.png Binary files differnew file mode 100644 index 0000000..42d01a2 --- /dev/null +++ b/using_sage_for_calculus/folder.png diff --git a/using_sage_for_calculus/quickref.tex b/using_sage_for_calculus/quickref.tex new file mode 100644 index 0000000..b26d168 --- /dev/null +++ b/using_sage_for_calculus/quickref.tex @@ -0,0 +1,8 @@ +Creating a linear array:\\ +{\ex \lstinline| x = linspace(0, 2*pi, 50)|} + +Plotting two variables:\\ +{\ex \lstinline| plot(x, sin(x))|} + +Plotting two lists of equal length x, y:\\ +{\ex \lstinline| plot(x, y)|} diff --git a/using_sage_for_calculus/script.odt b/using_sage_for_calculus/script.odt Binary files differnew file mode 100644 index 0000000..f26e438 --- /dev/null +++ b/using_sage_for_calculus/script.odt diff --git a/using_sage_for_calculus/script.rst b/using_sage_for_calculus/script.rst new file mode 100644 index 0000000..f465248 --- /dev/null +++ b/using_sage_for_calculus/script.rst @@ -0,0 +1,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! diff --git a/using_sage_for_calculus/script.txt b/using_sage_for_calculus/script.txt new file mode 100644 index 0000000..87a4d7d --- /dev/null +++ b/using_sage_for_calculus/script.txt @@ -0,0 +1,269 @@ + +{| style="border-spacing:0;" +| style="border-top:0.05pt double #808080;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| <center>'''Visual Cue'''</center> +| style="border:0.05pt double #808080;padding:0.049cm;"| <center>'''Narration'''</center> + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 1 + +Title Slide +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| Hello Friends and Welcome to the tutorial on 'Using Sage'. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 2 + +Objectives +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| # At the end of this tutorial, you will be able to,
+#
+# 1. Learn the range of things for which Sage can be used.
+# 2. Perform integrations & other Calculus in Sage.
+# 3. Perform matrix algebra in sage.
+ +Let us begin with Calculus. We shall be looking at limits, differentiation, integration, and Taylor polynomial. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Open sage notebook + +lim(x*sin(1/x), x=0) +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| We have our '''Sage''' '''notebook''' running. In case, you don't have it running,
start is using the command, '''sage''' ''space hyphen hyphen'' '''notebook.
''' + +To begin with, let us find the limit of the function '''x*sin(1/x)''', at '''x=0'''.
To do this we can use the '''lim''' '''funtcion''' as, '''lim''' ''within brackets'' '''x''' ''star '''''sin''' ''within brackets'' '''one''' ''divided by'' '''x '''''coma '''''x '''''is equal to '''''zero''' + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| lim(1/x, x=0, dir='right') +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| We get the limit to be 0, as expected. + +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. So we say '''lim '''''within brackets '''''one by x, x=0, dir '''''is equal to in single quotes '''''right.''' + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| lim(1/x, x=0, dir='left') +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| The same way we can even find the limit from the negative side, we say, '''lim '''''within brackets '''''one by x, x=0, dir '''''is equal to in single quotes '''''left.''' + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 3 + + +Differential Expression +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| Let us now see how to perform '''differentiation''', using '''Sage'''. We shall find the '''differential''' of the expression '''sin''' '''square''' '''by x''' with reference to '''x ''' + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| var('x') + +f = exp(sin(x^2))/x + +diff(f, x) +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| So switch to the sage notebook. + +We shall first define the expression, and then use the '''diff '''function to obtain the differential of the expression. + +So, type '''var '''''within round brackets in single quotes '''''x. '''Now, '''f '''''is equal to '''''exp '''''within brackets '''''sin '''''within brackets '''''x '''''to the power '''''two by x.''' + +We have the expression now and will obtain the differential using the '''diff function.''' + +Type '''diff '''''within brackets '''''f '''''coma '''''x.''' + +We get the differential. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show slide 4 + +Partial Differential Expression +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| We can also obtain the partial differentiation of an expression with one of the vriables. + +Let us '''differentiate''' the '''expression
'''shown on the slide with + +reference to '''x''' and '''y'''. Switch to sage notebook + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| var('x y') + +f = exp(sin(y - x^2))/x + + +diff(f, x) + + +diff(f, y) +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| We first define the expression. + +So type, '''var '''''within round brackets in single quotes '''''x y''' + +Then, '''f '''''is equal to '''''exp '''''in brackets '''''sin '''''in brackets '''''y '''''minus '''''x '''''to the power''''' two by x.''' + +So the expression is ready now to get the partial differential of the expression we say '''diff '''''in brackets '''''f, x.''' + +Similarly for '''y '''we say '''diff '''''in brackets '''''f, y''.''''' + +Thus we get our partial differential solution. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 5 + +Integration +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| 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 shown on the slide. + +The integrate command is used to obtain the integral of an expression or function. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| integrate(cos(-x^2 + y)*e^(sin(-x^2 + y))/x, y) +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| So, switch to sage notebook and type, '''integrate '''and the expression we got from the previous calculation. As we can see, we get back the correct expression. + +The minus sign being
inside or outside the '''sin function''' doesn't change much. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2) +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| 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. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| var('x n') + +taylor((x+1)^n, x, 0, 4) +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| Hence we get our solution for the definite integration. Let us now see how to obtain the Taylor expansion of an expression using sage using '''taylor function'''. + +Let us obtain the Taylor expansion of(x+1)^nup to degree 4 about 0. + +For this, type, '''var '''''in brackets '''''x n''' + +Now, '''taylor '''''in brackets again in brackets '''''x + one '''''the whole to the power '''''n '''''coma '''''x, zero, four.''' + +We easily got the Taylor expansion,using the function taylor(). + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 6 + + +More on Calculus +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| That we will be all about the features of '''Sage '''for calculus we will be looking at. For more, look at the Calculus quick-ref from the Sage Wiki. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 7 + +Equation +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| Next let us move on to Matrix Algebra. Let us begin with solving the equation. Ax = v, where A is the matrix <nowiki>matrix([[1,2],[3,4]]) </nowiki>and v is the vector <nowiki>vector([1,2])</nowiki>. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Switch back to sage notebook page + +<nowiki>A = matrix([[1,2],</nowiki> + + <nowiki>[3,4]])</nowiki> + +<nowiki>v = vector([1,2])</nowiki> + +x = A.solve_right(v) + +x +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| To solve the equation, Ax = v we simply say, + + +'''A '''''is equal to '''''matrix '''''within round brackets in square brackets '''''one, two, '''''again in square brackets '''''three, four''' + +'''v '''''is equal to '''''vector '''''within round brackets in square brackets '''''one, two''' + +'''x '''''is equal to '''''A '''''dot '''''solve_right '''''in brackets '''''v''' + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| x = A.solve_left(v) + +x +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| To solve the equation, xA = v we simply say, + + +'''x '''''is equal to '''''A '''''dot '''''solve_left '''''in brackets '''''v''' + + +'''The left and right here, denote the position of A, relative to x.''' + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 8 + +Summary slide +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| # This brings us to the end of this tutorial. In this tutorial we have learned to
+#
+# 1. Use functions like '''lim(), integrate(), integral(), solve()'''
+# <nowiki>#. Use </nowiki>'''sage''' for performing '''matrix algebra, integrations''' & other calculus
operations using the above mentioned functions.
+ + + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 9 + +Evaluation +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| 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. + +2. Solve the system of linear equations
+ +x-2y+3z = 7
+ +2x+3y-z = 5
+ +x+2y+4z = 9 + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 10 + +Solutions +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| And the answers, + +# 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") + +# We shall first write the equations in '''matrix''' form and then use the '''solve()''' function +# + + <nowiki>A = Matrix([[1, -2, 3],</nowiki> + <nowiki>[2, 3, -1],</nowiki> + <nowiki>[1, 2, 4]])</nowiki> + +<nowiki>b = vector([7, 5, 9])</nowiki> + + +x = A.solve_right(b) + +To view the output type x + +x + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 11 + +FOSSEE +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| 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. + +|} + +{| style="border-spacing:0;" +| style="border-top:0.05pt double #808080;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 12 + +About the Spoken Tutorial Project +| style="border:0.05pt double #808080;padding:0.049cm;"| 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. + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 13 + +Spoken Tutorial Workshop +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| The Spoken Tutorial Project Team conducts SELF workshops using spoken tutorials, gives certificates to those who pass an online test. For more details, you may write to contact@spoken-tutorial.org + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 14 + +Acknowledgements +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| 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. + + + + +|- +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:none;padding:0.049cm;"| Show Slide 15 + +Thank You +| style="border-top:none;border-bottom:0.05pt double #808080;border-left:0.05pt double #808080;border-right:0.05pt double #808080;padding:0.049cm;"| Hope you have enjoyed this tutorial and found it useful. Thank you! + +|} + diff --git a/using_sage_for_calculus/script2col.rst b/using_sage_for_calculus/script2col.rst new file mode 100644 index 0000000..16c4871 --- /dev/null +++ b/using_sage_for_calculus/script2col.rst @@ -0,0 +1,166 @@ +.. 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 +------ + + + ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the title slide }}} | Hello Friends and Welcome to the tutorial on 'Using Sage for Calculus'. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ show the 'objectives' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ show the 'pre-requisite' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ open sage notebook }}} | We have our Sage notebook running. In case, you don't have it running, | +| | start is using the command, ``sage --notebook``. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | To begin with, let us find the limit of the function x*sin(1/x), at x=0. | +| | To do this we say | +| lim(x*sin(1/x), x=0) | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | As expected, we get the limit to be 0. | +| | | +| lim(1/x, x=0, dir='right') | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | We get the limit from positive side. | +| | To find the limit from the negative side, we say, | +| lim(1/x, x=0, dir='left') | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'differential expression' slide }}} | 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 | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | And we get the expected differential of the expression. | +| | | +| var('x') | | +| f = exp(sin(x^2))/x | | +| diff(f, x) | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the slide 'Partial Differentiation' }}} | 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 | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Thus we get our partial differential solution. | +| | | +| var('x y') | | +| f = exp(sin(y - x^2))/x | | +| diff(f, x) | | +| diff(f, y) | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'integration' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch to sage }}} | As we can see, we get back the correct expression. The minus sign being | +| :: | inside or outside the ``sin`` function doesn't change much. | +| | | +| integrate(cos(-x^2 + y)*e^(sin(-x^2 + y))/x, y) | Now, let us find the value of the integral between the limits 0 and | +| | pi/2. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | Hence we get our solution for the definite integration. | +| | Let us now see how to obtain the Taylor expansion of an expression | +| integral(e^(sin(-x^2 + y))*cos(-x^2 + y)/x, y, 0, pi/2) | using sage. We will obtain the Taylor expansion of ``(x + 1)^n`` up to | +| | degree 4 about 0. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | We easily got the Taylor expansion,using the function ``taylor()``. | +| | This brings us to the end of the features of Sage for Calculus, that | +| var('x n') | we will be looking at. | +| taylor((x+1)^n, x, 0, 4) | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'More on Calculus' slide }}} | For more on calculus you may look at the Calculus quick-ref from the Sage | +| | documentation at the given link. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ show the 'Equation' slide }}} | 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])``. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Switch back to sage notebook page }}} | To solve the equation, ``Ax = v`` we simply say | +| :: | | +| | | +| A = matrix([[1,2], | | +| [3,4]]) | | +| v = vector([1,2]) | | +| x = A.solve_right(v) | | +| x | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| :: | To solve the equation, ``xA = v`` we simply say. | +| | The left and right here, denote the position of ``A``, relative to x. | +| x = A.solve_left(v) | | +| x | | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ show the 'Summary' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'Evaluation' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'Solutions' slide }}} | 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 | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'FOSSEE' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'About the Spoken Tutorial Project' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'Spoken Tutorial Workshops' slide }}} | 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 | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{ Show the 'Acknowledgements' slide }}} | 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. | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ +| {{{Show the 'Thank you' slide }}} | Hope you have enjoyed this tutorial and found it useful. | +| | Thank you! | ++----------------------------------------------------------------------------------+----------------------------------------------------------------------------------+ diff --git a/using_sage_for_calculus/slides.org b/using_sage_for_calculus/slides.org new file mode 100644 index 0000000..c5e35c8 --- /dev/null +++ b/using_sage_for_calculus/slides.org @@ -0,0 +1,117 @@ +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] +#+BEAMER_FRAME_LEVEL: 1 + +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} +#+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) +#+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] + +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} + +#+TITLE: +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: + +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc + +* +#+begin_latex +\begin{center} +\vspace{12pt} +\textcolor{blue}{\huge Using Sage} +\end{center} +\vspace{18pt} +\begin{center} +\vspace{10pt} +\includegraphics[scale=0.95]{../images/fossee-logo.png}\\ +\vspace{5pt} +\scriptsize Developed by FOSSEE Team, IIT-Bombay. \\ +\scriptsize Funded by National Mission on Education through ICT\\ +\scriptsize MHRD,Govt. of India\\ +\includegraphics[scale=0.30]{../images/iitb-logo.png}\\ +\end{center} +#+end_latex +* Objectives + At the end of this tutorial, you will be able to, + + - Learn the range of things for which Sage can be used. + - Know some of the functions for Calculus. + - Learn about graph theory and number theory using Sage. +* Pre-requisite + Spoken tuorial on - + - Getting started with Sage +* Equation + Ax = v, + where A is the matrix,'' matrix([[1,2],[3,4]])'' + v is the vector, ''vector([1,2])''. +* Summary +In this tutorial, we have learnt to, + - 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 + - solve()-- to solve a function, relative to it's postion. + - Create Both a simple graph and a directed graph, using the + functions ``graph()`` and ``digraph()`` respectively. + - Use functions for Number theory.For eg: + - primes\_range()-- to find out the prime numbers within the + specified range + - factor()-- to find out the factorized form of the number specified + - Permutations(), Combinations()-- to obtain the required permutation + and combinations for the given set of values. +* Evaluation + 1. How do you find the limit of the function ``x/sin(x)`` as ``x`` tends + to ``0`` from the negative side. + + 2. List all the primes between 2009 and 2900. + + 3. Solve the system of linear equations + + x-2y+3z = 7 + 2x+3y-z = 5 + x+2y+4z = 9 +* Solutions +1. lim(x/sin(x), x=0, dir="below") + +2. prime\_range(2009, 2901) + +3. A = Matrix([[1, -2, 3], + [2, 3, -1], + [1, 2, 4]]) + + b = vector([7, 5, 9]) + + solve\_right(A, b) +* +#+begin_latex + \begin{block}{} + \begin{center} + \textcolor{blue}{\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + \url{http://fossee.in/} + \end{center} + \end{block} +#+end_latex + + diff --git a/using_sage_for_calculus/slides.tex b/using_sage_for_calculus/slides.tex new file mode 100644 index 0000000..c9b58e6 --- /dev/null +++ b/using_sage_for_calculus/slides.tex @@ -0,0 +1,200 @@ +\documentclass[17pt]{beamer} +\usetheme{Madrid} +\useoutertheme{noslidenum} +\setbeamertemplate{navigation symbols}{} +\usepackage{beamerthemesplit} +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{mathpazo,courier,euler} +\usepackage{listings} + +\lstset{language=sh, + basicstyle=\ttfamily\bfseries, + showstringspaces=false, + keywordstyle=\color{black}\bfseries} + +\definecolor{NavyBlue}{RGB}{0, 76, 153} +\setbeamercolor{structure}{fg=NavyBlue} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% + +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.png} + +\hspace{7.5cm} +\includegraphics[scale=0.3]{../images/fossee-logo.png}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} + +\begin{document} + +\sffamily \bfseries +\title +[Using Sage for Calculus] +{Using Sage for Calculus} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\National Mission on Education + through ICT\\{\color{blue}\url{http://sakshat.ac.in}} \\ [0.8cm]Script by: Hardik Ghaghada \\Narration by: \\ [0.7cm] +{\small 15 May 2013}} + +% slide 1 +\begin{frame} + \titlepage +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Objectives} + At the end of this tutorial, you will be able to, +\begin{itemize} +\item Learn the range of things for which Sage can be used. +\item Perform integrations \& other Calculus in Sage. +\item Perform matrix algebra in sage. +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Differential Expression} +$exp(sin(x^2))/x$\\ +w.r.t $x$ +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Partial Differential Expression} +$exp(sin(y - x^2))/x$\\ +w.r.t $x, y$ +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Integration} +\begin{itemize} +\item $diff(f, y)$\\ +\item $cos(-x^2 + y)*e^(sin(-x^2 + y))/x$\\ +\item $integrate$ +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{More on Calculus} +\url{www.sagemath.org/help.html} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Equation} + $Ax = v$\\ + where A is the matrix,\\ + $matrix([[1,2],[3,4]])$\\ + v is the vector,\\ + $vector([1,2])$ +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Summary} +In this tutorial, we have learnt to, +\begin{itemize} +\item Use functions like lim(), integrate(), integral(), solve() +\item Use sage for performing matrix algebra, integrations \& other calculus +operations using the above mentioned functions. +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Evaluation} +\begin{enumerate} +\item How do you find the limit of the function ``x/sin(x)'' as ``x'' tends + to ``0'' from the negative side. +\vspace{3pt} +\vspace{3pt} +\item Solve the system of linear equations + x-2y+3z = 7\\ + 2x+3y-z = 5\\ + x+2y+4z = 9 +\end{enumerate} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Solutions} +\begin{enumerate} +\item lim(x/sin(x), x=0, dir=`left') +\vspace{4pt} +\item A = Matrix([[1, -2, 3], \\ +\hspace{1.78cm} + [2, 3, -1], \\ +\hspace{1.78cm} + [1, 2, 4]]) \\ +\vspace{2pt} + b = vector([7, 5, 9])\\ +\vspace{2pt} + x = A.solve$\_{\mathrm{right}}$(b)\\ +\vspace{2pt} + x +\end{enumerate} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{FOSSEE} +{\color{blue}Free and Open-source Software for \\Science and Engineering Education} \\ +\begin{itemize} +\item Goal - enabling all to use open source software tools +\item For more details, please visit {\color{blue}\url{http://fossee.in/}} +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} + \begin{block}{} + \begin{center} + \textcolor{blue}{\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + \url{http://fossee.in/} + \end{center} + \end{block} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\end{document} diff --git a/using_sage_for_graphs/part2.rst b/using_sage_for_graphs/part2.rst new file mode 100644 index 0000000..7eaca67 --- /dev/null +++ b/using_sage_for_graphs/part2.rst @@ -0,0 +1,178 @@ +########## Break Here ########## + +Now, let us look at Graph Theory in Sage. + +We shall look at some ways to create graphs and some of the graph +families available in Sage. + +The simplest way to define an arbitrary graph is to use a dictionary +of lists. We create a simple graph by using the ``Graph()`` function. + +.. L17 +:: + + G = Graph({0:[1,2,3], 2:[4]}) + +.. R18 + +to view the visualization of the graph, we say + +.. L18 +:: + + G.show() + +.. R19 + +Similarly, we can obtain a directed graph using the ``DiGraph`` +function. + +.. L19 +:: + + G = DiGraph({0:[1,2,3], 2:[4]}) + +.. R20 + +Sage also provides a lot of graph families which can be viewed by +typing ``graph.<tab>``. Let us obtain a complete graph with 5 vertices +and then show the graph. + +.. L20 +:: + + G = graphs.CompleteGraph(5) + + G.show() + +.. R21 + +Sage provides other functions for Number theory and +Combinatorics. Let's have a glimpse of a few of them. +``prime_range`` gives primes in the range 100 to 200. + +.. L21 +:: + + prime_range(100, 200) + +.. R22 + +``is_prime`` checks if 1999 is a prime number or not. + +.. L22 +:: + + is_prime(1999) + +.. R23 + +``factor(2001)`` gives the factorized form of 2001. + +.. L23 +:: + + factor(2001) + +.. R24 + +The ``Permutations()`` gives the permutations of ``[1, 2, 3, 4]`` + +.. L24 +:: + + C = Permutations([1, 2, 3, 4]) + C.list() + +.. R25 + +And the ``Combinations()`` gives all the combinations of ``[1, 2, 3, 4]`` + +.. L25 +:: + + C = Combinations([1, 2, 3, 4]) + C.list() + +.. L26 + +{{{ Show summary slide }}} + +.. R26 + +This brings us to the end of the tutorial.In this tutorial, +we have learnt to, + + 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 + - solve()-- to solve a function, relative to it's position. + #. Create Both a simple graph and a directed graph, using the + functions ``graph`` and ``digraph`` respectively. + #. Use functions for Number theory.For eg: + - primes_range()-- to find out the prime numbers within the + specified range + - factor()-- to find out the factorized form of the number specified + - Permutations(), Combinations()-- to obtain the required permutation + and combinations for the given set of values. + +.. L27 + +{{{Show self assessment questions slide}}} + +.. R27 + +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. + + +2. List all the primes between 2009 and 2900 + + +3. Solve the system of linear equations + + x-2y+3z = 7 + 2x+3y-z = 5 + x+2y+4z = 9 + +.. L28 + +{{{solution of self assessment questions on slide}}} + +.. R28 + +And the answers, + +1. To find out the limit of an expression from the negative side,we add + an argument dir="left" as +:: + + lim(x/sin(x), x=0, dir="left") + +2. The prime numbers from 2009 and 2900 can be obtained as, +:: + + prime_range(2009, 2901) + +3. We shall first write the equations in matrix form and then use the + solve() function +:: + + A = Matrix([[1, -2, 3], + [2, 3, -1], + [1, 2, 4]]) + + b = vector([7, 5, 9]) + + x = A.solve_right(b) + +To view the output type x +:: + + x + diff --git a/using_sage_for_graphs/script.odt b/using_sage_for_graphs/script.odt Binary files differnew file mode 100644 index 0000000..53dd5f4 --- /dev/null +++ b/using_sage_for_graphs/script.odt diff --git a/using_sage_for_graphs/slides.tex b/using_sage_for_graphs/slides.tex new file mode 100644 index 0000000..18e2d1c --- /dev/null +++ b/using_sage_for_graphs/slides.tex @@ -0,0 +1,149 @@ +\documentclass[17pt]{beamer} +\usetheme{Madrid} +\useoutertheme{noslidenum} +\setbeamertemplate{navigation symbols}{} +\usepackage{beamerthemesplit} +\usepackage{ae,aecompl} +\usepackage[scaled=.95]{helvet} +\usepackage[english]{babel} +\usepackage[latin1]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{mathpazo,courier,euler} +\usepackage{listings} + +\lstset{language=sh, + basicstyle=\ttfamily\bfseries, + showstringspaces=false, + keywordstyle=\color{black}\bfseries} + +\definecolor{NavyBlue}{RGB}{0, 76, 153} +\setbeamercolor{structure}{fg=NavyBlue} +\author[FOSSEE]{} +\institute[IIT Bombay]{} +\date[]{} + +% theme split +\usepackage{verbatim} +\newenvironment{colorverbatim}[1][]% +{% +\color{blue} +\verbatim +}% +{% +\endverbatim +}% + +% logo +\logo{\includegraphics[height=1.30 cm]{../images/3t-logo.pdf}} +\logo{\includegraphics[height=1.30 cm]{../images/fossee-logo.png} + +\hspace{7.5cm} +\includegraphics[scale=0.3]{../images/fossee-logo.png}\\ +\hspace{281pt} +\includegraphics[scale=0.80]{../images/3t-logo.pdf}} + +\begin{document} + +\sffamily \bfseries +\title +[Graph Theory in Sage] +{Grapy Theory in Sage} +\author +[FOSSEE] +{\small Talk to a Teacher\\{\color{blue}\url{http://spoken-tutorial.org}}\\National Mission on Education + through ICT\\{\color{blue}\url{http://sakshat.ac.in}} \\ [0.8cm]Script by: Hardik Ghaghada \\Narration by: \\ [0.7cm] +{\small 15 May 2013}} + +% slide 1 +\begin{frame} + \titlepage +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Objectives} + By the end of this tutorial, you will, +\begin{itemize} +\item Learn about graph theory using Sage +\item Learn about number theory using Sage +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Summary} +In this tutorial, we have learnt to, +\begin{itemize} +\item Create Both a simple graph and a directed graph, using the functions +graph() and DiGraph() respectively +\item Create a complete graph using CompleteGraph() function +\item Use functions like primes_range(), factor(), Permutations(), +Combinations() +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Evaluation} +\begin{enumerate} +\item Find Permutations for the list ['a', 'b', 'c', 'd'] +\item List all the primes between 2009 and 2900 including 2900 +\end{enumerate} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Solutions} +\begin{enumerate} +\item C = Permutations(['a', 'b', 'c', 'd']) +\item prime_range(2009, 2901) +\end{enumerate} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{FOSSEE} +{\color{blue}Free and Open-source Software for \\Science and Engineering Education} \\ +\begin{itemize} +\item Goal - enabling all to use open source software tools +\item For more details, please visit {\color{blue}\url{http://fossee.in/}} +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{About the Spoken Tutorial Project} +\begin{itemize} +\item Watch the video available at {\color{blue}\url{http://spoken-tutorial.org /What\_is\_a\_Spoken\_Tutorial}} +\item It summarises the Spoken Tutorial project +\item If you do not have good bandwidth, you can download and watch it +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Spoken Tutorial Workshops}The Spoken Tutorial Project Team +\begin{itemize} +\item Conducts workshops using spoken tutorials +\item Gives certificates to those who pass an online test +\item For more details, please write to \\ \hspace {0.5cm}{\color{blue}contact@spoken-tutorial.org} +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} +\frametitle{Acknowledgements} +\begin{itemize} +\item Spoken Tutorial Project is a part of the Talk to a Teacher project +\item It is supported by the National Mission on Education through ICT, MHRD, Government of India +\item More information on this Mission is available at: \\{\color{blue}\url{http://spoken-tutorial.org/NMEICT-Intro}} +\end{itemize} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{frame} + \begin{block}{} + \begin{center} + \textcolor{blue}{\Large THANK YOU!} + \end{center} + \end{block} +\begin{block}{} + \begin{center} + For more Information, visit our website\\ + \url{http://fossee.in/} + \end{center} + \end{block} +\end{frame} +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\end{document} |