Dear all, I have a system of simultaneous equations with 2 unknowns as follows: x*y + (1-x) = 0.05 x*(y - .5)^2 + (1-x)*0.6 = 0.56^2 Ofcourse I can do it manually however wondering whether there is any direct way in R available to get the solution of this system? Thanks and regards, [[alternative HTML version deleted]]
On Oct 9, 2011, at 14:02 , Bogaso Christofer wrote:> Dear all, I have a system of simultaneous equations with 2 unknowns as > follows: > > > > x*y + (1-x) = 0.05 > > x*(y - .5)^2 + (1-x)*0.6 = 0.56^2 > > > > Ofcourse I can do it manually however wondering whether there is any direct > way in R available to get the solution of this system?Not really (can't vouch for all 3000+ packages, though...) You can sometimes get away with converting to a minimization problem:> f <- function(xy,x=xy[1],y=xy[2])(x*y + (1-x) - 0.05)^2+(x*(y - .5)^2 + (1-x)*0.6 - 0.56^2)^2 > optim(par=c(0,0),f,method="BFGS")$par[1] 0.91674574 -0.03627402 $value [1] 5.351777e-13 $counts function gradient 39 13 $convergence [1] 0 $message NULL Notice that there is some risk of falling into a local minimum which has nothing to do with the solution. Always check that the minimum actually comes out as zero.> > > > Thanks and regards, > > > > > [[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.-- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd.mes at cbs.dk Priv: PDalgd at gmail.com
R is not the right tool for all things. This looks like a job for a computer algebra system. That said, R **does** have at least one interface to such a system. See the Ryacas package (check my capitalization, which may be wrong). HelpeRs may provide you with others. -- Bert On Sun, Oct 9, 2011 at 5:02 AM, Bogaso Christofer < bogaso.christofer@gmail.com> wrote:> Dear all, I have a system of simultaneous equations with 2 unknowns as > follows: > > > > x*y + (1-x) = 0.05 > > x*(y - .5)^2 + (1-x)*0.6 = 0.56^2 > > > > Ofcourse I can do it manually however wondering whether there is any direct > way in R available to get the solution of this system? > > > > Thanks and regards, > > > > > [[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. >[[alternative HTML version deleted]]
Bogaso wrote:> > Dear all, I have a system of simultaneous equations with 2 unknowns as > follows: > > x*y + (1-x) = 0.05 > > x*(y - .5)^2 + (1-x)*0.6 = 0.56^2 > > Ofcourse I can do it manually however wondering whether there is any > direct > way in R available to get the solution of this system? > >Look at the Task view Optimization. Two packages for solving systems of nonlinear equations are available: nleqslv and BB. Berend -- View this message in context: http://r.789695.n4.nabble.com/Finding-solution-tp3887148p3892804.html Sent from the R help mailing list archive at Nabble.com.