1

In R I need to solve a system of linear equations (Ax=b), where b=0. By using solve() it just returns a zero vector for the answer, but I want the non-zero solutions of the system. Is there any way for it?

Mahmoud
  • 844
  • 1
  • 10
  • 17
  • 1
    Post your code and the example for A that you are using. – IRTFM Apr 22 '13 at 15:49
  • I don't really understand what are you looking for. Are you searching a function that solve a equation? Are you looking for the mathematical explanation? – ZanattMan Apr 22 '13 at 15:50
  • 1
    If `A` is invertible, zero vector would be the only answer. – liuminzhao Apr 22 '13 at 15:51
  • I'm searching for a R function that solve such a system. A is (B-lambda*I) in (B-lambda*I)x=0. In fact I want to find the eigenvectors of matrix B when I have it's eigenvalues. – Mahmoud Apr 22 '13 at 15:55
  • check out `eigen` function? `eigen(B)` – liuminzhao Apr 22 '13 at 15:57
  • Maybe this is the clear version of my question: How to find eigenvectors of a matrix when we have it's eigenvalues (in R) (not using `eigen()`) – Mahmoud Apr 22 '13 at 15:59
  • if you don't want to use `eigen` find the root of the determinant of B - lambda*I using R (`det` and `?uniroot`) – dickoa Apr 22 '13 at 18:16

1 Answers1

5

I think you are looking for the null space of a matrix A. Try :

library(MASS)
Null(t(A))

R > (A <- matrix(c(1,2,3,2,4,7), ncol = 3, byrow = T))
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    7
R > Null(t(A))
              [,1]
[1,] -8.944272e-01
[2,]  4.472136e-01
[3,]  7.771561e-16
R > (A <- matrix(c(1,2,3,2,4,6), ncol = 3, byrow = T))
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    4    6
R > Null(t(A))
           [,1]       [,2]
[1,] -0.5345225 -0.8017837
[2,]  0.7745419 -0.3381871
[3,] -0.3381871  0.4927193

Be careful. There are some rounding errors.

Also, denote r as the rank of matrix A, and q as the number of columns of A. If r = q, then zero vector is the only answer. If r > q, then there is no solution. If r < q, we can use the above Null function to get null space of A, but remember they are not unique, in terms of neither magnitude nor directions.

Reference : http://stat.ethz.ch/R-manual/R-patched/library/MASS/html/Null.html

liuminzhao
  • 2,385
  • 17
  • 28