summary |
shortlog |
changelog |
graph |
tags |
bookmarks |
branches |
files |
changeset |
raw | zip | gz | bz2 |
help

author | Amit Sethi |

Thu, 11 Nov 2010 17:28:23 +0530 | |

changeset 468 | ac1198488c0e |

parent 467 | 501383b753c1 (current diff) |

parent 465 | 78d20cd87c7e (diff) |

child 484 | a1828587a617 |

child 485 | fd3902300f20 |

Merging heads

--- a/advanced-features-functions/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/advanced-features-functions/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -19,6 +19,7 @@ .. Author : Puneeth Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> External Reviewer : + Language Reviewer : Bhanukiran Checklist OK? : <put date stamp here, if OK> [2010-10-05] Script

--- a/getting-started-sagenotebook/quickref.tex Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-sagenotebook/quickref.tex Thu Nov 11 17:28:23 2010 +0530 @@ -1,8 +0,0 @@ -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)|}

--- a/getting-started-sagenotebook/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-sagenotebook/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -14,7 +14,7 @@ .. #. Be able to evaluate cells, create and delete cells, navigate them. .. #. Be able to make annotations in the worksheet .. #. Be able to use tab completion. -.. #. Be able to use code from other languages in the cells. +.. #. Be able to use code from other languages in the cells. .. Prerequisites .. ------------- @@ -30,10 +30,10 @@ Script ------ +{{{ Show the slide containing the title }}} + Hello friends. Welcome to this spoken tutorial on Getting started with -sage and sage notebook. - -{{{ Show the slide containing the title }}} +Sage and Sage notebook. {{{ Show the slide containing the outline }}} @@ -57,9 +57,10 @@ We are assuming that you have Sage installed on your computer now. If not please visit the page http://sagemath.org/doc/tutorial/introduction.html#installation for -the tutorial on how to install Sage. Let us move on now. +the tutorial on how to install Sage. -On the terminal type:: + +Let us now learn how to start Sage. On the terminal type:: sage @@ -81,8 +82,8 @@ {{{ Intentional *cough* *cough* }}} to use Sage and nothing else! The Sage notebook also provides a -convenient way of sharing and publishing our work which is very handy -when we use Sage for research or for teaching. +convenient way of sharing and publishing our work, which is very handy +for research and teaching. However we can also run our own instances of Sage notebook servers on all the computers we have a local installation of Sage. To start the @@ -319,5 +320,3 @@ Hope you have enjoyed and found it useful. Thank you! - -

--- a/getting-started-sagenotebook/slides.org Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-sagenotebook/slides.org Thu Nov 11 17:28:23 2010 +0530 @@ -18,7 +18,7 @@ #+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, #+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} -#+TITLE: Accessing parts of arrays +#+TITLE: Getting started -- Sage #+AUTHOR: FOSSEE #+EMAIL: #+DATE: @@ -30,81 +30,38 @@ #+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc * Outline - - Manipulating one and multi dimensional arrays - - Access and change individual elements - - Access and change rows and columns - - Slicing and striding on arrays to access chunks - - Read images into arrays and manipulations -* Sample Arrays - #+begin_src python - In []: A = array([12, 23, 34, 45, 56]) - - In []: C = array([[11, 12, 13, 14, 15], - [21, 22, 23, 24, 25], - [31, 32, 33, 34, 35], - [41, 42, 43, 44, 45], - [51, 52, 53, 54, 55]]) - - #+end_src -* Question 1 - Change the last column of ~C~ to zeroes. -* Solution 1 - #+begin_src python - In []: C[:, -1] = 0 - #+end_src -* Question 2 - Change ~A~ to ~[11, 12, 13, 14, 15]~. -* Solution 2 - #+begin_src python - In []: A[:] = [11, 12, 13, 14, 15] - #+end_src -* squares.png - #+begin_latex - \begin{center} - \includegraphics[scale=0.6]{squares} - \end{center} - #+end_latex -* Question 3 - - obtain ~[22, 23]~ from ~C~. - - obtain ~[11, 21, 31, 41]~ from ~C~. - - obtain ~[21, 31, 41, 0]~. -* Solution 3 - #+begin_src python - In []: C[1, 1:3] - In []: C[0:4, 0] - In []: C[1:5, 0] - #+end_src -* Question 4 - Obtain ~[[23, 24], [33, -34]]~ from ~C~ -* Solution 4 - #+begin_src python - In []: C[1:3, 2:4] - #+end_src -* Question 5 - Obtain the square in the center of the image -* Solution 5 - #+begin_src python - In []: imshow(I[75:225, 75:225]) - #+end_src -* Question 6 - Obtain the following - #+begin_src python - [[12, 0], [42, 0]] - [[12, 13, 14], [0, 0, 0]] - #+end_src - -* Solution 6 - #+begin_src python - In []: C[::3, 1::3] - In []: C[::4, 1:4] - #+end_src + - Know what Sage and Sage notebook are. + - Be able to start a Sage shell or notebook + - Be able to start using the notebook + - Be able to create new worksheets + - Know about the menu options available + - Know about the cells in the worksheet + - Be able to evaluate cells, create and delete cells, navigate them. + - Be able to make annotations in the worksheet + - Be able to use tab completion. + - Be able to use code from other languages in the cells. +* What is Sage? + - free, open-source mathematical software. + - can do a lot of math for you, including, but not limited to + + algebra + + geometry + + cryptography + + graph theory + - can be used as aid in teaching and research * Summary - You should now be able to -- - - Manipulate 1D \& Multi dimensional arrays - - Access and change individual elements - - Access and change rows and columns - - Slice and stride on arrays - - Read images into arrays and manipulate them. + + What is Sage + + How to start Sage shell + + What is Sage notebook + + How to start the Sage notebook + + How to create accounts and start using the notebook + + How to create new worksheets + + The menus available on the notebook + + About cells in the worksheet + + Methods to evaluate the cell, create new cells, delete the cells + and navigate around the cells + + To make annotations in the worksheet + + Tab completions + + And embedding code of other scripting languages in the cells * Thank you! #+begin_latex \begin{block}{}

--- a/getting-started-sagenotebook/slides.tex Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-sagenotebook/slides.tex Thu Nov 11 17:28:23 2010 +0530 @@ -1,95 +1,104 @@ -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%Tutorial slides on Python. -% -% Author: FOSSEE -% Copyright (c) 2009, FOSSEE, IIT Bombay -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% - -\documentclass[14pt,compress]{beamer} -%\documentclass[draft]{beamer} -%\documentclass[compress,handout]{beamer} -%\usepackage{pgfpages} -%\pgfpagesuselayout{2 on 1}[a4paper,border shrink=5mm] - -% Modified from: generic-ornate-15min-45min.de.tex -\mode<presentation> -{ - \usetheme{Warsaw} - \useoutertheme{infolines} - \setbeamercovered{transparent} -} - -\usepackage[english]{babel} +% Created 2010-11-11 Thu 02:40 +\documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} -%\usepackage{times} \usepackage[T1]{fontenc} - -\usepackage{ae,aecompl} -\usepackage{mathpazo,courier,euler} -\usepackage[scaled=.95]{helvet} +\usepackage{fixltx2e} +\usepackage{graphicx} +\usepackage{longtable} +\usepackage{float} +\usepackage{wrapfig} +\usepackage{soul} +\usepackage{textcomp} +\usepackage{marvosym} +\usepackage{wasysym} +\usepackage{latexsym} +\usepackage{amssymb} +\usepackage{hyperref} +\tolerance=1000 +\usepackage[english]{babel} \usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} +\usepackage{listings} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} -\definecolor{darkgreen}{rgb}{0,0.5,0} - -\usepackage{listings} -\lstset{language=Python, - basicstyle=\ttfamily\bfseries, - commentstyle=\color{red}\itshape, - stringstyle=\color{darkgreen}, - showstringspaces=false, - keywordstyle=\color{blue}\bfseries} - -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -% Macros -\setbeamercolor{emphbar}{bg=blue!20, fg=black} -\newcommand{\emphbar}[1] -{\begin{beamercolorbox}[rounded=true]{emphbar} - {#1} - \end{beamercolorbox} -} -\newcounter{time} -\setcounter{time}{0} -\newcommand{\inctime}[1]{\addtocounter{time}{#1}{\tiny \thetime\ m}} - -\newcommand{\typ}[1]{\lstinline{#1}} - -\newcommand{\kwrd}[1]{ \texttt{\textbf{\color{blue}{#1}}} } - -% Title page -\title{Your Title Here} - -\author[FOSSEE] {FOSSEE} - -\institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} +\title{Getting started -- Sage} +\author{FOSSEE} \date{} -% DOCUMENT STARTS +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} +\maketitle + + + + + + + + + \begin{frame} - \maketitle -\end{frame} +\frametitle{Outline} +\label{sec-1} -\begin{frame}[fragile] - \frametitle{Outline} - \begin{itemize} - \item - \end{itemize} +\begin{itemize} +\item Know what Sage and Sage notebook are. +\item Be able to start a Sage shell or notebook +\item Be able to start using the notebook +\item Be able to create new worksheets +\item Know about the menu options available +\item Know about the cells in the worksheet +\item Be able to evaluate cells, create and delete cells, navigate them. +\item Be able to make annotations in the worksheet +\item Be able to use tab completion. +\item Be able to use code from other languages in the cells. +\end{itemize} \end{frame} +\begin{frame} +\frametitle{What is Sage?} +\label{sec-2} + +\begin{itemize} +\item free, open-source mathematical software. +\item can do a lot of math for you, including, but not limited to -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% -%% All other slides here. %% -%% The same slides will be used in a classroom setting. %% -%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +\begin{itemize} +\item algebra +\item geometry +\item cryptography +\item graph theory +\end{itemize} + +\item can be used as aid in teaching and research +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-3} -\begin{frame}[fragile] - \frametitle{Summary} - \begin{itemize} - \item - \end{itemize} +\begin{itemize} +\item What is Sage +\item How to start Sage shell +\item What is Sage notebook +\item How to start the Sage notebook +\item How to create accounts and start using the notebook +\item How to create new worksheets +\item The menus available on the notebook +\item About cells in the worksheet +\item Methods to evaluate the cell, create new cells, delete the cells + and navigate around the cells +\item To make annotations in the worksheet +\item Tab completions +\item And embedding code of other scripting languages in the cells +\end{itemize} \end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-4} -\begin{frame} - \frametitle{Thank you!} \begin{block}{} \begin{center} This spoken tutorial has been produced by the

--- a/getting-started-with-functions/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-with-functions/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -32,29 +32,29 @@ {{{ show welcome slide }}} -Hello and welcome to the tutorial getting started with functions. +Hello and welcome to the tutorial, getting started with functions. {{{ switch to next slide, outline slide }}} In this tutorial we will learn about functions in python, how to -define functions, arguments to functions, docstrings, and function -return value. +define functions, passing arguments to functions, docstrings, and +function return value. {{{ switch to next slide, Function }}} -While writing code, we always want to reduce the number of lines of -code and functions is a way of reusing the code. Thus the same lines -of code can be used again and again. A function is a portion of code -within a larger program that performs a specific task and is -relatively independent of the remaining code. Now let us get more -familiar with functions, +While writing code, we would like to reduce the number of lines of +code and using functions is a way of reusing the code. A function is +a portion of code within a larger program that performs a specific +task and is relatively independent of the remaining code. Now let us +get more familiar with functions, {{{ switch to next slide, f(x) a mathematical function }}} -Consider a mathematical function f(x) = x square. Here x is a variable -and with different values of x the value of function will change. When -x is one f(1) will return the value 1 and f(2) will return us the -value 4. Let us now see how to define the function f(x) in python. +Consider a mathematical function f(x) = x squared. Here x is a +variable and with different values of x the value of function will +change. When x is one f(1) will return the value 1 and f(2) will +return us the value 4. Let us now see how to define the function f(x) +in Python. {{{ switch to next slide, define f(x) in Python }}} @@ -64,18 +64,22 @@ def f(x): return x*x -Well that defined the function, so before learning what we did let us -see if it returns the expected values, try, +Let us see, if the function ``f``, we defined, works as we expect. :: f(1) f(2) -Yes, it returned 1 and 2 respectively. And now let us see what we did, -we wrote two lines. The first line ``def f(x)`` is used to define the -name and the parameters to the function. ``def`` is a keyword and -``f`` is the name of the function and ``x`` the parameter of the -function. +Yes, it returned 1 and 2 respectively. + +Now, let us see what we did. The first line ``def f(x)`` is used to +define the name and the parameters to the function. ``def`` is a +keyword and ``f`` is the name of the function and ``x`` the parameter +of the function. + +The second line is the body of the function. Incidentally, this +function has a single line definition. Note that the body of the +function is indented, just like any other code block, in Python. {{{ switch to next slide, problem statement 1 }}} @@ -92,18 +96,18 @@ def cube(n): return n**3 -And now let us see how to write functions without arguments. +Now let us see how to write functions without arguments. {{{ switch to next slide, greet function }}} -let us define a new function called ``greet`` which will print ``Hello +Let us define a new function called ``greet`` which will print ``Hello World``. :: def greet(): print "Hello World!" -now try calling the function, +Now try calling the function, :: greet() @@ -123,7 +127,7 @@ {{{ switch to next slide, solution 2 }}} -The problem can be solved as, +The problem can be solved as shown, :: def avg(a,b): @@ -137,8 +141,8 @@ It is always a good practice to document the code that we write, and for a function we define we should write an abstract of what the -function does, and that is called a docstring. Let us modify the -function ``avg`` and add docstring to it. Do the following, +function does, and that is called a doc-string. Let us modify the +function ``avg`` and add doc-string to it. Do the following, :: def avg(a,b): @@ -146,7 +150,7 @@ returns the average of a and b""" return (a+b)/2 -Note that docstrings are entered in the immediate line after the +Note that doc-strings are entered in the immediate line after the function definition and put as a triple quoted string. And here as far as the code functionality is concerned, we didn't do anything. We just added an abstract of what the function does. @@ -286,6 +290,9 @@ We also did few code reading exercises. -{{{ switch to next slide, Thank you }}} +{{{ Show the "sponsored by FOSSEE" slide }}} +This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India + +Hope you have enjoyed and found it useful. Thank you!

--- a/getting-started-with-symbolics/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-with-symbolics/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -25,66 +25,65 @@ Symbolics with Sage ------------------- -Hello friends and welcome to the tutorial on symbolics with sage. +Hello friends and welcome to the tutorial on Symbolics with Sage. {{{ Show welcome slide }}} - -.. #[Madhu: What is this line doing here. I don't see much use of it] - During the course of the tutorial we will learn {{{ Show outline slide }}} -* Defining symbolic expressions in sage. +* Defining symbolic expressions in Sage. * Using built-in constants and functions. -* Performing Integration, differentiation using sage. +* Performing Integration, differentiation using Sage. * Defining matrices. -* Defining Symbolic functions. +* Defining symbolic functions. * Simplifying and solving symbolic expressions and functions. -We can use Sage for symbolic maths. +Amongst a lot of other things, Sage can do Symbolic Math and we shall +start with defining symbolic expressions in Sage. + +Hope you have your Sage notebook open. If not, pause the video and +start you Sage notebook. On the sage notebook type:: sin(y) -It raises a name error saying that y is not defined. But in sage we -can declare y as a symbol using var function. +It raises a name error saying that ``y`` is not defined. We need to +declare ``y`` as a symbol. We do it using the ``var`` function. +:: - -:: var('y') Now if you type:: sin(y) -sage simply returns the expression. - +Sage simply returns the expression. -Thus sage treats sin(y) as a symbolic expression . We can use -this to do symbolic maths using sage's built-in constants and -expressions.. +Sage treats ``sin(y)`` as a symbolic expression. We can use this to do +symbolic maths using Sage's built-in constants and expressions. - -So let us try :: +Let us try out a few examples. :: var('x,alpha,y,beta') x^2/alpha^2+y^2/beta^2 + +We have defined 4 variables, ``x``, ``y``, ``alpha`` and ``beta`` and +have defined a symbolic expression using them. -taking another example :: +Here is an expression in ``theta`` :: var('theta') sin(theta)*sin(theta)+cos(theta)*cos(theta) -Similarly, we can define many algebraic and trigonometric expressions using sage . - +Now that you know how to define symbolic expressions in Sage, here is +an exercise. -Following is an exercise that you must do. +{{ show slide showing question 1 }} -%% %% Define following expressions as symbolic expressions -in sage? +%% %% Define following expressions as symbolic expressions in Sage. 1. x^2+y^2 #. y^2-4ax @@ -93,42 +92,37 @@ The solution is on your screen. - -Sage also provides a few built-in constants which are commonly used in mathematics . - -example : pi,e,infinity , Function n gives the numerical values of all these constants. +{{ show slide showing solution 1 }} -{{{ Type n(pi) n(e) n(oo) On the sage notebook }}} - - - -If you look into the documentation of function "n" by doing - -.. #[Madhu: "documentation of the function "n"?] +Sage also provides built-in constants which are commonly used in +mathematics, for instance pi, e, infinity. The function ``n`` gives +the numerical values of all these constants. +:: + n(pi) + n(e) + n(oo) + +If you look into the documentation of function ``n`` by doing :: n(<Tab> -You will see what all arguments it takes and what it returns. It will be very -helpful if you look at the documentation of all functions introduced through -this script. - - +You will see what all arguments it takes and what it returns. It will +be very helpful if you look at the documentation of all functions +introduced in the course of this script. -Also we can define the no. of digits we wish to use in the numerical -value . For this we have to pass an argument digits. Type +Also we can define the number of digits we wish to have in the +constants. For this we have to pass an argument -- digits. Type -.. #[Madhu: "no of digits"? Also "We wish to obtain" than "we wish to - use"?] :: n(pi, digits = 10) -Apart from the constants sage also has a lot of builtin functions like -sin,cos,log,factorial,gamma,exp,arcsin etc ... -lets try some of them out on the sage notebook. +Apart from the constants Sage also has a lot of built-in functions +like ``sin``, ``cos``, ``log``, ``factorial``, ``gamma``, ``exp``, +``arcsin`` etc ... - +Lets try some of them out on the Sage notebook. :: sin(pi/2) @@ -137,9 +131,12 @@ log(e,e) -Following is are exercises that you must do. +Following are exercises that you must do. -%% %% Find the values of the following constants upto 6 digits precision +{{ show slide showing question 2 }} + +%% %% Find the values of the following constants upto 6 digits + precision 1. pi^2 #. euler_gamma^2 @@ -150,19 +147,18 @@ 1. sin(pi/4) #. ln(23) -Please, pause the video here. Do the exercises and then continue. +Please, pause the video here. Do the exercises and then continue. -The solutions are on your screen. +The solutions are on your screen - +{{ show slide showing solution 2 }} -Given that we have defined variables like x,y etc .. , We can define -an arbitrary function with desired name in the following way.:: +Given that we have defined variables like x, y etc., we can define an +arbitrary function with desired name in the following way.:: var('x') function('f',x) - Here f is the name of the function and x is the independent variable . Now we can define f(x) to be :: @@ -174,29 +170,18 @@ We can also define functions that are not continuous but defined piecewise. Let us define a function which is a parabola between 0 -to 1 and a constant from 1 to 2 . Type the following as given on the -screen - +to 1 and a constant from 1 to 2 . Type the following :: var('x') h(x)=x^2 g(x)=1 - f=Piecewise(<Tab> -{{{ Show the documentation of Piecewise }}} - -:: f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f - - - - -We can also define functions which are series - +We can also define functions convergent series and other series. We first define a function f(n) in the way discussed above.:: @@ -221,11 +206,11 @@ f(n) = (-1)^(n-1)*1/(2*n - 1) sum(f(n), n, 1, oo) - This series converges to pi/4. +Following are exercises that you must do. -Following are exercises that you must do. +{{ show slide showing question 3 }} %% %% Define the piecewise function. f(x)=3x+2 @@ -237,14 +222,15 @@ Please, pause the video here. Do the exercise(s) and then continue. +{{ show slide showing solution 3 }} + Moving on let us see how to perform simple calculus operations using Sage For example lets try an expression first :: diff(x**2+sin(x),x) - 2x+cos(x) -The diff function differentiates an expression or a function. Its +The diff function differentiates an expression or a function. It's first argument is expression or function and second argument is the independent variable. @@ -256,44 +242,40 @@ To get a higher order differential we need to add an extra third argument for order :: - diff(<tab> diff(f(x),x,3) + diff(f(x),x,3) in this case it is 3. - Just like differentiation of expression you can also integrate them :: x = var('x') s = integral(1/(1 + (tan(x))**2),x) s - - -Many a times we need to find factors of an expression ,we can use the "factor" function +Many a times we need to find factors of an expression, we can use the +"factor" function :: - factor(<tab> + y = (x^100 - x^70)*(cos(x)^2 + cos(x)^2*tan(x)^2) f = factor(y) -One can simplify complicated expression :: +One can simplify complicated expression :: f.simplify_full() -This simplifies the expression fully . We can also do simplification -of just the algebraic part and the trigonometric part :: +This simplifies the expression fully. We can also do simplification of +just the algebraic part and the trigonometric part :: f.simplify_exp() f.simplify_trig() - - -One can also find roots of an equation by using find_root function:: +One can also find roots of an equation by using ``find_root`` function:: phi = var('phi') find_root(cos(phi)==sin(phi),0,pi/2) -Lets substitute this solution into the equation and see we were +Let's substitute this solution into the equation and see we were correct :: var('phi') @@ -322,18 +304,13 @@ Please, pause the video here. Do the exercises and then continue. - Lets us now try some matrix algebra symbolically :: - - var('a,b,c,d') A=matrix([[a,1,0],[0,b,0],[0,c,d]]) A Now lets do some of the matrix operations on this matrix - - :: A.det() A.inverse() @@ -348,17 +325,15 @@ Please, pause the video here. Do the exercise(s) and then continue. - - {{{ Show the summary slide }}} -So in this tutorial we learnt how to - +That brings us to the end of this tutorial. In this tutorial we learnt +how to -* We learnt about defining symbolic expression and functions. -* Using built-in constants and functions. -* Using <Tab> to see the documentation of a function. -* Simple calculus operations . -* Substituting values in expression using substitute function. -* Creating symbolic matrices and performing operation on them . +* define symbolic expression and functions +* use built-in constants and functions +* use <Tab> to see the documentation of a function +* do simple calculus +* substitute values in expressions using ``substitute`` function +* create symbolic matrices and perform operations on them

--- a/getting-started-with-symbolics/slides.org Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-with-symbolics/slides.org Thu Nov 11 17:28:23 2010 +0530 @@ -37,14 +37,14 @@ - Defining Symbolic functions. - Simplifying and solving symbolic expressions and functions. -* Questions 1 +* Question 1 - Define the following expression as symbolic expression in sage. - x^2+y^2 - y^2-4ax -* Solutions 1 +* Solution 1 #+begin_src python var('x,y') x^2+y^2 @@ -52,10 +52,11 @@ var('a,x,y') y^2-4*a*x #+end_src python -* Questions 2 +* Question 2 - Find the values of the following constants upto 6 digits precision - pi^2 + - euler_gamma^2 - Find the value of the following. @@ -63,13 +64,13 @@ - sin(pi/4) - ln(23) -* Solutions 2 +* Solution 2 #+begin_src python n(pi^2,digits=6) n(sin(pi/4)) n(log(23,e)) #+end_src python -* Question 2 +* Question 3 - Define the piecewise function. f(x)=3x+2 when x is in the closed interval 0 to 4. @@ -78,7 +79,7 @@ - Sum of 1/(n^2-1) where n ranges from 1 to infinity. -* Solution Q1 +* Solution 3 #+begin_src python var('x') h(x)=3*x+2 @@ -86,18 +87,18 @@ f=Piecewise([[(0,4),h(x)],[(4,6),g(x)]],x) f #+end_src python -* Solution Q2 + #+begin_src python var('n') f=1/(n^2-1) sum(f(n), n, 1, oo) #+end_src python - -* Questions 3 +* Question 4 - Differentiate the following. - - x^5*log(x^7) , degree=4 + - sin(x^3)+log(3x), to the second order + - x^5*log(x^7), to the fourth order - Integrate the given expression @@ -107,7 +108,7 @@ - cos(x^2)-log(x)=0 - Does the equation have a root between 1,2. -* Solutions 3 +* Solution 4 #+begin_src python var('x') f(x)= x^5*log(x^7) @@ -121,12 +122,12 @@ find_root(f(x)==0,1,2) #+end_src -* Question 4 +* Question 5 - Find the determinant and inverse of : A=[[x,0,1][y,1,0][z,0,y]] -* Solution 4 +* Solution 5 #+begin_src python var('x,y,z') A=matrix([[x,0,1],[y,1,0],[z,0,y]]) @@ -134,19 +135,12 @@ A.inverse() #+end_src * Summary - - We learnt about defining symbolic - expression and functions. - - Using built-in constants and functions. - - Using <Tab> to see the documentation of a - function. - -* Summary - - Simple calculus operations . - - Substituting values in expression - using substitute function. - - Creating symbolic matrices and - performing operation on them . - + - We learnt about defining symbolic expression and functions. + - Using built-in constants and functions. + - Using <Tab> to see the documentation of a function. + - Simple calculus operations . + - Substituting values in expression using substitute function. + - Creating symbolic matrices and performing operation on them . * Thank you! #+begin_latex \begin{block}{}

--- a/getting-started-with-symbolics/slides.tex Thu Nov 11 13:21:10 2010 +0530 +++ b/getting-started-with-symbolics/slides.tex Thu Nov 11 17:28:23 2010 +0530 @@ -1,4 +1,4 @@ -% Created 2010-11-10 Wed 17:18 +% Created 2010-11-11 Thu 02:03 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -8,7 +8,6 @@ \usepackage{float} \usepackage{wrapfig} \usepackage{soul} -\usepackage{t1enc} \usepackage{textcomp} \usepackage{marvosym} \usepackage{wasysym} @@ -55,7 +54,7 @@ \end{itemize} \end{frame} \begin{frame} -\frametitle{Questions 1} +\frametitle{Question 1} \label{sec-2} \begin{itemize} @@ -72,28 +71,34 @@ \end{frame} \begin{frame}[fragile] -\frametitle{Solutions 1} +\frametitle{Solution 1} \label{sec-3} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} var('x,y') x^2+y^2 var('a,x,y') y^2-4*a*x -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} -\frametitle{Questions 2} +\frametitle{Question 2} \label{sec-4} + \begin{itemize} \item Find the values of the following constants upto 6 digits precision \begin{itemize} \item pi$^2$ +\item euler$_{\mathrm{gamma}}$$^2$ \end{itemize} +\end{itemize} + +\begin{itemize} \item Find the value of the following. \begin{itemize} @@ -104,17 +109,18 @@ \end{itemize} \end{frame} \begin{frame}[fragile] -\frametitle{Solutions 2} +\frametitle{Solution 2} \label{sec-5} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} n(pi^2,digits=6) n(sin(pi/4)) n(log(23,e)) -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} -\frametitle{Question 2} +\frametitle{Question 3} \label{sec-6} \begin{itemize} @@ -127,37 +133,35 @@ \end{itemize} \end{frame} \begin{frame}[fragile] -\frametitle{Solution Q1} +\frametitle{Solution 3} \label{sec-7} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} var('x') h(x)=3*x+2 g(x)= 4*x^2 f=Piecewise([[(0,4),h(x)],[(4,6),g(x)]],x) f -\end{verbatim} -\end{frame} -\begin{frame}[fragile] -\frametitle{Solution Q2} -\label{sec-8} +\end{lstlisting} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} var('n') f=1/(n^2-1) sum(f(n), n, 1, oo) -\end{verbatim} - +\end{lstlisting} \end{frame} \begin{frame} -\frametitle{Questions 3} -\label{sec-9} +\frametitle{Question 4} +\label{sec-8} \begin{itemize} \item Differentiate the following. \begin{itemize} -\item x$^5$*log(x$^7$) , degree=4 +\item sin(x$^3$)+log(3x), to the second order +\item x$^5$*log(x$^7$), to the fourth order \end{itemize} \item Integrate the given expression @@ -176,10 +180,11 @@ \end{itemize} \end{frame} \begin{frame}[fragile] -\frametitle{Solutions 3} -\label{sec-10} +\frametitle{Solution 4} +\label{sec-9} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} var('x') f(x)= x^5*log(x^7) diff(f(x),x,5) @@ -190,11 +195,11 @@ var('x') f=cos(x^2)-log(x) find_root(f(x)==0,1,2) -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} -\frametitle{Question 4} -\label{sec-11} +\frametitle{Question 5} +\label{sec-10} \begin{itemize} \item Find the determinant and inverse of : @@ -203,45 +208,33 @@ \end{itemize} \end{frame} \begin{frame}[fragile] -\frametitle{Solution 4} -\label{sec-12} +\frametitle{Solution 5} +\label{sec-11} -\begin{verbatim} +\lstset{language=Python} +\begin{lstlisting} var('x,y,z') A=matrix([[x,0,1],[y,1,0],[z,0,y]]) A.det() A.inverse() -\end{verbatim} +\end{lstlisting} \end{frame} \begin{frame} \frametitle{Summary} -\label{sec-13} +\label{sec-12} \begin{itemize} -\item We learnt about defining symbolic - expression and functions. +\item We learnt about defining symbolic expression and functions. \item Using built-in constants and functions. -\item Using <Tab> to see the documentation of a - function. -\end{itemize} - - -\end{frame} -\begin{frame} -\frametitle{Summary} -\label{sec-14} - -\begin{itemize} +\item Using <Tab> to see the documentation of a function. \item Simple calculus operations . -\item Substituting values in expression - using substitute function. -\item Creating symbolic matrices and - performing operation on them . +\item Substituting values in expression using substitute function. +\item Creating symbolic matrices and performing operation on them . \end{itemize} \end{frame} \begin{frame} \frametitle{Thank you!} -\label{sec-15} +\label{sec-13} \begin{block}{} \begin{center}

--- a/loops/questions.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/loops/questions.rst Thu Nov 11 17:28:23 2010 +0530 @@ -15,9 +15,10 @@ #. tuples #. all of the above -.. I was not sure of how to frame this question. Can someone fix it? + Answer: all of the above - Answer: all of the above +.. I was not sure of how to frame this question. Can someone fix it? +.. #[bhanu: it works for every `sequence` or an iterator for that matter right?] #. ``x = range(20)``. What is x? @@ -85,7 +86,7 @@ Answer: Nothing is printed -.. #[[Anoop: I think more questions on while loop has to be added as +.. #[[Anoop: I think more questions on while loop have to be added as for loop was already covered in another LO, these questions can be kept, but it will good if we add few more on while loop]] @@ -95,4 +96,7 @@ 1. A number is called Armstrong number if the sum of cubes of its digits is equal to the number itself. Find all the three digit Armstrong numbers. -.. #[[Anoop: Add one more question]] +2. Collatz sequence - Given a number ``n``, multiply by 3 and add 1 to + it, if it is odd, otherwise divide it by two. With whatever ``n`` + we start with, we finally end with the sequence 4, 2, 1. Write a + program to print this, given some number ``n``.

--- a/loops/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/loops/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -19,6 +19,7 @@ .. Author : Puneeth Internal Reviewer : Anoop Jacob Thomas<anoop@fossee.in> External Reviewer : + Langauge Reviewer : Bhanukiran Checklist OK? : <put date stamp here, if OK> [2010-10-05] Script

--- a/manipulating-strings/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/manipulating-strings/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -19,7 +19,8 @@ .. Author : Puneeth Internal Reviewer : Amit External Reviewer : - Checklist OK? : <put date stamp here, if OK> [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <08-11-2010, Anand, OK> [2010-10-05] Script ------ @@ -90,8 +91,8 @@ s[1:-1] -gives the a substring of s, without the first and the last -characters. +gives the substring of s, without the first and the last +characters of s. ::

--- a/progress.org Thu Nov 11 13:21:10 2010 +0530 +++ b/progress.org Thu Nov 11 17:28:23 2010 +0530 @@ -27,10 +27,10 @@ | 4.4 LO: | Least square fit | 2 | Nishanth | Punch (Done) | | | 4.5 LO: | Assessment | 3 | Punch | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| -| 5.1 LO: | getting started with sage notebook | 3 | Madhu | | | -| 5.2 LO: | getting started with symbolics | 3 | Amit | Pending | | +| 5.1 LO: | getting started with sage notebook | 3 | Madhu | Punch (Done) | | +| 5.2 LO: | getting started with symbolics | 3 | Amit | Punch (Done) | | | 5.3 LO: | using Sage | 4 | Punch | Anoop (Done) | | -| 5.4 LO: | using sage to teach | 3 | Nishanth | | | +| 5.4 LO: | using sage to teach | 3 | Nishanth | Punch (Done) | | | 5.5 LO: | Assessment | 3 | Anoop | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| | 6.1 LO: | basic datatypes & operators | 4 | Amit | Punch (Done) | | @@ -46,7 +46,7 @@ | 7.5 LO: | sets | 2 | Nishanth | Punch (Done) | | | 7.6 LO: | Assessment | 3 | Amit | | | |---------+----------------------------------------+-------+----------+-----------------+-----------| -| 8.1 LO: | getting started with functions | 3 | Anoop | Pending | | +| 8.1 LO: | getting started with functions | 3 | Anoop | Punch (Done) | | | 8.2 LO: | advanced features of functions | 3 | Punch | Anoop (Done) | | | 8.3 LO: | using python modules | 3 | Anoop | Punch (Done) | | | 8.4 LO: | writing python scripts | 2 | Nishanth | | |

--- a/using_sage_to_teach/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/using_sage_to_teach/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -19,9 +19,9 @@ Script ------ -Hello friends and welcome to the tutorial on "Using SAGE to teach" +{{{ Show the slide containing title }}} -{{{ Show the slide containing title }}} +Hello friends and welcome to the tutorial on Using SAGE to teach {{{ Show the slide containing the outline slide }}} @@ -41,14 +41,14 @@ :: t = var('t') - p1 = plot( e^(-t/2) * sin(2*t), (t, 0, 15)) + p1 = plot(e^(-t/2) * sin(2*t), (t, 0, 15)) show(p1) Now if we want to reduce the damping factor even more, we would be using e^(-t/3). We can observe that every time we have to change, all we do is change something very small and re evaluate the cell. -This process can be automated using the ``@interact`` feature of SAGE. +This process can be simplified, using the ``@interact`` feature of SAGE. :: @@ -141,10 +141,10 @@ in the top right, we can see a button called ``publish``. Click on that and we get a confirmation page with an option for re publishing. -For now lets forget that opion and simply publish by cliking ``yes``. The +For now lets forget that option and simply publish by clicking ``yes``. The worksheet is now published. -Now lets signout and go to the sage notebook home. We see link to browse +Now lets sign out and go to the sage notebook home. We see link to browse published worksheets. Lets click on it and we can see the worksheet. This does not require login and anyone can view the worksheet. @@ -173,9 +173,8 @@ {{{ Show the "sponsored by FOSSEE" slide }}} -#[Nishanth]: Will add this line after all of us fix on one. This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thankyou +Thank you!

--- a/writing_python_scripts/questions.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/writing_python_scripts/questions.rst Thu Nov 11 17:28:23 2010 +0530 @@ -118,3 +118,29 @@ Hello World Hello Test + 7. Say, we wish to use the ``pi`` value from the ``math`` module in + the standard library. How do we import it? + + Answer: from math import pi OR import math.pi OR + import math.pi as pi + + + 8. A module should contain only functions, True or False? + + Answer: False. + + +Larger Questions +---------------- + +1. Look at the python documentation (from the web) and learn how to + make a folder containing some python files into a module. + + Answer: Add a file named __init__.py + +2. We know that ``sys.path`` has the paths in which Python checks for + a module, when it is imported. Suppose you have a package ``utils`` + in some location on your disk, which is not on the python path, how + will you import it? + + Answer: Append that path to the ``sys.path`` variable.

--- a/writing_python_scripts/script.rst Thu Nov 11 13:21:10 2010 +0530 +++ b/writing_python_scripts/script.rst Thu Nov 11 17:28:23 2010 +0530 @@ -19,19 +19,19 @@ Script ------ -Hello friends and welcome to the tutorial on "Writing Python scripts" +{{{ Show the slide containing title }}} -{{{ Show the slide containing title }}} +Hello friends and welcome to the tutorial on "Writing Python scripts" {{{ Show the slide containing the outline slide }}} In this tutorial, we shall learn - * How write Python scripts + * How to write Python scripts Often we will have to reuse the code that we haave written. We do that by writing functions. Functions are bundled into packages and are imported as and -required in the script. +when required in other scripts. Let us first write a function that computes the gcd of two numbers and save it in a script. @@ -58,16 +58,16 @@ else: print "The GCD function is wrong" -Let us save the file as script.py in /home/fossee/gcd_script.py +Let us save the file as script.py in ``/home/fossee/gcd_script.py`` -We shall run the script by doing +We shall run the script by typing :: $ python /home/fossee/gcd_script.py We can see that the script is executed and everything is fine. -What if we want to use the gcd function in some of our later scripts. This +What if we want to use the gcd function in some of our other scripts. This is also possible since every python file can be used as a module. But first, we shall understand what happens when you import a module. @@ -81,13 +81,14 @@ This is a list of locations where python searches for a module when it encounters an import statement. -hence when we just did =import sys=, python searches for a file named sys.py or -a folder named sys in all these locations one by one, until it finds one. +Hence, when we just did ``import sys``, python searches for a file +named sys.py or a folder named sys in all these locations one by one, +until it finds one. We can place our script in any one of these locations and can import it. -The first item in the list is an empty string which means the current working -directory is also searched. +The first item in the list is an empty string which means the current +working directory is also searched. Alternatively, we can also import the module if we are working in same directory where the script exists. @@ -103,9 +104,9 @@ But we want the test code to be executed only when the file is run as a python script and not when it is imported. -This is possible by using =__name__= variable. +This is possible by using ``__name__`` variable. -First we shall look at how to use the idiom and then understand how it works. +First, we shall look at how to use the idiom and then understand how it works. Go to the file and add :: @@ -128,11 +129,12 @@ We see that now the test code is not executed. -The __name__ variable is local to every module and it is equal to __main__ only -when the file is run as a script. +The ``__name__`` variable is local to every module and it is equal to +``__main__`` only when the file is run as a script. -hence all the code that goes after __name__ == "__main__" is executed only when -the file is run as a python script. +Hence, all the code that goes in to the if block, ``if __name__ == +"__main__":`` is executed only when the file is run as a python +script. {{{ Show summary slide }}} @@ -145,9 +147,8 @@ {{{ Show the "sponsored by FOSSEE" slide }}} -#[Nishanth]: Will add this line after all of us fix on one. This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India Hope you have enjoyed and found it useful. -Thankyou +Thank you!