symbolics/script.rst
author amit
Thu, 21 Oct 2010 00:22:42 +0530
changeset 342 588b681e70c6
parent 321 2e49b1b72996
permissions -rw-r--r--
Added a few large questions and quickrefs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     1
Symbolics with Sage
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     2
-------------------
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     3
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     4
Hello friends and welcome to the tutorial on symbolics with sage.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     5
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
     6
{{{ Show welcome slide }}}
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     7
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     8
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
     9
.. #[Madhu: What is this line doing here. I don't see much use of it]
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    10
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    11
During the course of the tutorial we will learn
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    12
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    13
{{{ Show outline slide  }}}
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    14
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    15
* Defining symbolic expressions in sage.  
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    16
* Using built-in costants and functions. 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    17
* Performing Integration, differentiation using sage. 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    18
* Defining matrices. 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    19
* Defining Symbolic functions.  
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    20
* Simplifying and solving symbolic expressions and functions.
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    21
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    22
We can use Sage for symbolic maths. 
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    23
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    24
On the sage notebook type::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    25
   
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    26
    sin(y)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    27
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    28
It raises a name error saying that y is not defined. But in sage we
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    29
can declare y as a symbol using var function.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    30
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    31
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    32
::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    33
    var('y')
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    34
   
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    35
Now if you type::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    36
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    37
    sin(y)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    38
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    39
sage simply returns the expression.
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    40
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    41
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    42
Thus sage treats sin(y) as a symbolic expression . We can use
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    43
this to do  symbolic maths using sage's built-in constants and
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    44
expressions..
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    45
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    46
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    47
So let us try ::
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    48
   
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    49
   var('x,alpha,y,beta') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    50
   x^2/alpha^2+y^2/beta^2
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    51
 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    52
taking another example
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    53
   
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    54
   var('theta')
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    55
   sin^2(theta)+cos^2(theta)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    56
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    57
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    58
Similarly, we can define many algebraic and trigonometric expressions
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    59
using sage .
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    60
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    61
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    62
Sage also provides a few built-in constants which are commonly used in
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    63
mathematics .
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    64
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    65
example : pi,e,infinity , Function n gives the numerical values of all these
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    66
    constants.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    67
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    68
{{{ Type n(pi)
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    69
   	n(e)
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    70
	n(oo) 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    71
    On the sage notebook }}}  
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    72
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    73
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    74
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    75
If you look into the documentation of function "n" by doing
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    76
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    77
.. #[Madhu: "documentation of the function "n"?]
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    78
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    79
::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    80
   n(<Tab>
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    81
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    82
You will see what all arguments it takes and what it returns. It will be very
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    83
helpful if you look at the documentation of all functions introduced through
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    84
this script.
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    85
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    86
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    87
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    88
Also we can define the no. of digits we wish to use in the numerical
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    89
value . For this we have to pass an argument digits.  Type
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    90
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    91
.. #[Madhu: "no of digits"? Also "We wish to obtain" than "we wish to
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    92
     use"?]
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    93
::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    94
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    95
   n(pi, digits = 10)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    96
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
    97
Apart from the constants sage also has a lot of builtin functions like
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    98
sin,cos,log,factorial,gamma,exp,arcsin etc ...
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
    99
lets try some of them out on the sage notebook.
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   100
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   101
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   102
::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   103
     
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   104
   sin(pi/2)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   105
   
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   106
   arctan(oo)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   107
     
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   108
   log(e,e)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   109
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   110
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   111
Given that we have defined variables like x,y etc .. , We can define
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   112
an arbitrary function with desired name in the following way.::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   113
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   114
       var('x') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   115
       function('f',x)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   116
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   117
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   118
Here f is the name of the function and x is the independent variable .
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   119
Now we can define f(x) to be ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   120
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   121
     f(x) = x/2 + sin(x)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   122
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   123
Evaluating this function f for the value x=pi returns pi/2.::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   124
	   
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   125
	   f(pi)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   126
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   127
We can also define functions that are not continuous but defined
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   128
piecewise.  Let us define a function which is a parabola between 0
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   129
to 1 and a constant from 1 to 2 .  Type the following as given on the
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   130
screen
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   131
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   132
::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   133
      
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   134
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   135
      var('x') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   136
      h(x)=x^2 g(x)=1 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   137
      f=Piecewise(<Tab>
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   138
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   139
{{{ Show the documentation of Piecewise }}} 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   140
    
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   141
::
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   142
      f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   143
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   144
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   145
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   146
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   147
We can also define functions which are series 
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   148
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   149
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   150
We first define a function f(n) in the way discussed above.::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   151
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   152
   var('n') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   153
   function('f', n)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   154
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   155
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   156
To sum the function for a range of discrete values of n, we use the
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   157
sage function sum.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   158
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   159
For a convergent series , f(n)=1/n^2 we can say ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   160
   
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   161
   var('n') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   162
   function('f', n)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   163
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   164
   f(n) = 1/n^2
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   165
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   166
   sum(f(n), n, 1, oo)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   167
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   168
 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   169
Lets us now try another series ::
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   170
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   171
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   172
    f(n) = (-1)^(n-1)*1/(2*n - 1)
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   173
    sum(f(n), n, 1, oo)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   174
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   175
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   176
This series converges to pi/4. 
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   177
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   178
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   179
Moving on let us see how to perform simple calculus operations using Sage
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   180
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   181
For example lets try an expression first ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   182
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   183
    diff(x**2+sin(x),x) 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   184
    2x+cos(x)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   185
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   186
The diff function differentiates an expression or a function. Its
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   187
first argument is expression or function and second argument is the
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   188
independent variable.
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   189
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   190
We have already tried an expression now lets try a function ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   191
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   192
   f=exp(x^2)+arcsin(x) 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   193
   diff(f(x),x)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   194
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   195
To get a higher order differential we need to add an extra third argument
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   196
for order ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   197
 
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   198
   diff(<tab> diff(f(x),x,3)
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   199
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   200
in this case it is 3.
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   201
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   202
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   203
Just like differentiation of expression you can also integrate them ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   204
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   205
     x = var('x') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   206
     s = integral(1/(1 + (tan(x))**2),x) 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   207
     s
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   208
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   209
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   210
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   211
Many a times we need to find factors of an expression ,we can use the "factor" function
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   212
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   213
::
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   214
    factor(<tab> 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   215
    y = (x^100 - x^70)*(cos(x)^2 + cos(x)^2*tan(x)^2) 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   216
    f = factor(y)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   217
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   218
One can  simplify complicated expression ::
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   219
    
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   220
    f.simplify_full()
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   221
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   222
This simplifies the expression fully . We can also do simplification
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   223
of just the algebraic part and the trigonometric part ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   224
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   225
    f.simplify_exp() 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   226
    f.simplify_trig()
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   227
    
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   228
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   229
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   230
One can also find roots of an equation by using find_root function::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   231
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   232
    phi = var('phi') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   233
    find_root(cos(phi)==sin(phi),0,pi/2)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   234
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   235
Lets substitute this solution into the equation and see we were
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   236
correct ::
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   237
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   238
     var('phi') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   239
     f(phi)=cos(phi)-sin(phi)
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   240
     root=find_root(f(phi)==0,0,pi/2) 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   241
     f.substitute(phi=root)
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   242
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   243
as we can see when we substitute the value the answer is almost = 0 showing 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   244
the solution we got was correct.
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   245
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   246
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   247
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   248
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   249
Lets us now try some matrix algebra symbolically ::
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   250
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   251
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   252
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   253
   var('a,b,c,d') 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   254
   A=matrix([[a,1,0],[0,b,0],[0,c,d]]) 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   255
   A
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   256
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   257
Now lets do some of the matrix operations on this matrix
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   258
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   259
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   260
::
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   261
    A.det() 
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   262
    A.inverse()
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   263
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   264
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   265
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   266
{{{ Part of the notebook with summary }}}
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   267
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   268
So in this tutorial we learnt how to
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   269
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   270
342
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   271
* We learnt about defining symbolic expression and functions.  
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   272
* Using built-in constants and functions.  
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   273
* Using <Tab>  to see the documentation of a function.  
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   274
* Simple calculus operations .  
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   275
* Substituting values in expression using substitute function.
588b681e70c6 Added a few large questions and quickrefs
amit
parents: 321
diff changeset
   276
* Creating symbolic matrices and performing operation on them .
321
2e49b1b72996 adding questions for all other LO needs to be cleaned
amit
parents:
diff changeset
   277