Try the pseudo inverse: m <- rbind(c(1, 1, 1), c(1, 0, 1), c(0, 1, 0)) b <- c(5, 2, 3)
library(MASS) ginv(m) %*% b On Thu, Dec 11, 2008 at 2:20 AM, Chris Line <[EMAIL PROTECTED]> wrote: > I have a set of linear equations and would like to find any feasible > solution. A simplex solution works in Case 1 below, but not in Case 2. I > would be grateful for any help. > > Case 1: Find any feasible solution for the set of linear equations: > a + b + c = 5 > a + b + 0c = 4 > 0a + b + c = 4 > > Solution - a feasible (and unique) solution is a=1, b=3, c=1. > > The following R code returns a feasible solution: > A3M = matrix(c(1,1,0,1,1,1,1,0,1),nrow=3) > b3M = matrix(c(5,4,4),ncol=1) > A1M = matrix(c(1,0,0,0,1,0,0,0,1),nrow=3) > b1M = matrix(c(10,10,10),ncol=1) > AM = matrix(c(1,1,1),nrow=1) > simplex(a = AM, A1 = A1M, b1 = b1M, A2 = NULL, b2 = NULL, A3 = A3M, b3 = b3M, > maxi = TRUE) > > > Case 2: Find any feasible solution for the set of linear equations > a + b + c = 5 > a + 0b + c = 2 > 0a + b + 0c = 3 > > Solution - one feasible solution of many is a=1, b=3, c=1. There are > infinite possible solutions in Case 2. > > However, the following R code fails to return any feasible solution: > A3M = matrix(c(1,1,0,1,0,1,1,1,0),nrow=3) > b3M = matrix(c(5,2,3),ncol=1) > A1M = matrix(c(1,0,0,0,1,0,0,0,1),nrow=3) > b1M = matrix(c(10,10,10),ncol=1) > AM = matrix(c(1,1,1),nrow=1) > simplex(a = AM, A1 = A1M, b1 = b1M, A2 = NULL, b2 = NULL, A3 = A3M, b3 = b3M, > maxi = TRUE) > > The code returns the error: > Error in A.out[, basic] <- iden(M) : subscript out of bounds > > Am I using the Simplex function incorrectly? There may be a better way to > approach the problem of finding a feasible solution. > > Cheers, > Chris. > > The contents of this email including any attachments are confidential. If you > have received this email in error, please advise the sender by return email > and delete this email. Any unauthorised use of the contents of the email is > prohibited and you must not disseminate, copy or distribute the message or > use the information contained in the email or its attachments in any way. > > The views or opinions expressed are the author's own and may not reflect the > views or opinions of Tibra. Tibra does not guarantee the integrity of any > emails or attached files. E-mails may be interfered with, may contain > computer viruses or other defects. Under no circumstances do we accept > liability for any loss or damage which may result from your receipt of this > message or any attachments. > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.