Skip to content
Prev 360290 / 398503 Next

Solving sparse, singular systems of equations

a a
Thanks for the help. Sorry, I am not sure why it looks like that in the mailing list - it looks much more neat on my end (see attached file).
On Wednesday, April 20, 2016 2:01 PM, Berend Hasselman <bhh at xs4all.nl> wrote:

            
Your code is a mess. 

A singular square system of linear equations has an infinity of solutions if a solution exists at all.
How that works you can find here: https://en.wikipedia.org/wiki/System_of_linear_equations
in the section "Matrix solutions".

For your simple example you can do it like this:

library(MASS)
Ag <- ginv(A)??? # pseudoinverse

xb <- Ag %*% b # minimum norm solution

Aw <- diag(nrow=nrow(Ag)) - Ag %*% A? # see the Wikipedia page
w <- runif(3)
z <- xb + Aw %*% w
A %*% z - b

N <- Null(t(A))??? # null space of A;? see the help for Null in package MASS
A %*% N
A %*% (xb + 2 * N) - b

For sparse systems you will have to approach this differently; I have no experience with that.

Berend