Hello, I have a system of five equations to solve with five 'unknows'(V, W, X, Y and Z) and constraints. The equations are: 0.007= 2VZ 0.03= W(Y+Z) 0.034= X(y+Z) 0.013 = (X+W)Y +(X-W)Z X = W+V Constraints: 0<V<W<X 0<Y<Z<1 Does anyone know a R-package to solve this system? Thanks, E-mail: sebastien.puechmaille at ucd.ie
Try brute force:> f <- function(x) {+ V <- x[1]; W <- x[2]; X <- x[3]; Y <- x[4]; Z <- x[5] + if (!(V < W && W < X && Y < Z)) return(Inf) + ((0.007 - 2*V*Z)^2 + + (0.03 - W*(Y+Z))^2 + + (0.034 - X*(Y+Z))^2 + + (X - W+V)^2 + + (0.013 - (X+W)*Y +(X-W)*Z))^2 + }> s <- 1:10/10 > g <- expand.grid(V = s, W = s, X = s, Y = s, Z = s) > idx <- which.min(apply(g, 1, f)) > idx[1] 10541> g[idx,]V W X Y Z 10541 0.1 0.5 0.6 0.1 0.2> as.vector(f(g[idx,]))[1] 3.8025e-08 On 8/6/07, sebastien puechmaille <sebastien.puechmaille at ucd.ie> wrote:> Hello, > > I have a system of five equations to solve with five 'unknows'(V, W, X, > Y and Z) and constraints. The equations are: > 0.007= 2VZ > 0.03= W(Y+Z) > 0.034= X(y+Z) > 0.013 = (X+W)Y +(X-W)Z > X = W+V > Constraints: > 0<V<W<X > 0<Y<Z<1 > > Does anyone know a R-package to solve this system? > > Thanks, > > E-mail: sebastien.puechmaille at ucd.ie > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >
Hi Sebastian, Your equations can be easily solved - no programming is required! Let's number you equations: (1) 0.007= 2VZ (2) 0.03= W(Y+Z) (3) 0.034= X(y+Z) (4) 0.013 = (X+W)Y +(X-W)Z (5) X = W+V Substitute (5) into (3) and then divide (2) by (3) to get (W+V)/W = 0.034/0.03 so that (6) V = (2/15)*W (7) X = V+W = (17/15)*W Substitute (7) into (3) and (4) to get: (3') (17/15)*(WY + WZ) = 0.034 (4') (32/15)WY + (2/15)WZ = 0.013 Solving (3') and (4') for two new unknowns WY and WZ yields (8) WY = 0.0045 (9) WZ = 0.0255 So that (10) Z = (17/3)*Y Substitute (10) into (1) to get 2*Y*(17/3)*Y = 0.07 So (since Y > 0), Y = sqrt(0.21/34) = 0.07859052>From (10), Z = (17/3)*Y = 0.4453463 >From (8), W = 0.0045/Y = 0.05725881 >From (6), V = (2/15)*W = 0.007634508Finally, X = V + W = 0.06489332 So there is a unique solution (which luckily satisfies your constraints!). Regards, Moshe. --- sebastien puechmaille <sebastien.puechmaille at ucd.ie> wrote:> Hello, > > I have a system of five equations to solve with > five 'unknows'(V, W, X, > Y and Z) and constraints. The equations are: > 0.007= 2VZ > 0.03= W(Y+Z) > 0.034= X(y+Z) > 0.013 = (X+W)Y +(X-W)Z > X = W+V > Constraints: > 0<V<W<X > 0<Y<Z<1 > > Does anyone know a R-package to solve this system? > > Thanks, > > E-mail: sebastien.puechmaille at ucd.ie > > ______________________________________________ > R-help at stat.math.ethz.ch 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. >