[R] Solving sparse, singular systems of equations
A A
awawaed at yahoo.com
Wed Apr 20 13:22:34 CEST 2016
I have a situation in R where I would like to find any x (if one exists) that solves the linear system of equations Ax = b, where A is square, sparse, and singular, and b is a vector. Here is some code that mimics my issue with a relatively simple A and b, along with three other methods of solving this system that I found online, two of which give me an error and one of which succeeds on the simplified problem, but fails on my data set(attached). Is there a solver in R that I can use in order to get x without any errors given the structure of A? Thanks for your time.
#CODE STARTS HEREA = as(matrix(c(1.5,-1.5,0,-1.5,2.5,-1,0,-1,1),nrow=3,ncol=3),"sparseMatrix")b = matrix(c(-30,40,-10),nrow=3,ncol=1)
#solve for x, Error in LU.dgC(a) : cs_lu(A) failed: near-singular A (or out of memory)solve(A,b,sparse=TRUE,tol=.Machine$double.eps)
#one x that happens to solve Ax = bx = matrix(c(-10,10,0),nrow=3,ncol=1)A %*% x
#Error in lsfit(A, b) : only 3 cases, but 4 variableslsfit(A,b)#solves the system, but fails belowsolve(qr(A, LAPACK=TRUE),b)#Error in qr.solve(A, b) : singular matrix 'a' in solveqr.solve(A,b)
#matrices used in my actual problem (see attached files)A = readMM("A.txt")b = readMM("b.txt")
#Error in as(x, "matrix")[i, , drop = drop] : subscript out of boundssolve(qr(A, LAPACK=TRUE),b)
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: A.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20160420/d5cf4593/attachment-0002.txt>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: b.txt
URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20160420/d5cf4593/attachment-0003.txt>
More information about the R-help
mailing list