Documente Academic
Documente Profesional
Documente Cultură
Introduction to MATLAB
The purpose of this introduction is to illustrate some basic MATLAB commands for linear
algebra. It is suggested that you complete the following series of simple examples while
actually working at the computer terminal. Once you have signed on to MATLAB, you
should type in your commands to the right of the prompt >>.
1. Enter the matrix
冤 冥
1 2 3
a 4 5 6
7 8 0
by typing a ⴝ [1 2 3; 4 5 6; 7 8 0] and hitting the return or enter key. Be sure to
separate the entries in each row by spaces and to terminate the rows with semicolons.
MATLAB should return the following matrix.
1 2 3
a 4 5 6
7 8 0
2. Perform the following elementary commands on the matrix a. You should obtain the
indicated results.
(a) inv冇a冈
1.7778 0.8889 0.1111
ans 1.5556 0.7778 0.2222
0.1111 0.2222 0.1111
(b) a
1 4 7
ans 2 5 8
3 6 0
(c) a*inv冇a冈
1.0000 0 0.0000
ans 0.0000 1.0000 0
0.0000 0.0000 1.0000
332600_tech_guide.qxp 4/22/08 4:59 PM Page 3
(d) 2*a
2 4 6
ans 8 10 12
14 16 0
(e) rref 冇a冈
1 0 0
ans 0 1 0
0 0 1
(f ) det冇a冈
ans 27
(g) rank冇a冈
ans 3
(h) diag冇a冈
1
ans 5
0
3. Enter the matrix b ⴝ [7; 16; 7] . You can solve the system of linear equations ax b in
different ways:
(a) a\ b
1
ans 0
2
(b) c ⴝ [a b] and then rref 冇c冈
1 2 3 7
c4 5 6 16
7 8 0 7
rref冇c冈
1 0 0 1
ans 0 1 0 0
0 0 1 2
4. Enter the matrices A ⴝ [1 2; 3 4] and B ⴝ [2 0; ⴚ3 5] and perform the following
matrix operations. Notice that MATLAB distinguishes between upper- and lowercase
letters; using the uppercase letter B to label the matrix above is not the same as using
the lowercase letter b.
332600_tech_guide.qxp 4/22/08 4:59 PM Page 4
(a) A 1 B
3 2
ans
0 9
(b) A ⴚ B
1 2
ans
6 1
(c) A * B
4 10
ans
6 20
5. What do the following commands do?
(a) zeros冇3, 5冈
(b) eye(5)
(c) rand(6)
(d) hilb(6)
6. Describe the effects of the following commands on the matrix a ⴝ [1 2 3; 4 5 6; 7 8 0].
(a) a(2, 3)
(b) a(2, :)
(c) a(:, 3)
7. You can obtain more information about MATLAB by typing help.
8. You can exit MATLAB by typing exit.
Introduction to Maple
The purpose of this introduction is to illustrate some basic Maple commands for linear
algebra. It is suggested that you complete the following series of simple examples while
actually working at the computer terminal. Once you have signed on to Maple, you should
type in your commands to the right of the prompt >.
Begin by loading the linear algebra package that comes with Maple by typing
with(linalg); and hitting the return or enter key. Notice that all commands in Maple
terminate with a semicolon ;.
1. Enter the matrix
冤 冥
1 2 3
a 4 5 6
7 8 0
by typing a: ⴝ matrix 冇[[1, 2, 3], [4, 5, 6], [7, 8, 0]]冈; and hitting the return or enter
key. Be sure to separate the entries in each row by commas and place each row of the
matrix within brackets. Maple should return the following matrix.
332600_tech_guide.qxp 4/22/08 4:59 PM Page 5
冤 冥
1 2 3
a: 4 5 6
7 8 0
2. Perform the following elementary commands on the matrix a. You should obtain the
indicated results.
(a) inverse(a);
冤 冥
16
8
9 9 19
14
79
2
9 9
19
2
9 19
(b) transpose(a);
冤 冥
1 4 7
2 5 8
3 6 0
(c) multiply(a, inverse(a));
冤 冥
1 0 0
0 1 0
0 0 1
(d) scalarmul(a, 2);
冤 冥
2 4 6
8 10 12
14 16 0
(e) rref(a);
冤 冥
1 0 0
0 1 0
0 0 1
(f) det(a);
27
(g) rank(a);
3
(h) diag(a, inverse(a));
冤 冥
1 2 3 0 0 0
4 5 6 0 0 0
7 8 0 0 0 0
0 16 8
0 0 9 9 19
14
79
2
0 0 0 9 9
0 19
2
0 0 9 19
332600_tech_guide.qxp 4/22/08 4:59 PM Page 6
3. Enter the column matrix b: ⴝ transpose冇matrix冇[[7, 16, 7]]冈冈;. You can solve the
system of linear equations ax b in different ways:
(a) linsolve(a, b);
冤冥
1
0
2
(b) c: ⴝ augment冇a, b冈; and then rref(c);
冤 冥
1 2 3 7
c: 4 5 6 16
7 8 0 7
冤 冥
1 0 0 1
0 1 0 0
0 0 1 2
4. Enter the matrices A: ⴝ matrix冇[[1, 2], [3, 4]]冈; and B: ⴝ matrix冇[[2, 0], [ⴚ3, 5]]冈;
and perform the following matrix operations. Notice that Maple distinguishes between
upper- and lowercase letters; using the uppercase letter B to label the matrix above is not
the same as using the lowercase letter b.
(a) matadd冇A, B冈;
冤0 冥
3 2
9
(b) matadd冇A, B, 1, ⴚ1冈;
1
冤 冥
2
6 1
(c) multiply冇A, B冈;
4
冤6 冥
10
20
5. What do the following commands do?
(a) matrix共3, 5, 0兲;
(b) band冇[1], 5冈;
(c) randmatrix冇4, 6冈;
(d) hilbert冇6冈;
6. Describe the effects of the following commands on the matrix a: ⴝ matrix
冇[[1, 2, 3] , [4, 5, 6] , [7, 8, 0]]冈;.
(a) submatrix冇a, 2..2, 3..3冈;
(b) submatrix冇a, 2..2, 1..3冈;
(c) submatrix冇a, 1..3, 3..3冈;
7. You can obtain more information about a particular topic, such as eigenvalues, by typing
?eigenvalues.
8. You can exit Maple by choosing Exit from the file menu.
332600_tech_guide.qxp 4/22/08 4:59 PM Page 7
Introduction to Mathematica
The purpose of this introduction is to illustrate some basic Mathematica commands for
linear algebra. It is suggested that you complete the following series of simple examples
while actually working at the computer terminal. Once you have signed on to Mathematica,
you should type in your commands to the right of the prompt.
1. Enter the matrix
冤 冥
1 2 3
a 4 5 6
7 8 0
by typing a ⴝ {{1, 2, 3}, { 4, 5, 6}, { 7, 8, 0}} and evaluating the expression (cell). Be sure
to separate the entries in each row by commas and place each row of the matrix within
braces. Mathematica should return the following matrix. You can obtain a more natural
matrix display by typing %//MatrixForm.
Out[1]
再再1, 2, 3冎, 再4, 5, 6冎, 再7, 8, 0冎冎
In[2]
%//MatrixForm
Out[2]//MatrixForm
冢 冣
1 2 3
4 5 6
7 8 0
2. Perform the following elementary commands on the matrix a. You should obtain the
indicated results.
(a) Inverse[a] //MatrixForm
Out[3]//MatrixForm
冢 冣
16 8
9 9 19
14
79
2
9 9
1 2
9 9 19
(b) Transpose[a]
Out[4]
再再1, 4, 7冎, 再2, 5, 8冎, 再3, 6, 0冎冎
(c) a.Inverse[a]
Out[5]
再再1, 0, 0冎, 再0, 1, 0冎, 再0, 0, 1冎冎
(d) 2*a
Out[6]
再再2, 4, 6冎, 再8, 10, 12冎, 再14, 16, 0冎冎
332600_tech_guide.qxp 4/22/08 4:59 PM Page 8
(e) RowReduce[a]
Out[7]
再再1, 0, 0冎, 再0, 1, 0冎, 再0, 0, 1冎冎
(f) Det[a]
Out[8]
27
3. Enter the matrix b ⴝ { 7, 16, 7 }. You can solve the system of linear equations ax ⴝ b in
different ways:
(a) LinearSolve[a, b]
Out[10]
再1, 0, 2冎
(b) c ⴝ Table[Append[a[[i]], b[[i]]], { i, 1, 3}] and then RowReduce[c]
Out[11]
再再1, 2, 3, 7冎, 再4, 5, 6, 16冎, 再7, 8, 0, 7冎冎
In[12]
RowReduce[c]//MatrixForm
Out[12]//MatrixForm
冢 冣
1 0 0 1
0 1 0 0
0 0 1 2
4. Enter the matrices A ⴝ {{1, 2}, {3, 4}} and B ⴝ {{2, 0}, {ⴚ3, 5}} and perform the
following matrix operations. Notice that Mathematica distinguishes between upper- and
lowercase letters; using the uppercase letter B to label the matrix above is not the same
as using the lowercase letter b.
(a) A 1 B
Out[15]
再再3, 2冎, 再0, 9冎冎
(b) A ⴚ B
Out[16]
再再1, 2冎, 再6, 1冎冎
(c) A.B 共Matrix multiplication is not A * B.兲
Out[17]
再再4, 10冎, 再6, 20冎冎
5. What do the following commands do?
(a) Table[0, { i, 1, 3}, { j, 1, 5}]
(b) IdentityMatrix[5]
(c) Table [Random[Integer, { ⴚ 100, 100}], { 4}, {6 }]//MatrixForm
(d) Table[1/冇i j 1冈, { i, 1, 6}, { j, 1, 6}]
332600_tech_guide.qxp 4/22/08 4:59 PM Page 9
6. Describe the effects of the following commands on the matrix a ⴝ {{1, 2, 3}, { 4, 5, 6 },
{7, 8, 0}}.
(a) a[[2, 3]]
(b) a[[2]]
(c) Transpose[a] [[3]]
7. You can obtain more information about a particular topic, such as determinants, by
typing ?Det.
8. You can exit Mathematica by choosing Exit from the file menu.
Introduction to Derive
The purpose of this introduction is to illustrate some basic Derive commands for linear
algebra. It is suggested that you complete the following series of simple examples while
actually working at the computer terminal.
1. Enter the matrix
冤 冥
1 2 3
a 4 5 6
7 8 0
by using the Author/Expression feature—i.e., a: ⴝ [[1, 2, 3] , [4, 5, 6] , [7, 8, 0]] and
hitting the return or enter key. Be sure to separate the entries in each row by commas
and place each row of the matrix within brackets. Derive should return the following
matrix.
冤 冥
1 2 3
a: 4 5 6
7 8 0
2. Perform the following elementary operations on the matrix a by typing the given
expression and Simplifying it. You should obtain the indicated results.
(a) a^ⴚ1
冤 冥
16
8
9 9 19
14
9 79 2
9
19 2
9 19
(b) a`
冤 冥
1 4 7
2 5 8
3 6 0
332600_tech_guide.qxp 4/22/08 4:59 PM Page 10
(c) a * a^ⴚ1
冤 冥
1 0 0
0 1 0
0 0 1
(d) a * 2
冤 冥
2 4 6
8 10 12
14 16 0
(e) Row_Reduce(a)
冤 冥
1 0 0
0 1 0
0 0 1
(f) det(a)
27
3. Enter the column matrix b: ⴝ 关关7兴 , 关16兴 , 关7兴兴 . You can solve the system of linear
equations ax ⴝ b in several ways:
(a) You can row reduce the augmented matrix 关a ⯗ b兴.
Row_Reduce(a, b)
冤 冥
1 0 0 1
0 1 0 0
0 0 1 2
(b) You can Simplify the equation [[x], [ y], [z]] ⴝ a^ⴚ1* b.
冤 冥
x1
y0
z2
(c) You can Expand the equation a[[x], [ y], [z]] ⴝ b. Then Solve the Expression by
choosing solution variables x, y, and z and choosing Solve.
关x 1, y 0, z 2兴
4. Enter the matrices “A”: ⴝ [[1, 2] , [3, 4]] and “B”: ⴝ [[2, 0] , [ⴚ3, 5]] and perform the
following matrix operations.
(a) “A” 1 “B”
冤30 冥
2
9
(b) “A” ⴚ “B”
1
冤 冥
2
6 1
332600_tech_guide.qxp 4/22/08 4:59 PM Page 11
Graphing Utilities
The following chart lists various graphing utilities* and their built-in matrix capabilities.
For example, the first row indicates that all the graphing utilities can perform matrix
addition.
Matrix operation Voyage TI-92 TI-89 TI-86 TI-84 TI-83 TI-83
200 Plus Plus
Addition x x x x x x x
Scalar multiplication x x x x x x x
Multiplication x x x x x x x
Elementary row operations x x x x x x x
Reduced row-echelon form x x x x x x x
Determinant x x x x x x x
Inverse x x x x x x x
Transpose x x x x x x x
Norm x x x x
Power x x x x x x x
Eigenvalues x x x x
LU-decomposition x x x x
Identity matrix x x x x x x x
Random matrix x x x x x x x
Concatenate matrices x x x x x x x
Condition number x
Complex matrices x x x x
Vectors x x x x
Technology Pitfalls
Many matrix computations in linear algebra can be performed by modern graphing utilities
and computer software programs. However, you should be aware that these devices are
not perfect because of roundoff error—that is, the graphing utility or computer must
approximate fractions by decimals either by rounding off the last digit or by truncating.
For example, evaluate 16 using your graphing utility. On the TI-86 you will get
0.166666666667, which is not correct, because the graphing utility has rounded the last
digit up. To analyze this more closely, evaluate 关共16 兲 3兴 0.5. Do you get the expected
answer of 0? Normally this kind of rounding will not affect your answers to problems in
linear algebra, but it can happen. Here are a couple of simple examples.
冤 冥
3 11
1. Calculate the determinant of the matrix A on the TI-86. Then calculate the
2 6
greatest integer of the determinant, int det A. Again, roundoff error has produced an error.
2. The Hilbert matrix of order 6 is
1 1 1 1 1
冤 冥
1 2 3 4 5 6
1 1 1 1 1 1
2 3 4 5 6 7
1 1 1 1 1 1
3 4 5 6 7 8
H 1 1 1 1 1 1 .
4 5 6 7 8 9
1 1 1 1 1 1
5 6 7 8 9 10
1 1 1 1 1 1
6 7 8 9 10 11
This matrix is notorious for causing poor results in matrix computations. Try calculating
inv共H兲 H to see if you obtain the identity matrix.
You might find it interesting to discover other examples for which your graphing
utility gives erroneous results. In general, you should always be aware that such errors are
possible, and accept the outputs of your graphing utility with some skepticism.p
332600_keystrokes.qxp 4/22/08 4:58 PM Page 13
Add ⫺2 times the first row to the third row to produce a new third row.
Original Matrix
⫺4
冤 冥
1 2 3
(c) 0 3 ⫺2 ⫺1
2 1 5 ⫺2
⫺1
冤 冥
1 2 2
(f) 0 0 0 0
0 1 2 ⫺4
⫺1
冤1 冥冤 冥
1 2 2
(c)
1 1 ⫺1
2⫻2 2⫻2
冤 冥
1 0
A⫽ 1 0 ⫺1
⫺6 2 3
Keystrokes for TI-83
Enter the matrix into matrix A.
To find the inverse, use the following keystrokes.
MATRX 1 x ⫺1 ENTER
冤 冥
1 3 0
⫺1 1 0 2
A⫽ .
0 2 0 3
3 4 0 ⫺2
冤2 冥
1 4
Find the eigenvalues and corresponding eigenvectors of the matrix A ⫽ .
3
Keystrokes for TI-83, TI-83 Plus, and TI-84 Plus
These graphing utilities cannot find eigenvalues.
1 冈 ENTER
332600_keystrokes.qxp 4/22/08 4:58 PM Page 28
>
>
Programming Syntax for MATLAB
MATLAB cannot calculate inner products.
冤 冥冤 冥 冤冥
1 1 0
c0
1 2 ⫽ 1 .
c1
1 3 3
→
→
F5
→
→
F5
F5
F5
冤 冥
1 0 0 0
0 1 5 ⫺10
A⫽ .
1 0 2 0
1 0 0 3