# HG changeset patch # User Puneeth Chaganti # Date 1289421254 -19800 # Node ID 9a1c5d134feb1f38b8f53d305989217179e840d5 # Parent 2ce824b5adf4909a1fa856702596e82ec1bc1f63 Reviewed getting started with symbolics. diff -r 2ce824b5adf4 -r 9a1c5d134feb getting-started-with-symbolics/script.rst --- a/getting-started-with-symbolics/script.rst Wed Nov 10 19:00:23 2010 +0530 +++ b/getting-started-with-symbolics/script.rst Thu Nov 11 02:04:14 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( -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( -{{{ 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( 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( + 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 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 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 diff -r 2ce824b5adf4 -r 9a1c5d134feb getting-started-with-symbolics/slides.org --- a/getting-started-with-symbolics/slides.org Wed Nov 10 19:00:23 2010 +0530 +++ b/getting-started-with-symbolics/slides.org Thu Nov 11 02:04:14 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 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 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}{} diff -r 2ce824b5adf4 -r 9a1c5d134feb getting-started-with-symbolics/slides.tex --- a/getting-started-with-symbolics/slides.tex Wed Nov 10 19:00:23 2010 +0530 +++ b/getting-started-with-symbolics/slides.tex Thu Nov 11 02:04:14 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 to see the documentation of a - function. -\end{itemize} - - -\end{frame} -\begin{frame} -\frametitle{Summary} -\label{sec-14} - -\begin{itemize} +\item Using 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}