[R] detecting singular matrices
Murray Jorgensen
maj at stats.waikato.ac.nz
Thu Oct 9 22:34:43 CEST 2003
My colleague runs R 1.7.1 under Windows XP. He remarks:
>> A
> [,1] [,2] [,3]
> [1,] 1 2 3
> [2,] 4 5 6
> [3,] 7 8 9
>>
>> b
> [1] 1 2 3
>> solve(A,b)
> [1] -0.3333333 0.6666667 0.0000000
>> solve(A)
> [,1] [,2] [,3]
> [1,] -4.5036e+15 9.00720e+15 -4.5036e+15
> [2,] 9.0072e+15 -1.80144e+16 9.0072e+15
> [3,] -4.5036e+15 9.00720e+15 -4.5036e+15
>> eigen(A)
> $values
> [1] 1.611684e+01 -1.116844e+00 -1.303678e-15
>
> with a condition number of 1.236260e+16 I think I'd like it to tell me it's singular like it used to :) and I know it is singular
Under 1.6.0 also on XP I get
> solve(A,1:3)
Error in solve.default(A, 1:3) : singular matrix `a' in solve
> solve(A)
Error in solve.default(A) : singular matrix `a' in solve
> eigen(A)
$values
[1] 1.611684e+01 -1.116844e+00 -1.120190e-16
$vectors
[,1] [,2] [,3]
[1,] -0.2719964 -0.76169140 0.3734378
[2,] -0.6159646 -0.08408654 -0.7468756
[3,] -0.9599328 0.59351831 0.3734378
Which seems to be preferable output.
Murray
--
Dr Murray Jorgensen http://www.stats.waikato.ac.nz/Staff/maj.html
Department of Statistics, University of Waikato, Hamilton, New Zealand
Email: maj at waikato.ac.nz Fax 7 838 4155
Phone +64 7 838 4773 wk +64 7 849 6486 home Mobile 021 1395 862
More information about the R-help
mailing list