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