[R] Finding solution
peter dalgaard
pdalgd at gmail.com
Sun Oct 9 14:28:41 CEST 2011
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
More information about the R-help
mailing list