symbolics.rst
author amit
Thu, 16 Sep 2010 19:40:33 +0530
changeset 149 b9ae88095ade
parent 148 60a4616dbf55
child 187 3b912b3fdcbf
permissions -rw-r--r--
Merging the changes from Nishanth and Punch
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
148
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     1
Symbolics with Sage
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     2
-------------------
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     3
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     4
This tutorial on using Sage for symbolic calculation is brought to you
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     5
by Fossee group.
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     6
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     7
{{{ Part of Notebook with title }}}
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     8
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
     9
We would be using simple mathematical functions on the sage notebook
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    10
for this tutorial .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    11
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    12
During the course of the tutorial we will learn
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    13
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    14
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    15
{{{ Part of Notebook with outline }}}
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    16
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    17
To define symbolic expressions in sage .  Use built-in costants and
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    18
function.  Integration , differentiation using sage .  Defining
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    19
matrices.  Defining Symbolic functions .  Simplifying and solving
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    20
symbolic expressions and functions
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    21
    
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    22
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    23
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    24
Using sage we can perform mathematical operations on symbols .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    25
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    26
On the sage notebook type::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    27
   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    28
    sin(y)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    29
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    30
It raises a name error saying that y is not defined . But in sage we
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    31
can declare y as a symbol using var function. ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    32
   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    33
    var('y')
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    34
   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    35
Now if you type::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    36
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    37
    sin(y)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    38
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    39
     sage simply returns the expression .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    40
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    41
thus now sage treats sin(y) as a symbolic expression . You can use
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    42
this to do a lot of symbolic maths using sage's built-in constants and
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    43
expressions .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    44
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    45
Try out ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    46
   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    47
   var('x,alpha,y,beta') x^2/alpha^2+y^2/beta^2
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    48
 
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    49
Similarly , we can define many algebraic and trigonometric expressions
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    50
using sage .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    51
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    52
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    53
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    54
Sage also provides a few built-in constants which are commonly used in
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    55
mathematics .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    56
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    57
example : pi,e,oo , Function n gives the numerical values of all these
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    58
    constants.
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    59
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    60
For instance::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    61
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    62
   n(e)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    63
   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    64
   2.71828182845905
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    65
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    66
gives numerical value of e.
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    67
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    68
If you look into the documentation of n by doing ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    69
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    70
   n(<Tab>
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    71
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    72
You will see what all arguments it can take etc .. It will be very
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    73
helpful if you look at the documentation of all functions introduced
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    74
      
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    75
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    76
Also we can define the no of digits we wish to use in the numerical
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    77
value . For this we have to pass an argument digits.  Type::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    78
  
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    79
   n(pi, digits = 10)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    80
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    81
Apart from the constants sage also has a lot of builtin functions like
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    82
sin,cos,sinh,cosh,log,factorial,gamma,exp,arcsin,arccos,arctan etc ...
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    83
lets try some out on the sage notebook. ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    84
     
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    85
   sin(pi/2)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    86
   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    87
   arctan(oo)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    88
     
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    89
   log(e,e)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    90
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    91
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    92
Given that we have defined variables like x,y etc .. , We can define
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    93
an arbitrary function with desired name in the following way.::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    94
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    95
       var('x') function(<tab> {{{ Just to show the documentation
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    96
       extend this line }}} function('f',x)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    97
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    98
Here f is the name of the function and x is the independent variable .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
    99
Now we can define f(x) to be ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   100
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   101
     f(x) = x/2 + sin(x)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   102
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   103
Evaluating this function f for the value x=pi returns pi/2.::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   104
	   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   105
	   f(pi)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   106
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   107
We can also define function that are not continuous but defined
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   108
piecewise.  We will be using a function which is a parabola between 0
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   109
to 1 and a constant from 1 to 2 .  type the following as given on the
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   110
screen::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   111
      
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   112
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   113
      var('x') h(x)=x^2 g(x)=1 f=Piecewise(<Tab> {{{ Just to show the
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   114
      documentation extend this line }}}
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   115
      f=Piecewise([[(0,1),h(x)],[(1,2),g(x)]],x) f
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   116
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   117
Checking f at 0.4, 1.4 and 3 :: f(0.4) f(1.4) f(3)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   118
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   119
for f(3) it raises a value not defined in domain error .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   120
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   121
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   122
Apart from operations on expressions and functions one can also use
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   123
them for series .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   124
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   125
We first define a function f(n) in the way discussed above.::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   126
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   127
   var('n') function('f', n)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   128
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   129
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   130
To sum the function for a range of discrete values of n, we use the
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   131
sage function sum.
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   132
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   133
 For a convergent series , f(n)=1/n^2 we can say ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   134
   
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   135
   var('n') function('f', n)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   136
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   137
   f(n) = 1/n^2
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   138
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   139
   sum(f(n), n, 1, oo)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   140
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   141
For the famous Madhava series :: var('n') function('f', n)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   142
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   143
    f(n) = (-1)^(n-1)*1/(2*n - 1)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   144
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   145
This series converges to pi/4. It was used by ancient Indians to
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   146
interpret pi.
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   147
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   148
For a divergent series, sum would raise a an error 'Sum is
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   149
divergent' :: 
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   150
	
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   151
	var('n') 
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   152
	function('f', n) 
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   153
	f(n) = 1/n sum(f(n), n,1, oo)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   154
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   155
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   156
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   157
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   158
We can perform simple calculus operation using sage
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   159
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   160
For example lets try an expression first ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   161
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   162
    diff(x**2+sin(x),x) 2x+cos(x)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   163
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   164
The diff function differentiates an expression or a function . Its
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   165
first argument is expression or function and second argument is the
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   166
independent variable .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   167
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   168
We have already tried an expression now lets try a function ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   169
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   170
   f=exp(x^2)+arcsin(x) diff(f(x),x)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   171
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   172
To get a higher order differentiation we need to add an extra argument
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   173
for order ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   174
 
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   175
   diff(<tab> diff(f(x),x,3)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   176
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   177
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   178
in this case it is 3.
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   179
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   180
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   181
Just like differentiation of expression you can also integrate them ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   182
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   183
     x = var('x') s = integral(1/(1 + (tan(x))**2),x) s
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   184
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   185
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   186
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   187
To find factors of an expression use the function factor
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   188
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   189
    factor(<tab> y = (x^100 - x^70)*(cos(x)^2 + cos(x)^2*tan(x)^2) f =
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   190
    factor(y)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   191
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   192
One can also simplify complicated expression using sage ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   193
    f.simplify_full()
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   194
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   195
This simplifies the expression fully . You can also do simplification
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   196
of just the algebraic part and the trigonometric part ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   197
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   198
    f.simplify_exp() f.simplify_trig()
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   199
    
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   200
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   201
One can also find roots of an equation by using find_root function::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   202
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   203
    phi = var('phi') find_root(cos(phi)==sin(phi),0,pi/2)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   204
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   205
Lets substitute this solution into the equation and see we were
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   206
correct ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   207
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   208
     var('phi') f(phi)=cos(phi)-sin(phi)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   209
     root=find_root(f(phi)==0,0,pi/2) f.substitute(phi=root)
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   210
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   211
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   212
as we can see the solution is almost equal to zero .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   213
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   214
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   215
We can also define symbolic matrices ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   216
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   217
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   218
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   219
   var('a,b,c,d') A=matrix([[a,1,0],[0,b,0],[0,c,d]]) A
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   220
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   221
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   222
Now lets do some of the matrix operations on this matrix ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   223
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   224
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   225
    A.det() A.inverse()
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   226
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   227
You can do ::
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   228
    
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   229
    A.<Tab>
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   230
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   231
To see what all operations are available
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   232
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   233
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   234
{{{ Part of the notebook with summary }}}
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   235
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   236
So in this tutorial we learnt how to
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   237
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   238
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   239
We learnt about defining symbolic expression and functions .  
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   240
And some built-in constants and functions .  
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   241
Getting value of built-in constants using n function.  
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   242
Using Tab to see the documentation.  
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   243
Also we learnt how to sum a series using sum function.  
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   244
diff() and integrate() for calculus operations .  
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   245
Finding roots , factors and simplifying expression using find_root(), 
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   246
factor() , simplify_full, simplify_exp , simplify_trig .
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   247
Substituting values in expression using substitute function.
60a4616dbf55 Symbolics with Sage initial commit
amit
parents:
diff changeset
   248
And finally creating symbolic matrices and performing operation on them .