A sampler of Sage mathematics
Sage offers tools for learning and for doing research in many different areas of mathematics. The purpose of this module is to provide a very brief glimpse into some these areas, including:
- Multivariate calculus
- Linear algebra
- Ordinary differential equations
- Abstract algebra/ Groups
Functions of 2 or more variables
There are several ways to define them. The easiest and most intuitive way is shown in the example below. it defines a function, evaluates it at a point, and takes its partial derivatives.
Example 1: Let . Evaluate the function at
some point in its domain, and find its 1st partial derivatives.
2
(x, y, z) |--> 2*x*z
(x, y, z) |--> 2*x*z
(x, y, z) |--> 2*x*z
(x, y, z) |--> x^2 + y^2
(x, y, z) |--> (2*x*z, 2*y*z, x^2 + y^2)
Vector functions of 2 or more variables
When the dependent variable of a function is also a vector, we have the more general case. Here are some examples
,
Such functions offer more interesting and fun variations
for applying familiar calculus concepts! For example, taking
their derivatives can be approached in the form of a "divergence"
or a "curl," with very different conceptual meaning and results.
The Sage segment below defines each of these functions, evaluates them at a point, and computes their divergence and curl.
f(0,2)= (4, 0)
g(1,2,3)= (2, 3, 6)
div(f)= 5*x
curl(f)= y
div(g)= 2*x*y + y
curl(g)= (-x^2 + z, 0, -x^2 + 2*x*z)
Some linear algebra
Sage offers powerful tools for working with vectors and matrices. Here is an example showing how to define them, and how to do basic arithmetic operations:x+y = (6, 8, -10)
A*x = (6, 7, -12)
Here is how to solve a matrix-vector system:
x = (0, 1, 2)
To find the eigenvalues and eigenvectors of a matrix:
[1, -3.732050807568878?, -0.2679491924311227?]
[(1, [
(1, 0, 0)
], 1), (-3.732050807568878?, [(1, -1.953254218877944?, 3.080966067942896?)], 1), (-0.2679491924311227?, [(1, -0.3544380888143643?, 0.1498031628263346?)], 1)]
It is equally easy to transpose, invert, or raise a matrix to any power:
[ 1 0 0]
[ 4 1 -2]
[ 1 3 -5]
[ 1 510 1200]
[ 0 -989 -2340]
[ 0 1560 3691]
A^(-1) = [ 1 18 11]
[ 0 -5 -3]
[ 0 2 1]
Ordinary differential equations
ODEs come in many flavors. Some have closed-form analytical solutions, while most can only be solved numerically. In addition, sometimes we have only single equations, and other times we have systems of ODEs. Sage provides tools for working with all these situations.
The following example shows how to find the general solution of
the 1st order differential equation . Note that
the key step is to rewrite the equation with on one side:
.
1/6*x(t)^2 == _C + t
It is also possible to solve ODEs that contain arbitrary parameters,
as shown next:
(log(b*y(t) - 1) - log(y(t)))/a == _C + t
Often, we want to plot direction fields for an ODE. Here is
how to do it:
Sage can solve systems of linear 1st order ODEs in analytical form.
Here are two examples -- one shows how to find the general solution,
the other shows how to find a particular solution:
[x(t) == -((x(0) - 2*y(0))*sin(t) - cos(t)*x(0))*e^(3*t), y(t) == -((x(0) - y(0))*sin(t) - cos(t)*y(0))*e^(3*t)]
[x(t) == -2*(cos(t) - 2*sin(t))*e^(3*t), y(t) == (cos(t) + 3*sin(t))*e^(3*t)]
It is also possible to solve ODE systems numerically, as shown
below:
A taste of abstract algebra/ Groups
The group of all permutations of elements is a symmetric group. For example, the symmetric group of the set can be constructed using the command:Symmetric group of order 4! as a permutation group
It is now possible to find the number of elements in the
group, and to list all of them:
24
[(), (1,2), (1,2,3,4), (1,3)(2,4), (1,3,4), (2,3,4), (1,4,3,2), (1,3,4,2), (1,3,2,4), (1,4,2,3), (1,2,4,3), (2,4,3), (1,4,3), (1,4)(2,3), (1,4,2), (1,3,2), (1,3), (3,4), (2,4), (1,4), (2,3), (1,2)(3,4), (1,2,3), (1,2,4)]
(1,4,2,3)
(1,4)
(2,3,4)
(1,2,3)