[R] Simplex function in R
Gerard M. Keogh
GMKeogh at justice.ie
Thu Dec 11 14:26:29 CET 2008
re pseudo inverse
On the point of generalised inverses - GINV is usually taken to mean the
moore-penrose pseudo inverse - this is the least squares projection.
There are others - e.g. the Drazin inverse which amounts to diagonalisation
- of course this inverse may not be available in R.
Gerard
"Gabor
Grothendieck"
<ggrothendieck at gm To
ail.com> "Chris Line"
Sent by: <chris.line at tibra.com.au>
r-help-bounces at r- cc
project.org "r-help at r-project.org"
<r-help at r-project.org>
Subject
11/12/2008 12:14 Re: [R] Simplex function in R
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 <chris.line at tibra.com.au>
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 at 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 at 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.
**********************************************************************************
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer. It is the policy of the Department of Justice, Equality and Law Reform and the Agencies and Offices using its IT services to disallow the sending of offensive material.
Should you consider that the material contained in this message is offensive you should contact the sender immediately and also mailminder[at]justice.ie.
Is le haghaidh an duine nó an eintitis ar a bhfuil sí dírithe, agus le haghaidh an duine nó an eintitis sin amháin, a bheartaítear an fhaisnéis a tarchuireadh agus féadfaidh sé go bhfuil ábhar faoi rún agus/nó faoi phribhléid inti. Toirmisctear aon athbhreithniú, atarchur nó leathadh a dhéanamh ar an bhfaisnéis seo, aon úsáid eile a bhaint aisti nó aon ghníomh a dhéanamh ar a hiontaoibh, ag daoine nó ag eintitis seachas an faighteoir beartaithe. Má fuair tú é seo trí dhearmad, téigh i dteagmháil leis an seoltóir, le do thoil, agus scrios an t-ábhar as aon ríomhaire. Is é beartas na Roinne Dlí agus Cirt, Comhionannais agus Athchóirithe Dlí, agus na nOifígí agus na nGníomhaireachtaí a úsáideann seirbhísí TF na Roinne, seoladh ábhair cholúil a dhícheadú.
Más rud é go measann tú gur ábhar colúil atá san ábhar atá sa teachtaireacht seo is ceart duit dul i dteagmháil leis an seoltóir láithreach agus le mailminder[ag]justice.ie chomh maith.
***********************************************************************************
More information about the R-help
mailing list