author | Puneeth Chaganti <punchagan@fossee.in> |
Tue, 09 Nov 2010 15:33:47 +0530 | |
changeset 413 | da1f270b07b7 |
parent 376 | 3e947a3fa83e |
child 442 | a9b71932cbfa |
permissions | -rw-r--r-- |
376 | 1 |
.. Objectives |
2 |
.. ---------- |
|
3 |
||
4 |
.. By the end of this tutorial, you will be able to |
|
5 |
||
6 |
.. 1. Defining symbolic expressions in sage. |
|
7 |
.. # Using built-in costants and functions. |
|
8 |
.. # Performing Integration, differentiation using sage. |
|
9 |
.. # Defining matrices. |
|
10 |
.. # Defining Symbolic functions. |
|
11 |
.. # Simplifying and solving symbolic expressions and functions. |
|
12 |
||
13 |
||
14 |
.. Prerequisites |
|
15 |
.. ------------- |
|
16 |
||
17 |
.. 1. getting started with sage notebook |
|
18 |
||
19 |
||
20 |
.. Author : Amit |
|
21 |
Internal Reviewer : |
|
22 |
External Reviewer : |
|
23 |
Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
|
24 |
||
351
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
25 |
Symbolics with Sage |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
26 |
------------------- |
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 |
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
|
29 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
30 |
{{{ Show welcome slide }}} |
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 |
.. #[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
|
34 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
35 |
During the course of the tutorial we will learn |
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 |
{{{ Show outline slide }}} |
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 |
* Defining symbolic expressions in sage. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
40 |
* Using built-in costants and functions. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
41 |
* Performing Integration, differentiation using sage. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
42 |
* Defining matrices. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
43 |
* Defining Symbolic functions. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
44 |
* Simplifying and solving symbolic expressions and functions. |
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 |
We can use Sage for symbolic maths. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
47 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
48 |
On the sage notebook type:: |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
49 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
50 |
sin(y) |
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 |
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
|
53 |
can declare y as a symbol using var function. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
54 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
55 |
|
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 |
var('y') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
58 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
59 |
Now if you type:: |
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 |
sin(y) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
62 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
63 |
sage simply returns the expression. |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
66 |
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
|
67 |
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
|
68 |
expressions.. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
69 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
70 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
71 |
So let us try :: |
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 |
var('x,alpha,y,beta') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
74 |
x^2/alpha^2+y^2/beta^2 |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
75 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
76 |
taking another example |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
77 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
78 |
var('theta') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
79 |
sin^2(theta)+cos^2(theta) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
80 |
|
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 |
Similarly, we can define many algebraic and trigonometric expressions |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
83 |
using sage . |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
84 |
|
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 |
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
|
87 |
mathematics . |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
88 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
89 |
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
|
90 |
constants. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
91 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
92 |
{{{ Type n(pi) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
93 |
n(e) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
94 |
n(oo) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
95 |
On the sage notebook }}} |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
98 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
99 |
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
|
100 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
101 |
.. #[Madhu: "documentation of the function "n"?] |
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 |
n(<Tab> |
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 |
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
|
107 |
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
|
108 |
this script. |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
112 |
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
|
113 |
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
|
114 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
115 |
.. #[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
|
116 |
use"?] |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
119 |
n(pi, digits = 10) |
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 |
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
|
122 |
sin,cos,log,factorial,gamma,exp,arcsin etc ... |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
123 |
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
|
124 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
125 |
|
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
128 |
sin(pi/2) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
129 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
130 |
arctan(oo) |
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 |
log(e,e) |
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 |
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
|
136 |
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
|
137 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
138 |
var('x') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
139 |
function('f',x) |
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 |
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
|
143 |
Now we can define f(x) to be :: |
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 |
f(x) = x/2 + sin(x) |
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 |
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
|
148 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
149 |
f(pi) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
150 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
151 |
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
|
152 |
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
|
153 |
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
|
154 |
screen |
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 |
:: |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
157 |
|
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 |
var('x') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
160 |
h(x)=x^2 g(x)=1 |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
161 |
f=Piecewise(<Tab> |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
162 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
163 |
{{{ Show the documentation of Piecewise }}} |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
164 |
|
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 |
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
|
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 |
|
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 |
We can also define functions which are series |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
172 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
173 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
174 |
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
|
175 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
176 |
var('n') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
177 |
function('f', n) |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
180 |
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
|
181 |
sage function sum. |
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 |
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
|
184 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
185 |
var('n') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
186 |
function('f', n) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
187 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
188 |
f(n) = 1/n^2 |
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 |
sum(f(n), n, 1, oo) |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
193 |
Lets us now try another series :: |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
196 |
f(n) = (-1)^(n-1)*1/(2*n - 1) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
197 |
sum(f(n), n, 1, oo) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
198 |
|
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 |
This series converges to pi/4. |
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 |
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
|
204 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
205 |
For example lets try an expression first :: |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
206 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
207 |
diff(x**2+sin(x),x) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
208 |
2x+cos(x) |
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 |
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
|
211 |
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
|
212 |
independent variable. |
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 |
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
|
215 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
216 |
f=exp(x^2)+arcsin(x) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
217 |
diff(f(x),x) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
218 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
219 |
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
|
220 |
for order :: |
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 |
diff(<tab> diff(f(x),x,3) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
223 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
224 |
in this case it is 3. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
225 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
226 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
227 |
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
|
228 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
229 |
x = var('x') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
230 |
s = integral(1/(1 + (tan(x))**2),x) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
231 |
s |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
232 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
233 |
|
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 |
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
|
236 |
|
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 |
factor(<tab> |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
239 |
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
|
240 |
f = factor(y) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
241 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
242 |
One can simplify complicated expression :: |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
243 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
244 |
f.simplify_full() |
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 |
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
|
247 |
of just the algebraic part and the trigonometric part :: |
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 |
f.simplify_exp() |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
250 |
f.simplify_trig() |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
254 |
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
|
255 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
256 |
phi = var('phi') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
257 |
find_root(cos(phi)==sin(phi),0,pi/2) |
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 |
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
|
260 |
correct :: |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
261 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
262 |
var('phi') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
263 |
f(phi)=cos(phi)-sin(phi) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
264 |
root=find_root(f(phi)==0,0,pi/2) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
265 |
f.substitute(phi=root) |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
266 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
267 |
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
|
268 |
the solution we got was correct. |
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 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
272 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
273 |
Lets us now try some matrix algebra symbolically :: |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
274 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
275 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
276 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
277 |
var('a,b,c,d') |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
278 |
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
|
279 |
A |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
280 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
281 |
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
|
282 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
283 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
284 |
:: |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
285 |
A.det() |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
286 |
A.inverse() |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
287 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
288 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
289 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
290 |
{{{ Part of the notebook with summary }}} |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
291 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
292 |
So in this tutorial we learnt how to |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
293 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
294 |
|
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
295 |
* We learnt about defining symbolic expression and functions. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
296 |
* Using built-in constants and functions. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
297 |
* Using <Tab> to see the documentation of a function. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
298 |
* Simple calculus operations . |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
299 |
* Substituting values in expression using substitute function. |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
300 |
* Creating symbolic matrices and performing operation on them . |
054117c9dd59
changed the name of symbolics to getting started with symbolics
amit
parents:
diff
changeset
|
301 |