Anda di halaman 1dari 28

Maple Handbook

Carl-Gustav Werner
Centre for Mathematical Science
Lund University
Contents
1 Introduction to Maple 5
1.1 Input of Mathematical Expressions . . . . . . . . . . . . . . . . . 5
1.2 Arithmetical Expressions . . . . . . . . . . . . . . . . . . . . . . 5
1.3 Dening Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Working with Algebraic Expressions . . . . . . . . . . . . . . . . 8
1.5 Dening Functions . . . . . . . . . . . . . . . . . . . . . . . . . . 9
1.6 Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.6.1 General Equations . . . . . . . . . . . . . . . . . . . . . . 11
1.6.2 Inequalities . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.6.3 Systems of Equations . . . . . . . . . . . . . . . . . . . . 12
1.6.4 Numerical Solutions . . . . . . . . . . . . . . . . . . . . . 12
1.6.5 Integer Equations . . . . . . . . . . . . . . . . . . . . . . . 13
1.6.6 Dierential Equations . . . . . . . . . . . . . . . . . . . . 13
1.6.7 Dierence Equations . . . . . . . . . . . . . . . . . . . . . 14
2 Linear Algebra 15
2.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.1.1 Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.1.2 Vector Commands in Maple . . . . . . . . . . . . . . . . . 16
2.1.3 A Geometrical Example . . . . . . . . . . . . . . . . . . . 16
2.1.4 Examples with Orthogonal Vectors . . . . . . . . . . . . . 17
2.1.5 Examples with Lines in R
3
. . . . . . . . . . . . . . . . . 18
2.2 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2.1 Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.2.2 Matrix Commands in Maple . . . . . . . . . . . . . . . . . 20
2.2.3 Orthogonal Matrices . . . . . . . . . . . . . . . . . . . . . 21
2.2.4 Determinants . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.5 Systems of Equations . . . . . . . . . . . . . . . . . . . . 22
2.2.6 Functions of Matrices and Vectors . . . . . . . . . . . . . 23
2.2.7 Linear Maps . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.2.8 Eigenvalues and Eigenvectors . . . . . . . . . . . . . . . . 25
2.2.9 Diagonalization . . . . . . . . . . . . . . . . . . . . . . . . 27
3
CONTENTS
4
Chapter 1
Introduction to Maple
1.1 Input of Mathematical Expressions
When Maple is ready to receive input, a so called prompt becomes visible:
>
Right after this > one can write the mathematical expression and Maple com-
mands, which should always be followed by ; (or in some cases :). This is
easily forgotten, so once again: All input must nish with ;. An easy
example:
> 3+12;
15
If one would like to modify something in a previous input, one could use the
arrow-tangent (or the mouse) to mark and modify the text. The new command
is executed again if you press Return/Enter.
1.2 Arithmetical Expressions
The basic arithmetic operators such as plus, minus, and equal to are written in
Maple using their symbols+, , =. More is to be found in the following table:
Mathematics Maple Explanation
x +y x+y addition
x y x-y subtraction
xy x*y multiplication
x
y
x/y division
x
y
xy or x**y exponentiate
x = y x=y equal to
x = y x<>y not equal to
x < y x<y less than
x y x<=y less than or equal to
x > y x>y greater than
x y x>=y greater than or equal to
5
CHAPTER 1. INTRODUCTION TO MAPLE
The usual constants are available in Maple and denoted by their usual symbols
and :
Mathematics Maple Explanation
Pi the number = 3.141 . . .
e E the number e = 2.718 . . .
i I the number i =

1
innity innity
true true (in logical expressions)
false false(in logical expressions)
Plenty of functions are dened in Maple. Here are the most usual ones:
Mathematics Maple Explanation

x sqrt(x) or x(1/2) square root


n

x root(x,n) or surd(x,n)
1
n:te-rot
e
x
exp(x) exponential function
ln x or log x ln(x) or log(x) natural logarithm
log
10
x or lg x log10(x) decimal logarithm(base 10)
sin x sin(x) sine
cos x cos(x) cosine
tan x tan(x) tangent
arcsinx arcsin(x) arcsine
arccos x arccos(x) arccosine
arctanx arctan(x) arctangent
|x| abs(x) absolute value
x! factorial(x) or x! factorial
_
n
k
_
binomial(n,k) binomial coecients
Since all the usual functions are available, Maple can be used as an advanced
calculator. Some examples:
> 3*4/6;
2
> sin(Pi/2);
1
Note that Maple returns exact expressions whenever this is possible:
> 8/12+sqrt(2);
2
3
+

2
If the numerical answer is prefered, one could use the command evalf, or write
some of the numbers involved as a decimal number:
1
root and surd do not always return the same answer. Try to compute
3

8.
6
1.3. DEFINING VARIABLES
> evalf(8/12+sqrt(2));
2.080880229
> 8/12+sqrt(2.0);
2.080880229
Maple answers normally with 10 digits. If one wants a computation to be exe-
cuted using for instance 25 digits instead, one could specify this in the command
evalf:
> evalf(8/12+sqrt(2), 25);
2.080880229039761715468356
1.3 Dening Variables
Sometimes a result to some computation is to be used several times in other
calculations. It is therefore important to be able to access such a result in Maple.
This can be done in several ways:
1. One can refer to the last and second last result using %, and %% respec-
tively:
> 60*60*24;
86400
> %*365;
31536000
2. Save the answer as a constant s:
> s:=60*60*24;
s := 86400
> s*365;
31536000
If the result is to be used several times, the second method is to prefer. Nev-
ertheless, it is always easier to dene a variable and assign a value to it. The
7
CHAPTER 1. INTRODUCTION TO MAPLE
notation used for the variable may contain both capital and small letters, dig-
its and underscore. In the previous example one could have used the notation
SecondsPerDay or seconds_per_day instead of s.
One can also assign values to several variables at a time:
> a:=3; b:=6.75; c:=2.83;
a := 3
b := 6.75
c := 2.83
Once a value is assigned to some variable, this value remains unchanged until
one assigns a new value to it, or until Maple is shut down. To get rid of a value
assigned to some variable, one could "erase" the value by writing:
> s:=s;
s := s
1.4 Working with Algebraic Expressions
If one writes an algebraic expression that contains "free" variables, Maple re-
sponds by writing the same expression, in a slightly simpler way:
> 2*(x+y)*(x+y)/(x-y);
2
(x +y)
2
x y
If one wants to control what Maple does to some algebraic expression, the fol-
lowing commands are available:
Maple Explanation
expand(u) expands the expression u
factor(u) factorizes u
normal(u) simplies u
simplify(u) simplies u
collect(u,x) adds together terms in u containing the variable x
combine(u,f) combines all functions f in u to one function
To illustrate the dierences between these commands consider the following
expression:
> a:=2*(x+y)*(x+y)/(x-y)+(x+y)/(x-y)2;
a := 2
(x +y)
2
x y
+
x +y
(x y)
2
> simplify(a);
8
1.5. DEFINING FUNCTIONS
2 x
3
+ 2 x
2
y 2 xy
2
2 y
3
+x +y
(x y)
2
> factor(a);
(x +y)
_
2 x
2
+ 1 2 y
2
_
(x y)
2
> expand(a);
2
x
2
x y
+ 4
xy
x y
+ 2
y
2
x y
+
x
(x y)
2
+
y
(x y)
2
Some of these commands prove useful in simplifying expressions containing num-
bers:
> (sqrt(5)-1)2/(sqrt(5)-3);
_
5 1
_
2

5 3
One can use % to refer to the previous result:a
> simplify(%);
_
5 1
_
2

5 3
Nothing seems to have happened. One could try factor instead. To this end
one can use %. (In fact, it is the second last result that is to be factorized, and
it can be refered to using %%)
> factor(%);
2
It turns out that factor is often better than simplify on this type of simplica-
tions.
1.5 Dening Functions
One can dene functions in the same manner that one can assign a value to
some variable. This can be useful since in many situations, one may have an
expression that is to be used several times. There are two ways to "save" a
certain expression. One can assign the expression as "value" to some variable:
> f:=x+2/(x*x+2*x);
f := x +
2
x
2
+ 2 x
9
CHAPTER 1. INTRODUCTION TO MAPLE
but it is often more useful to dene it as a proper function in Maple:
> g:=x->x+2/(x*x+2*x);
g := x x +
2
x
2
+ 2 x
Note the dierences in the syntax. The arrow is written as a minus sign
followed by the symbol >.
Most situations can be handled using both ways, but in some cases it turns
out that the second method is far more advantageous. Below we compare how
the value of the expression is computed given a certain value of the variable x:
> eval(f, x=1);
5
3
> g(1);
5
3
It is of course possible to dene a function out of an expression:
> unapply(f, x);
x x +
2
x
2
+ 2 x
and vice-versa:
> g(x);
x +
2
x
2
+ 2 x
Note though that it is not possible to write in the following manner in order to
dene a function:
> h(x):=x+2/(x*x+2*x);
h(x) := x +
2
x
2
+ 2 x
Unfortunately, Maple does not return any error message, but "h" is not dened
as a function.
1.6 Equations
Maple can solve many types of equations and each such type requires a special
command:
10
1.6. EQUATIONS
Maple Explanation
solve solves general equations (polynomial)
fsolve solves equations numerically
isolve solves integer equations
dsolve solves dierential equations
rsolve solves dierence equations
1.6.1 General Equations
One of the most common types of equations are polynomial equations. To solve
for instance the second-degree equation x
2
4x + 3 = 0, write:
> solve(x2-4*x+3=0, x);
1, 3
thus, Maple returns the two roots 1 and 3. If the right hand side is equal to
zero, one does not have to write it:
> solve(x2-4*x+3, x);
1, 3
If the equation one wants to solve using Maple contains only one variable (as in
the above example) one does not need to specify this fact either. On the other
hand, the variable must be specied when using the command di:
> solve(x2-4*x+3);
1, 3
If one wants the solution returned by Maple to appear more clearly, one could
write x using set-brackets:
> solve(x2-4*x+3=0, {x});
{x = 1} , {x = 3}
If the equation contains several variables, the variable that one wants to equate
must be specied. To obtain x from yx +
x
y
= 5 write:
> solve(y*x+x/y=5, x);
5
y
y
2
+ 1
1.6.2 Inequalities
To solve an inequality one can again use the command solve:
> solve(x2-4*x+3<0);
11
CHAPTER 1. INTRODUCTION TO MAPLE
RealRange(Open(1), Open(3))
The answer might look a little bit weird, but it means real interval from 1 till
3, open at both endpoints (i.e. end-points excluded). To obtain the answer on
the form 1 < x < 3 or ]1..3[. write:
> solve(x2-4*x+3<0, {x});
{x < 3, 1 < x}
1.6.3 Systems of Equations
A system of two or more equations can be solved using the command solve as
well. To solve the system:
_
3x + 2y = 16
2x y = 1
write (note that the equation must be written using set-brackets):
> solve({3*x+2*y=16, 2*x-y=-1});
{y = 5, x = 2}
Systems of inequalities can be solved in a similar manner.
1.6.4 Numerical Solutions
If one attempts to solve an equation that cannot be solved exactly, Maples
response is either none whatsoever or a meaningless reformulation of the original
equation:
> solve(3*sin(x)=log(x));
RootOf(_Z e
3 sin(_Z)
)
One could try to obtain a numerical solution to such an equation instead, using
> fsolve(3*sin(x)=log(x));
2.792247796
Often, Maple answers to the command fsolve with the rst numerical solution
that is computed. If one has reason to believe that there might be a larger
solution x, for instance in the interval 3 < x < 10 one could specify this interval
in fsolve:
> fsolve(3*sin(x)=log(x), x=3..10);
6.988241068
So there is another solution! This procedure makes it hard to nd, numerically,
all the solutions to such equations. In practice, in such cases it is to prefer to
draw the graphs of the functions involved.
12
1.6. EQUATIONS
1.6.5 Integer Equations
Integer or Diophantine equations can be solved in Maple with isolve. To nd
integer solutions to x
2
+y
2
= 8 write:
> isolve(x2+y2=8);
{y = 2, x = 2} , {x = 2, y = 2} , {x = 2, y = 2} , {y = 2, x = 2}
Here is one equation with no integer solution:
> isolve(2*x+2*y=5);
So Maple does not give any answer whatsoever! A small modication gives in-
nitely many solutions:
> isolve(2*x+2*y=6);
{x = 3 _Z1, y = _Z1}
The answer looks more peculiar than what it is. Since the equation has in-
nitely many solutions, these can be written using a parameter. In the example
above, Maple used the parameter _Z1. One could change the notation for the
parameter _Z1 to k by writing:
> isolve(2*x+2*y=6, k);
{x = 3 k, y = k}
1.6.6 Dierential Equations
Dierential equations and systems of such are solved in Maple using dsolve.
The rst order linear dierential equation, y

+2y = 5, without initial values is


solved by:
> dsolve(D(y)(x)+2*y(x)=5);
y(x) = 5/2 +e
2 x
_C1
Instead of D(y)(x) one can write di(y(x),x) to express y

. The undetermined
constant usually denoted by C is denoted here by _C1.
One can of course solve initial value problems as well. Add to the equation
above the initial condition y(1) = 3. Unfortunately, the syntax becomes more
complicated since one must specify which function is to be determined (in this
case y(x)) even if there are no other alternatives:
> dsolve({D(y)(x)+2*y(x)=5, y(1)=3}, y(x));
y(x) =
5
2
+
1
2
e
2 x
e
2
13
CHAPTER 1. INTRODUCTION TO MAPLE
1.6.7 Dierence Equations
Dierence or recursive equations can also be solved in Maple. The command is
rsolve and the syntax is similar to the one used for dsolve.
Below it is shown how to obtain a (non-recursive) formula for the Fibonacci
sequence (1, 1, 2, 3, 5, 8, 13, 21, . . .) that is dened by:
F(k) = F(k 1) +F(k 2), F(0) = 1, F(1) = 1
The initial values are written inside brackets together with the dierence equa-
tion:
> rsolve({F(k)=F(k-1)+F(k-2), F(0)=1, F(1)=1}, F(k));
2
5

5
_
2
1
1 +

5
_
k
1 +

5
+
2
5

5
_
2
1

5 + 1
_
k

5 + 1
.
14
Chapter 2
Linear Algebra
Maple has only a couple of functionalities available when working with matrices
and vectors. Nevertheless, there are two additional packages that contain more:
linalg (older) and the newer LinearAlgebra package. In what follows we give a
description of the latter.
In order to have access to the contents of this package one has to write rst:
> with(LinearAlgebra):
Instead of ":" at the end of this line one could write ";" in order to obtain a list
of all the commands available in this package.
2.1 Vectors
2.1.1 Input
Vectors are created with the command Vector.
In what follows we give an account of the most useful ways to create vectors.
(In Maples help-section one nds several other ways that can be useful in some
special cases, but for our purposes, the examples below are enough.)
So one can create a vector with 3 entries, all of them equal to 1 and save
this vector as the value of the variable v1:
> v1:=Vector(3, 1);
v1 :=
_

_
1
1
1
_

_
Note that the vector is represented by a (column) 3 1 matrix. If you would
like to have a (row) vector represented by a 13 matrix instead, this is possible.
The following command creates a (row) vector with 5 entries, all equal to 2:
> v2:=Vector[row](5, 2);
v2 := [2, 2, 2, 2, 2]
15
CHAPTER 2. LINEAR ALGEBRA
If the entries of the vectors are dierent, they should be enumerated like in the
example below:
> v3:=Vector[row]([2, 3, 5, 7, 11]);
v3 := [2, 3, 5, 7, 11]
Once a vector is dened, one can access its entries by giving the index for the
entries in question :
> v4:=v3[2]*v3[3..5];
v4 := [15, 21, 33]
2.1.2 Vector Commands in Maple
The operators (and operations) that usually are dened on vectors are of course
available in Maple:
Mathematics Maple Explanation
u + v u+v; addition
u v u-v; subtraction
sv s*v; multiplication by scalars
1
u v or (u | v) DotProduct(u,v); scalar product
u v CrossProduct(u,v); vector product
|v| Norm(v,2); length of a vector
v
t
Transpose(v); transpose (changes between
row- and column-vectors)
map(f,v); applies the function f on all
the entries of the vector v.
The operations + and are of course dened only if the vectors have the same
number of entries. Also, to add or subtract vectors, Maple requires that these
should be either row- or column- vectors.
2.1.3 A Geometrical Example
1. Compute the distance between the lines L
1
and L
2
in R
3
, where L
1
is the line
through the points (1, 1, 1) and (4, 5, 3), and L
2
the line through (1, 10, 1)
and (8, 2, 2). (The points are given with their coordinates with respect to a
positively oriented ON coordinate system.)
Solution: Begin by dening v
1
and v
2
, the orientation vectors for L
1
and L
2
,
respectively:
> v1:=Vector[row]([4, 5, 3] - [1, 1, 1]);
v1 := [3, 4, 2]
1
If the scalar, s, is a variable (with no assigned value) then Maple does not perform the
multiplication. One should instead use the command ScalarMultiply(v,s);
16
2.1. VECTORS
> v2:=Vector[row]([8, 2, 2] - [-1, -10, -1]);
v2 := [9, 12, 3]
Determine a vector that is orthogonal to v1 and v2:
> ort:=CrossProduct(v1, v2);
ort := [12, 9, 0]
Divide this vector with its length in order to obtain a vector e of length 1 or-
thogonal to both v1 and v2.
2
:
> e:=1/Norm(ort, 2)*ort;
e :=
_

4
5
,
3
5
, 0
_
Create a vector PQ associated to the directed segment from an arbitrary point
P on the line L
1
to an arbitrary point Q on the line L
2
:
> PQ:=Vector[row]([8, 2, 2] - [1, 1, 1]);
PQ := [7, 1, 1]
The distance between the two lines equals the absolute value of the scalar prod-
uct between e and PQ:
> abs(DotProduct(PQ, e));
5
2.1.4 Examples with Orthogonal Vectors
Consider the vectors e
1
= (2, 1, 0, 1), e
2
= (0, 2, 1, 2) and w = (1, 2, 1, 2). Show
that e
1
and e
2
are orthogonal and determine numbers s
1
and s
2
such that the
vector s
1
e
1
+s
2
e
2
+ w becomes orthogonal to both e
1
and e
2
3
.
Solution: We begin by dening the vectors:
> e1:=Vector[row]([2, 1, 0, 1]);
e1 := [2, 1, 0, 1]
> e2:=Vector[row]([0, 2, 1, -2]);
e2 := [0, 2, 1, 2]
2
There is a command Normalize that can be used to normalize vectors. Using this command
we could have written e:=Normalize(ort, Euclidean);
3
Example 4, Chapter 7, Linear Algebra, K. G. Andersson, 2000
17
CHAPTER 2. LINEAR ALGEBRA
> w:=Vector[row]([1, 2, 1, 2]);
w := [1, 2, 1, 2]
If e
1
and e
2
are orthogonal then their scalar product is equal to zero:
> DotProduct(e1, e2);
0
So these vectors are indeed orthogonal. Let now u = s
1
e
1
+s
2
e
2
+ w:
> u:=ScalarMultiply(e1,s1)+ScalarMultiply(e2,s2)+w;
u := [2 s1 + 1, s1 + 2 s2 + 2, s2 + 1, s1 2 s2 + 2]
Note that ScalarMultiply(e1,s1) is used here instead of s1*e1 since Maple does
not know whether s1 is a scalar.
We can now set up a system of equations with the two conditions on the
scalar products and let Maple solve it:
> solve({DotProduct(u, e1)=0, DotProduct(u, e2)=0});
_
s2 =
1
9
, s1 = 1
_
2.1.5 Examples with Lines in R
3
Do the lines
L
1
:
_
_
_
x = 2 + 3t
y = 5 t
z = 3 5t
L
2
:
_
_
_
x = 11 t
y = 2 + t
z = 4 2t
intersect each other? And, if this is the case, what is their point of intersection?
In Maple, lines given by parametric equations are handled by letting the
right-hand sides be the entries of a Vector:
> L1:=Vector([-2+3*t,5-t,3-5*t]);
L
1
:=
_
_
2 + 3t
5 t
3 5t
_
_
> L2:=Vector([11-s,-2+s,-4-2*s]);
L
2
:=
_
_
11 s
2 +s
4 2s
_
_
Note that the parameters involved in the parametric equations of the two lines
must be carried in dierent variables.
18
2.2. MATRICES
The fact that the lines intersect each other results in the solvability of the
system of equations given by L
1
= L
2
. However, it turns out that In Maple it
is easier to write this system in the form L
1
L
2
= 0 and consider only the left
hand side of this:
> L1-L2;
_
_
13 + 3t +s
7 t s
7 5t + 2s
_
_
Since the command solve requires that the solution to such a system is a set, we
can not solve the system directly, but we have to convert the right-hand side to a
set (that is, the set of all points in R
3
of the form (13+3t+s, 7ts, 75t+2s)
):
> convert(%, set);
{13 + 3t +s, 7 t s, 7 5t + 2s}
and nally solve the system L
1
L
2
= 0:
> solve(%);
{t = 3, s = 4}
The point of intersection is determined by letting t = 3 in the equation for L
1
,
or s = 4 in the equation for L
2
; this can be done with eval
> eval(L1, %);
_
_
7
2
12
_
_
2.2 Matrices
2.2.1 Input
Matrices are created using the command Matrix. The syntax is similar to the
command Vector.
A square 3 3 matrix with all entries equal to zero is created via:
> Matrix(3);
_

_
0 0 0
0 0 0
0 0 0
_

_
En 2 3 matrix whose entries are all equal to 8 can be created by:
> Matrix(2, 3, 8);
19
CHAPTER 2. LINEAR ALGEBRA
_
8 8 8
8 8 8
_
However, to create a matrix with dierent entries, one has to list the entries on
each row like in the example below. Notice the double square-brackets used in
the syntax:
> A:=Matrix([[1, 2], [3, 4]]);
A :=
_
1 2
3 4
_
When a matrix is dened, parts of it can be accessed via the indices of the
elements in question:
> A[2, 2]*A[2, 1..2];
[12, 16]
2.2.2 Matrix Commands in Maple
Most of the operations that are dened for matrices are available in Maple:
Mathematics Maple Explanation
A +B A+B; addition
A B A-B; subtraction
sA s*A; multiplication by a scalar
4
AB A.B; matrix product
A
t
Transpose(A); transpose
A
1
A(-1); matrix inverse
I or E IdentityMatrix(n); identity matrix (of order n)
NullSpace(A); null space
Rank(A); rang
LinearSolve(A, b); solve the system of Ax = b
QRDecomposition(A); QR-faktorization
det A or D(A) Determinant(A); determinant
trA Trace(A); trace
Eigenvalues(A); eigenvalues
Eigenvectors(A); eigenvectors and eigenvalues
map(f, A); Apply the function f on all
the entries of the matrix A.
There are many functions and operations dened on matrices that are avail-
able in Maple. To nd more information, see the Help section available in the
LinearAlgebra package.
4
If the scalar, s, is a free variable, then Maple does not perform the multiplication. One
should use the command ScalarMultiply(A,s);
20
2.2. MATRICES
2.2.3 Orthogonal Matrices
Determine the numbers a, b and c such that the matrix
1
7
_
_
2 6 b
3 2 c
6 a 2
_
_
becomes orthogonal
5
.
Solution: Begin by dening the matrix:
> Q:=1/7*Matrix([[2, 6, b], [3, 2, c], [6, a, 2]]);
Q :=
_

_
2
7
6
7
1
7
b
3
7
2
7
1
7
c
6
7
1
7
a
2
7
_

_
To check whether a matrix Q is orthogonal one has to check the equality Q
t
Q =
E (or QQ
t
= E). The equality can be checked in Maple, but it turns out that
it is easier to proceed as in section 2.1.5, that is:
- consider the right-hand side of the equality Q
t
Q E = 0 :
> Q.Transpose(Q)-IdentityMatrix(3);
_

9
49
+
1
49
b
2
18
49
+
1
49
bc
12
49
+
6
49
a +
2
49
b
18
49
+
1
49
bc
36
49
+
1
49
c
2
18
49
+
2
49
a +
2
49
c
12
49
+
6
49
a +
2
49
b
18
49
+
2
49
a +
2
49
c
9
49
+
1
49
a
2
_

_
- convert it into a set:
> convert(%, set);
_
18
49
+
1
49
bc,
12
49
+
6
49
a +
2
49
b,
18
49
+
2
49
a +
2
49
c,
9
49
+
1
49
b
2
,
36
49
+
1
49
c
2
,
9
49
+
1
49
a
2
_
- solve the system Q
t
Q E = 0
> solve(%);
{a = 3, c = 6, b = 3}
- and nally, to get Q, write:
> eval(Q, %);
5
Exercise 7, chapter 7, Linear Algebra, K. G. Andersson, 2000
21
CHAPTER 2. LINEAR ALGEBRA
_

_
2
7
6
7
3
7
3
7
2
7
6
7
6
7
3
7
2
7
_

_
2.2.4 Determinants
Determinants are computed using the command Determinant. By dening
some matrices:
> A:=Matrix([[1, 2], [3, 4]]);
A :=
_
1 2
3 4
_
> B:=Matrix([[2, 4], [6, 8]]);
B :=
_
2 4
6 8
_
and compute their determinants, one can check (not prove) the product rule for
determinants:
> Determinant(A); Determinant(B); Determinant(A.B);
2
8
16
2.2.5 Systems of Equations
Systems of equations of the type Ax = b are solved A
1
b, provided that ( A) is
invertible. (Let A be the matrix from the previous example.):
> b:=Vector([5, 7]);
b :=
_
5
7
_
> A(-1).b;
_
3
4
_
22
2.2. MATRICES
One could also use one of Maples special commands (there are several) to solve
such systems of equations:
> LinearSolve(A, b);
_
3
4
_
In easier cases it does not matter which method one chooses to use. LinearSolve
is faster, and this method is to prefer if the matrix involved is very large. Also,
this command manages to determine the structure of the solutions to systems of
equations Ax = b having innitely many solutions (det A = 0 and the solutions
depend on one or more parameters).
2.2.6 Functions of Matrices and Vectors
Certain commands and functions that are dened for real numbers are even
dened for vectors and matrices. One such command is evalf:
> C:=Pi*Matrix([[-1/2, 5/6], [5/6, -1/2]]);
_

1
2

5
6

5
6

1
2

_

_
> evalf(C);
_
1.570796327 2.617993878
2.617993878 1.570796327
_
If one would like to compute the sine of each entry of some matrix or vector,
one could use the command map:
> map(sin, C);
_

_
1
1
2
1
2
1
_

_
Moreover, there are commands that enables one to compute functions of matri-
ces:
Mathematics Maple
e
A
MatrixExponential(A);
A
x
MatrixPower(A, x);
f(A) MatrixFunction(A, f(x), x);
With the same matrix C as above one could for instance compute sin C ( to
spare some time one could simplify the answer directly as well):
> simplify(MatrixFunction(C, sin(x), x));
23
CHAPTER 2. LINEAR ALGEBRA
_

_
1
2

3 0
0
1
2

3
_

_
2.2.7 Linear Maps
Using Maple one can illustrate geometrically the action of certain linear maps.
In what follows we describe how one can illustrate what a rotation around the
origin does to some object. To this end it is appropriate to consider some non-
symmetric object, like for instance, an L with corner (1, 1) and endpoints (1, 3)
and (2, 1). To be able to work with this geometric object we store the coordi-
nates of the three points as the columns of a matrix:
> L:=Matrix([[1, 1, 2], [3, 1, 1]]);
L :=
_
1 1 2
3 1 1
_
On the other hand, the command plot requires that the coordinates are given
in a list of lists, so the matrix above must be converted into such a list:
> l:=convert(Transpose(L), listlist);
l := [[1, 3], [1, 1], [2, 1]]
before we can draw our L:
> plot(l, x=-4..4, y=-4..4, scaling=constrained, color=black);
4
3
2
1
0
1
2
3
4
y
4 3 2 1 1 2 3 4
x
To see what a rotation around the origin does to the geometric object above,
dene rst a general matrix for rotation around the origin in a plane as a func-
tion (rather than considering a rotation by a certain angle):
> Rot:=v->Matrix([[cos(v), -sin(v)], [sin(v), cos(v)]]);
24
2.2. MATRICES
Rot := v > Matrix([[cos(v), sin(v)], [sin(v), cos(v)]])
It is now easy to consider a rotation by a certain angle (in this case

6
):
> R:=Rot(Pi/6);
R :=
_

_
1
2

3
1
2
1
2
1
2

3
_

_
The action of the rotation on the L above is represented by:
Lr:=R.L;
Lr :=
_

_
1
2

3
3
2
1
2

3
1
2

3
1
2
1
2
+
3
2

3
1
2
+
1
2

3 1 +
1
2

3
_

_
Finally, the result (the matrix above) can be converted to a list and represented
as a geometrical object on the plane:
lr:=convert(Transpose(Lr), listlist);
lr :=
__
1
2

3
3
2
,
1
2
+
3
2

3
_
,
_
1
2

3
1
2
,
1
2
+
1
2

3
_
,
_

3
1
2
, 1 +
1
2

3
__
> plot(lr, x=-4..4, y=-4..4, scaling=constrained, color=black);
4
3
2
1
0
1
2
3
4
y
4 3 2 1 1 2 3 4
x
2.2.8 Eigenvalues and Eigenvectors
Let A be the matrix given by:
25
CHAPTER 2. LINEAR ALGEBRA
> A:=Matrix([[3, -1, 0], [-1, 2, -1], [0, -1, 3]]);
_

_
3 1 0
1 2 1
0 1 3
_

_
To compute the eigenvalues of A write:
> Eigenvalues(A);
_

_
3
1
4
_

_
To compute the eigenvectors of A one uses the command Eigenvectors(A). This
command produces both the eigenvalues and the eigenvectors of A. In order to
be able to work with the computed eigenvalues and the corresponding eigenvec-
tors in Maple, one could save their values in two dierent variables, and T
respectively:
> (lambda, T):=Eigenvectors(A);
, T :=
_

_
3
1
4
_

_
,
_

_
1 1 1
0 2 1
1 1 1
_

_
Notice that the eigenvectors are given as columns of a matrix. By denition,
e = Ae where e is the eigenvector corresponding to . This can easily be
checked; here is the rst eigenvalue and its corresponding eigenvector:
> e1:=T[1..3, 1];
e1 :=
_

_
1
0
1
_

_
> lambda[1]*e1;
_

_
3
0
3
_

_
> A.e1;
_

_
3
0
3
_

_
26
2.2. MATRICES
2.2.9 Diagonalization
For a matrix A that can be diagonalized, the diagonal matrix T is the matrix
whose columns are the eigenvectors of A, which is exactly the output of the
command Eigenvectors(A). With A and T as in the previous example, the
matrix A is diagonalized as follows:
> R:=T(-1).A.T;
R :=
_

_
3 0 0
0 1 0
0 0 4
_

_
so the eigenvalues are the entries on the main diagonal in the diagonal matrix. (
Note that the diagonal matrix cannot be denoted by D in Maple since D means
the dierentiation operator.)
The diagonalized matrix can be used to compute more complicated functions
of matrices. An example that shows how one can determine a matrix B that
satises B
2
= A (i.e. a matrix which in some sense is

A), is given below.


First, dene a matrix S that satises S
2
= R. Such a matrix is easily
computed by taking the square root of the diagonal entries of the (diagonal)
matrix R:
> S:=map(sqrt, R);
S :=
_

3 0 0
0 1 0
0 0 2
_

_
Actually, it is easier (from Maples point of view) to compute the square root
of all the entries of R, which has of course no eect on the zero entries.
The matrix B is then given by B = TST
1
:
> B:=T.S.T(-1);
B :=
_

_
1
2

3 +
5
6

1
3

1
2

3 +
5
6

1
3
4
3

1
3

1
2

3 +
5
6

1
3
1
2

3 +
5
6
_

_
One can compute B
2
to check whether the computations carried out so far are
correct:
> B2;
27
CHAPTER 2. LINEAR ALGEBRA
_

_
_
1
2

3 +
5
6
_
2
+
1
9
+
_

1
2

3 +
5
6
_
2
1 2
_
1
2

3 +
5
6
__

1
2

3 +
5
6
_
+
1
9
1 2 1
2
_
1
2

3 +
5
6
__

1
2

3 +
5
6
_
+
1
9
1
_
1
2

3 +
5
6
_
2
+
1
9
+
_

1
2

3 +
5
6
_
2
_

_
The result above does not really look like as the original matrix A, but if we
simplify
6
:
> simplify(%);
_

_
3 1 0
1 2 1
0 1 3
_

_
we see that B
2
= A.
One could also compare this result to the result given by MatrixPower or
MatrixFunction:
> simplify(MatrixPower(A, 1/2));
_

_
1
2

3 +
5
6

1
3
5
6

1
2

1
3
4
3

1
3
5
6

1
2

3
1
3
1
2

3 +
5
6
_

_
6
In older versions of Maple one would have to write map(simplify,%); instead.
28

Anda mungkin juga menyukai