# HG changeset patch # User Amit Sethi # Date 1289389794 -19800 # Node ID a9b71932cbfaf8d1aea641feb24163dde9feb2bf # Parent 430035b678f7fbc53f67a0323d9703dec537ba61 Added exercises and slides to getting started with symbolics diff -r 430035b678f7 -r a9b71932cbfa getting-started-with-lists/script.rst.orig --- a/getting-started-with-lists/script.rst.orig Wed Nov 10 12:23:40 2010 +0530 +++ b/getting-started-with-lists/script.rst.orig Wed Nov 10 17:19:54 2010 +0530 @@ -1,361 +1,224 @@ - - - - - - - - - - -
+As you can see you get the last element which is 1.234. -
-

Objective Questions

- -
    -
  1. How do you create an empty list?

    -
    -empty=[]
    -
    -
  2. -
  3. What is the most important property of sequence data types like lists?

    -

    The elements are in order and can be accessed by index numbers.

    -
  4. -
  5. Can you have a list inside a list ?

    -

    Yes,List can contain all the other data types, including list.

    -

    Example: -list_in_list=[2.3,[2,4,6],'string,'all datatypes can be there']

    -
  6. -
  7. What is the index number of the first element in a list?

    -

    0 -nonempty = ['spam', 'eggs', 100, 1.234] -nonempty[0]

    -
  8. -
  9. How would you access the end of a list without finding its length?

    -

    Using negative indices. We can the list from the end using negative indices.

    -

    :: -nonempty = ['spam', 'eggs', 100, 1.234] -nonempty[-1]

    -
  10. -
  11. What is the function to find the length of a list?

    -

    len

    -
  12. -
  13. Delete the last element from list sq=[5,4,3,2,1,0]

    -

    del(sq[-1])

    -
  14. -
  15. How many will you have to use remove function to remove all 6's from the given list sq=[2,5,6,7,6,4,6]?

    -

    3

    -
  16. -
-
-
-

Larger Questions

- -

1. Add all elemets of seq1=['e','f','g','h'] -to the sequence seq=['a','b','c','d']

-
    -
  1. Delete all elements of seq1=[3,5,6] from sequence -seq=[1,2,3,4,5,6,7,8,9]
  2. -
-
-
- - +In python negative indices are used to access elements from the end:: + + nonempty[-1] + nonempty[-2] + nonempty[-4] + +-1 gives the last element which is the 4th element , -2 second to last +and -4 gives the fourth from last element which is first element. + +We can append elements to the end of a list using append command. :: + + nonempty.append('onemore') + nonempty + nonempty.append(6) + nonempty + +Following are exercises that you must do. + +%% %% What is the syntax to get the element 'and' +in the list,listinlist ? + + +%% %% How would you get 'and' using negative indices? + +Please, pause the video here. Do the exercise and then continue. + +The solution is on your screen + + +As we can see non empty appends 'onemore' and 6 at the end. + +Using len function we can check the number of elements in the list +nonempty. In this case it 6 :: + + len(nonempty) + + + +Just like we can append elements to a list we can also remove them. +There are two ways of doing it. One is by using index. :: + + del(nonempty[1]) + + + +deletes the element at index 1, 'eggs' which is the second element of +the list. The other way is removing element by content. Lets say one +wishes to delete 100 from nonempty list the syntax of the command +should be + +.. #[[Anoop: let x = [1,2,1,3] + now x.remove(x[2]) + still x is [2,1,3] so that is not the way to remove + element by index, it removed first occurrence of 1(by + content) and not based on index, so make necessary + changes]] + +:: + + nonempty.remove(100) + +but what if there were two 100's. To check that lets do a small +experiment. :: + + nonempty.append('spam') + nonempty + nonempty.remove('spam') + nonempty + +If we check now we will see that the first occurence 'spam' is removed +thus remove removes the first occurence of the element in the sequence +and leaves others untouched. + + + + + +.. #[[Anoop: does it have two spams or two pythons?]] + +.. #[[Anoop: there are no exercises/solved problems in this script, + add them]] + +Following are exercises that you must do. + +%% %% Remove the third element from the list, listinlist. + +%% %% Remove 'and' from the list, listinlist. + +Please, pause the video here. Do the exercise and then continue. + + + +{{{Slide for Summary }}} + + +In this tutorial we came across a sequence data type called lists. :: + + * We learned how to create lists. + * How to access lists. + * Append elements to list. + * Delete Element from list. + * And Checking list length. + + + +{{{ show Sponsored by Fossee Slide }}} + +This tutorial was created as a part of FOSSEE project. + +I hope you found this tutorial useful. + +Thank You + +.. + * Author : Amit Sethi + * First Reviewer : + * Second Reviewer : Nishanth diff -r 430035b678f7 -r a9b71932cbfa getting-started-with-symbolics/script.rst --- a/getting-started-with-symbolics/script.rst Wed Nov 10 12:23:40 2010 +0530 +++ b/getting-started-with-symbolics/script.rst Wed Nov 10 17:19:54 2010 +0530 @@ -4,7 +4,7 @@ .. By the end of this tutorial, you will be able to .. 1. Defining symbolic expressions in sage. -.. # Using built-in costants and functions. +.. # Using built-in constants and functions. .. # Performing Integration, differentiation using sage. .. # Defining matrices. .. # Defining Symbolic functions. @@ -37,7 +37,7 @@ {{{ Show outline slide }}} * Defining symbolic expressions in sage. -* Using built-in costants and functions. +* Using built-in constants and functions. * Performing Integration, differentiation using sage. * Defining matrices. * Defining Symbolic functions. @@ -73,26 +73,32 @@ var('x,alpha,y,beta') x^2/alpha^2+y^2/beta^2 -taking another example +taking another example :: var('theta') - sin^2(theta)+cos^2(theta) - + sin(theta)*sin(theta)+cos(theta)*cos(theta) -Similarly, we can define many algebraic and trigonometric expressions -using sage . +Similarly, we can define many algebraic and trigonometric expressions using sage . -Sage also provides a few built-in constants which are commonly used in -mathematics . +Following is an exercise that you must do. -example : pi,e,infinity , Function n gives the numerical values of all these - constants. +%% %% Define following expressions as symbolic expressions +in sage? + + 1. x^2+y^2 + #. y^2-4ax + +Please, pause the video here. Do the exercise and then continue. -{{{ Type n(pi) - n(e) - n(oo) - On the sage notebook }}} +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. + +{{{ Type n(pi) n(e) n(oo) On the sage notebook }}} @@ -131,6 +137,24 @@ log(e,e) +Following is are exercises that you must do. + +%% %% Find the values of the following constants upto 6 digits precision + + 1. pi^2 + #. euler_gamma^2 + + +%% %% Find the value of the following. + + 1. sin(pi/4) + #. ln(23) + +Please, pause the video here. Do the exercises and then continue. + +The solutions are on your screen. + + Given that we have defined variables like x,y etc .. , We can define an arbitrary function with desired name in the following way.:: @@ -157,13 +181,16 @@ var('x') - h(x)=x^2 g(x)=1 + h(x)=x^2 + g(x)=1 f=Piecewise( {{{ Show the documentation of Piecewise }}} :: - f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f + f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) + f + @@ -184,9 +211,7 @@ var('n') function('f', n) - f(n) = 1/n^2 - sum(f(n), n, 1, oo) @@ -200,6 +225,18 @@ This series converges to pi/4. +Following are exercises that you must do. + +%% %% Define the piecewise function. + f(x)=3x+2 + when x is in the closed interval 0 to 4. + f(x)=4x^2 + between 4 to 6. + +%% %% Sum of 1/(n^2-1) where n ranges from 1 to infinity. + +Please, pause the video here. Do the exercise(s) and then continue. + Moving on let us see how to perform simple calculus operations using Sage For example lets try an expression first :: @@ -267,6 +304,22 @@ as we can see when we substitute the value the answer is almost = 0 showing the solution we got was correct. +Following is an (are) exercise(s) that you must do. + +%% %% Differentiate the following. + + 1. sin(x^3)+log(3x) , degree=2 + #. x^5*log(x^7) , degree=4 + +%% %% Integrate the given expression + + sin(x^2)+exp(x^3) + +%% %% Find x + cos(x^2)-log(x)=0 + Does the equation have a root between 1,2. + +Please, pause the video here. Do the exercises and then continue. @@ -286,8 +339,18 @@ A.inverse() +Following is an (are) exercise(s) that you must do. -{{{ Part of the notebook with summary }}} +%% %% Find the determinant and inverse of : + + A=[[x,0,1][y,1,0][z,0,y]] + +Please, pause the video here. Do the exercise(s) and then continue. + + + + +{{{ Show the summary slide }}} So in this tutorial we learnt how to diff -r 430035b678f7 -r a9b71932cbfa getting-started-with-symbolics/slides.org --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/getting-started-with-symbolics/slides.org Wed Nov 10 17:19:54 2010 +0530 @@ -0,0 +1,166 @@ +#+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: Getting started with symbolics +#+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 + +* Outline + - Defining symbolic expressions in sage. + - Using built-in constants and functions. + - Performing Integration, differentiation using sage. + - Defining matrices. + - Defining Symbolic functions. + - Simplifying and solving symbolic expressions and functions. + +* Questions 1 + - Define the following expression as symbolic + expression in sage. + + - x^2+y^2 + - y^2-4ax + +* Solutions 1 +#+begin_src python + var('x,y') + x^2+y^2 + + var('a,x,y') + y^2-4*a*x +#+end_src python +* Questions 2 + - Find the values of the following constants upto 6 digits precision + + - pi^2 + + + - Find the value of the following. + + - sin(pi/4) + - ln(23) + +* Solutions 2 +#+begin_src python + n(pi^2,digits=6) + n(sin(pi/4)) + n(log(23,e)) +#+end_src python +* Question 2 + - Define the piecewise function. + f(x)=3x+2 + when x is in the closed interval 0 to 4. + f(x)=4x^2 + between 4 to 6. + + - Sum of 1/(n^2-1) where n ranges from 1 to infinity. + +* Solution Q1 +#+begin_src python + 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_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 + - Differentiate the following. + + - x^5*log(x^7) , degree=4 + + - Integrate the given expression + + - x*sin(x^2) + + - Find x + - cos(x^2)-log(x)=0 + - Does the equation have a root between 1,2. + +* Solutions 3 +#+begin_src python + var('x') + f(x)= x^5*log(x^7) + diff(f(x),x,5) + + var('x') + integral(x*sin(x^2),x) + + var('x') + f=cos(x^2)-log(x) + find_root(f(x)==0,1,2) +#+end_src + +* Question 4 + - Find the determinant and inverse of : + + A=[[x,0,1][y,1,0][z,0,y]] + +* Solution 4 +#+begin_src python + var('x,y,z') + A=matrix([[x,0,1],[y,1,0],[z,0,y]]) + A.det() + A.inverse() +#+end_src +* Summary + - We learnt about defining symbolic + expression and functions. + - Using built-in constants and functions. + - Using 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 . + +* Thank you! +#+begin_latex + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +#+end_latex + + + diff -r 430035b678f7 -r a9b71932cbfa getting-started-with-symbolics/slides.tex --- a/getting-started-with-symbolics/slides.tex Wed Nov 10 12:23:40 2010 +0530 +++ b/getting-started-with-symbolics/slides.tex Wed Nov 10 17:19:54 2010 +0530 @@ -1,21 +1,34 @@ -% Created 2010-10-21 Thu 00:06 +% Created 2010-11-10 Wed 17:18 \documentclass[presentation]{beamer} -\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} +\usepackage{fixltx2e} \usepackage{graphicx} \usepackage{longtable} \usepackage{float} \usepackage{wrapfig} \usepackage{soul} +\usepackage{t1enc} +\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}} -\title{Plotting Data } +\title{Getting started with symbolics} \author{FOSSEE} -\date{2010-09-14 Tue} +\date{} +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} \maketitle @@ -25,43 +38,222 @@ + + + \begin{frame} -\frametitle{Tutorial Plan} +\frametitle{Outline} \label{sec-1} + \begin{itemize} +\item Defining symbolic expressions in sage. +\item Using built-in constants and functions. +\item Performing Integration, differentiation using sage. +\item Defining matrices. +\item Defining Symbolic functions. +\item Simplifying and solving symbolic expressions and functions. +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Questions 1} +\label{sec-2} + +\begin{itemize} +\item Define the following expression as symbolic + expression in sage. + +\begin{itemize} +\item x$^2$+y$^2$ +\item y$^2$-4ax +\end{itemize} + +\end{itemize} + + +\end{frame} +\begin{frame}[fragile] +\frametitle{Solutions 1} +\label{sec-3} + +\begin{verbatim} +var('x,y') +x^2+y^2 + +var('a,x,y') +y^2-4*a*x +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Questions 2} +\label{sec-4} + +\begin{itemize} +\item Find the values of the following constants upto 6 digits precision + +\begin{itemize} +\item pi$^2$ +\end{itemize} + +\item Find the value of the following. + +\begin{itemize} +\item sin(pi/4) +\item ln(23) +\end{itemize} + +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solutions 2} +\label{sec-5} + +\begin{verbatim} +n(pi^2,digits=6) +n(sin(pi/4)) +n(log(23,e)) +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-6} -\item Defining symbolic expressions in sage.\\ -\label{sec-1.1}% -\item Using built-in costants and functions.\\ -\label{sec-1.2}% -\item Performing Integration, differentiation using sage.\\ -\label{sec-1.3}% -\item Defining matrices.\\ -\label{sec-1.4}% -\item Defining Symbolic functions.\\ -\label{sec-1.5}% -\item Simplifying and solving symbolic expressions and functions.\\ -\label{sec-1.6}% -\end{itemize} % ends low level +\begin{itemize} +\item Define the piecewise function. + f(x)=3x+2 + when x is in the closed interval 0 to 4. + f(x)=4x$^2$ + between 4 to 6. +\item Sum of 1/(n$^2$-1) where n ranges from 1 to infinity. +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution Q1} +\label{sec-7} + +\begin{verbatim} +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} + +\begin{verbatim} +var('n') +f=1/(n^2-1) +sum(f(n), n, 1, oo) +\end{verbatim} + +\end{frame} +\begin{frame} +\frametitle{Questions 3} +\label{sec-9} + +\begin{itemize} +\item Differentiate the following. + +\begin{itemize} +\item x$^5$*log(x$^7$) , degree=4 +\end{itemize} + +\item Integrate the given expression + +\begin{itemize} +\item x*sin(x$^2$) +\end{itemize} + +\item Find x + +\begin{itemize} +\item cos(x$^2$)-log(x)=0 +\item Does the equation have a root between 1,2. +\end{itemize} + +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solutions 3} +\label{sec-10} + +\begin{verbatim} +var('x') +f(x)= x^5*log(x^7) +diff(f(x),x,5) + +var('x') +integral(x*sin(x^2),x) + +var('x') +f=cos(x^2)-log(x) +find_root(f(x)==0,1,2) +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Question 4} +\label{sec-11} + +\begin{itemize} +\item Find the determinant and inverse of : + + A=[[x,0,1][y,1,0][z,0,y]] +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 4} +\label{sec-12} + +\begin{verbatim} +var('x,y,z') +A=matrix([[x,0,1],[y,1,0],[z,0,y]]) +A.det() +A.inverse() +\end{verbatim} \end{frame} \begin{frame} \frametitle{Summary} -\label{sec-2} +\label{sec-13} + \begin{itemize} +\item We learnt about defining symbolic + expression and functions. +\item Using built-in constants and functions. +\item Using to see the documentation of a + function. +\end{itemize} + + +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-14} -\item We learnt about defining symbolic expression and functions.\\ -\label{sec-2.1}% -\item Using built-in constants and functions.\\ -\label{sec-2.2}% -\item Using to see the documentation of a function.\\ -\label{sec-2.3}% -\item Simple calculus operations .\\ -\label{sec-2.4}% -\item Substituting values in expression using substitute function.\\ -\label{sec-2.5}% -\item Creating symbolic matrices and performing operation on them .\\ -\label{sec-2.6}% -\end{itemize} % ends low level +\begin{itemize} +\item Simple calculus operations . +\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} + + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} \end{frame} \end{document} diff -r 430035b678f7 -r a9b71932cbfa symbolics/slides.org --- a/symbolics/slides.org Wed Nov 10 12:23:40 2010 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,33 +0,0 @@ -#+LaTeX_CLASS: beamer -#+LaTeX_CLASS_OPTIONS: [presentation] -#+BEAMER_FRAME_LEVEL: 1 - -#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\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 -#+OPTIONS: H:5 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t - -#+TITLE: Plotting Data -#+AUTHOR: FOSSEE -#+DATE: 2010-09-14 Tue -#+EMAIL: info@fossee.in - -# \author[FOSSEE] {FOSSEE} - -# \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -# \date{} - -* Tutorial Plan -** Defining symbolic expressions in sage. -** Using built-in costants and functions. -** Performing Integration, differentiation using sage. -** Defining matrices. -** Defining Symbolic functions. -** Simplifying and solving symbolic expressions and functions. -* Summary -** We learnt about defining symbolic expression and functions. -** Using built-in constants and functions. -** Using 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 .