Matlab/Octave

We can define a matrix in either of the following forms:

> A = [4 0 5; -1 3 2]

> A = [4 0 5
-1 3 2]
You can execute basic matrix operations as follows.
> 5 * A

> A + B

> A * B

EXAMPLES 1. Let $ A =
\left[\begin{array}{ccc}
4 & 0 & 5 \\
-1 & 3 & 2
\end{array}\right]$, $ B =
\left[\begin{array}{ccc}
1 & 1 & 1 \\
3 & 5 & 7
\end{array}\right]$, and $ C =
\left[\begin{array}{cc}
2 & 3 \\
0 & 1
\end{array}\right]$.

  1. Compute $ A + B$.
  2. Is the matrix sum $ A + C$ defined?
  3. Compute $ 2B$.
  4. Compute $ A - 2B$.

EXAMPLES 2. Compute $ A B$ in each of the following:

  1. $ A =
\left[\begin{array}{cc}
2 & 3 \\
1 &-5
\end{array}\right]$ and $ B =
\left[\begin{array}{ccc}
4 & 3 & 6 \\
1 &-2 & 3
\end{array}\right]$.
  2. $ A =
\left[\begin{array}{ccc}
2 & -5 & 0 \\
-1 & 3 &-4 \\
6 & -8 &-7 \\
-3 & 0 & 9
\end{array}\right]$ and $ B =
\left[\begin{array}{cc}
4 &-6 \\
7 & 1 \\
3 & 2
\end{array}\right]$.

EXAMPLE 3 Let $ A =
\left[\begin{array}{cc}
5 & 1 \\
3 &-2
\end{array}\right]$ and $ B =
\left[\begin{array}{cc}
2 & 0 \\
4 & 3
\end{array}\right]$. Show that these matrices do not commute.

Matlab/Octave can compute the power A^k and the transpose A' of A as follows.

> A^5

> A'

EXAMPLE 4. Let $ B =
\left[\begin{array}{ccc}
-5 & 1 & 0\\
2 &-3 & 4
\end{array}\right]$ and $ C =
\left[\begin{array}{cccc}
1 & 1 & 1 & 1 \\
-3 & 5 &-2 & 7
\end{array}\right]$. Compute $ B^T$ and $ C^T$.

EXAMPLE 5. Write the function rmatrix() that will create an $ n\times m$ matrix with random entries. Then create a $ 3\times 3$ matrix with random entries between $ -9$ and $ 9$.



Department of Mathematics
Last modified: 2005-10-21