Font (2 3)
-+
Letter spacing (4 5)
- +
Word spacing (6 7)
- +
Line spacing (8 9)
-+
2.2 Constructing a diagonal matrix
In some cases we may want to construct a diagonal matrix. The function diag is available for this. diag may be used in several ways.
If a single scalar input n is supplied then the
identity matrix
is created.
For instance
I <- diag(10)
creates a identity matrix. If two scalar inputs k and n are supplied then the
matrix
is created, e.g.
I <- diag(5,7)
creates a matrix with diagonal elements 5.
If a single vector input is supplied then a diagonal matrix
with diagonal elements corresponding to the elements of
that vector is created e.g.
H <- diag(c(1,2,3,4))
creates the matrix
In the next section we will see that diag can also be used
to extract the diagonal elements of a matrix.
Workshop 1: Constructing a matrix (I)
Construct a matrix
Workshop 2: Constructing a matrix (II)
Construct a
matrix of the form:
Quiz 1: Constructing a matrix (III)
Which of the following commands creates the matrix