On April 15th, Elizabeth wrote: <snip>> In execises 39-42, determine if the columns of the matrix span > R4:<snip>>(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 <snip>Have you tried det(x) and/or eigen(x) ? A zero determinant (within computer precision) means that the matrix does not have full rank, i.e. it does not span R4. Count how many eigenvalues are zero (within computer precision). What does this tell you?> In the Solutions Manual, there is mention of the gauss() and >bgauss() functions which apparently written by Lay - these are to >speed up matrix reduction but I have not noticed these functions in R.Have you encountered speed problems in R? Do you really need these functions in R in addition to solve(), backsolve() etc. ? If you just want to learn about how they work you could have a look at the Matlab code for these functions (which I think you have access to). You could even try rewriting them in R yourself. Hope this helps, James
wettenhall at wehi.EDU.AU writes:> On April 15th, Elizabeth wrote: > <snip> > > In execises 39-42, determine if the columns of the matrix span > > R4: > <snip> > >(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 <snip> > > Have you tried det(x) and/or eigen(x) ?An alternative is to determine the condition number (kappa) of the matrix> x <- matrix(data=c(7, -5, 6, -7, 2, -3, 10, 9, -5,+ 4, -2, 2, 8, -9, 7, 15), nrow=4, ncol=4)> kappa(x)[1] 5.31557e+17 A very large condition number like this indicates that the matrix is computationally singular.
>>On April 15th, Elizabeth wrote: >><snip> >> >>>(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)qr(x)$rank gives the rank qr.R(qr(x)) gives the R part (an upper triangular matrix similar to the one produced by Gauss elimination). With the given matrix, we get rank 3, but the last row of qr.R(qr(x)) is not 0 due to rounding errors. -- Erich Neuwirth, Computer Supported Didactics Working Group Visit our SunSITE at http://sunsite.univie.ac.at Phone: +43-1-4277-38624 Fax: +43-1-4277-9386
<wettenhall <at> wehi.EDU.AU> writes: : : On April 15th, Elizabeth wrote: : <snip> : > In execises 39-42, determine if the columns of the matrix span : > R4: : <snip> : >(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 <snip> : : Have you tried det(x) and/or eigen(x) ? : : A zero determinant (within computer precision) means that the matrix does : not have full rank, i.e. it does not span R4. In this case we can avoid the computer precision problem by noting that the determinant of an integer matrix is always integer, so: round(det(x)) will be non-zero iff the square integer matrix x is of full rank.
James writes:> Have you tried det(x) and/or eigen(x) ? > > A zero determinant (within computer precision) means that the matrix > does not have full rank, i.e. it does not span R4. Count how many > eigenvalues are zero (within computer precision). What does this > tell you?I'm still on chapter 1 and we have not yet covered eigenvalues so this is a bit fuzzy.> > In the Solutions Manual, there is mention of the gauss() and > >bgauss() functions which apparently written by Lay - these are to > >speed up matrix reduction but I have not noticed these functions in R. > > Have you encountered speed problems in R? Do you really need these > functions in R in addition to solve(), backsolve() etc. ? If you > just want to learn about how they work you could have a look at the > Matlab code for these functions (which I think you have access to). > You could even try rewriting them in R yourself.No, the speed is fine but I'm in early Linear Algebra and am working with basic matrices right now. I do have access to the author's functions and I may try re-writing those in R - that should be a good project and should help me better understand R as I'm a novice. Thank you, Elizabeth
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. Another way to look at this is that it's a question about the rank of the matrix. The rank of an mxn matrix is at most min(m,n). Unfortunately, help("rank") doesn't tell you about matrix rank, but about something else. Possibly the simplest method is to look at eign(x, only.values=TRUE) and see how many of the eigenvalues are non-zero.> eigen(x, only.values=TRUE)$values [1] 9.275635e+00+8.169494i 9.275635e+00-8.169494i -1.551270e+00+0.000000i [4] -1.603246e-14+0.000000i $vectors NULL We see that this matrix has a pair of conjugate eigenvalues 9.28 +/- 8.17 i and two real eigenvalues -1.55 -1.6e-14 The smallest eigenvalue is pretty close to 0 Try again, this time asking for the eigenvectors: vv <- eigen(x)$vectors Check what happens when you multiply the eigenvector corresponding to the smallest eigenvalue by the matrix: > print(v1 <- as.real(vv[,4])) [1] -0.4172502 0.2377877 -0.8479600 -0.2243281 > print(v2 <- as.vector(x %*% v1)) [1] 4.884981e-15 -2.664535e-15 8.437695e-15 -5.329071e-15 So x doesn't _precisely_ map that vector to 0, but it's close enough for government work. 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. Finally, look at help(qr). This is the most direct way of finding the rank of a matrix. > qr(x)$rank [1] 3 So here are three different functions all saying much the same thing about x: it is numerically close to a matrix which does NOT span the whole of R**4.