[R] Solving Matrices

Douglas Bates bates at stat.wisc.edu
Fri Apr 16 14:18:40 CEST 2004


"Richard A. O'Keefe" <ok at cs.otago.ac.nz> writes:

> Elizabeth (etb <lizzy at noradd.org>) wrote:
> 	     In execises 39-42, determine if the columns of the matrix span
> 	     R4:
>                    4	
> Presumably that's R, 4-dimensional real space.
> 
> 	(or x <- matrix(data=c(7, -5, 6, -7, 2, -3, 10, 9, -5, 
> 	                       4, -2, 2, 8, -9, 7, 15), nrow=4, ncol=4)
> 	
> 	That is the whole of the question and I suppose that the way to answer
> 	this is by determining if:
> 	
> 		1. For each b in Rm, the equation Ax = b has a solution, or
> 		2. A has a pivot position in every row,
> 	
> 	where A is an (m X n) matrix.
...
> For another look at this, try the singular-value decomposition.
> ?svd
> 
>     > svd(x)$d
>     [1] 2.436185e+01 1.376648e+01 6.163148e+00 9.241655e-16
> 
> Again, we see a pretty strong hint that the matrix is close to rank 3.

Thanks for the suggestion of looking at the svd.  In fact the svd
gives two linear combinations of the elements of x that are (nearly)
zero - one for the rows and one for the columns.

> sv = svd(x)
> sv
$d
[1] 2.436185e+01 1.376648e+01 6.163148e+00 2.708761e-16

$u
           [,1]       [,2]       [,3]         [,4]
[1,] -0.3797190 -0.5126130  0.4176563 6.469966e-01
[2,]  0.4193577  0.3345945 -0.3773834 7.548294e-01
[3,] -0.4980502 -0.2953438 -0.8153024 1.387779e-16
[4,] -0.6571899  0.7335165  0.1357460 1.078328e-01

$v
           [,1]       [,2]       [,3]       [,4]
[1,] -0.1290047 -0.8838820 -0.1673698 -0.4172502
[2,] -0.5300387  0.1176192 -0.8054078  0.2377877
[3,]  0.1337233  0.4328750 -0.2751384 -0.8479600
[4,] -0.8273662  0.1324295  0.4975987 -0.2243281

> x %*% sv$v[,4]
              [,1]
[1,] -8.881784e-16
[2,]  1.776357e-15
[3,] -4.440892e-16
[4,] -2.220446e-15
> sv$u[,4] %*% x
             [,1]          [,2]         [,3]          [,4]
[1,] 2.220446e-16 -4.440892e-16 5.551115e-16 -3.108624e-15

The left and right singular vectors sv$u[,4] and sv$v[,4] have been
normalized to have unit length and do not have a simple expression as
integers.  However, if we divide by the smallest non-zero element in
the vector we get

> sv$u[,4]/sv$u[4,4]
[1] 6.000000e+00 7.000000e+00 1.286973e-15 1.000000e+00

and now we can verify that

> 6 * x[1,] + 7 * x[2,] + x[4,]
[1] 0 0 0 0

Obtaining the relationship of the columns as integers is more
difficult (probably intentionally) but we can get a hint by looking at
small differences in magnitudes

> sv$v[,4]/(sv$v[2,4] + sv$v[4,4])
[1] -31.00000  17.66667 -63.00000 -16.66667

from which it is easy to see that

> 3*(sv$v[,4]/(sv$v[2,4] + sv$v[4,4]))
[1]  -93   53 -189  -50

> x %*% c(93, -53, 189, 50)
     [,1]
[1,]    0
[2,]    0
[3,]    0
[4,]    0




More information about the R-help mailing list