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