jolo999
2011-Nov-07 11:38 UTC
[R] How to do a target value search analogous to Excel Solver
Hi all, i'm trying to find a solver possibility analogous to the Excel Solver in R. Since i just started with R, I have only little knowledge. Can someone help me by solving the problem? I have the following 'starting position': z = rnorm(1,0,1) y <- function(x,z){2*x - 1 + z} I am looking for a certain "x" in such a way that the result of the function 'y' equals 5.5 Thanks a lot! -- View this message in context: http://r.789695.n4.nabble.com/How-to-do-a-target-value-search-analogous-to-Excel-Solver-tp3998347p3998347.html Sent from the R help mailing list archive at Nabble.com. [[alternative HTML version deleted]]
Joshua Wiley
2011-Nov-07 12:45 UTC
[R] How to do a target value search analogous to Excel Solver
Hi, Try this: set.seed(1) z <- rnorm(1,0,1) y <- function(x, z, xc){2*x - 1 + z - xc} ## uniroot finds a 0 value, so offset function by 5.5 uniroot(y, z = z, xc = 5.5, interval = c(-100, 100)) ## use the root and now no offset y(3.563227, z, 0) see ?uniroot for help Cheers, Josh On Mon, Nov 7, 2011 at 3:38 AM, jolo999 <jonas.lorson at ebs.de> wrote:> Hi all, > > i'm trying to find a solver possibility analogous to the Excel Solver in R. > Since i just started with R, I have only little knowledge. Can someone help > me by solving the problem? > > I have the following 'starting position': > > z = rnorm(1,0,1) > y <- function(x,z){2*x - 1 + z} > > I am looking for a certain "x" in such a way that the result of the function > 'y' equals 5.5 > > Thanks a lot! > > -- > View this message in context: http://r.789695.n4.nabble.com/How-to-do-a-target-value-search-analogous-to-Excel-Solver-tp3998347p3998347.html > Sent from the R help mailing list archive at Nabble.com. > ? ? ? ?[[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. >-- Joshua Wiley Ph.D. Student, Health Psychology Programmer Analyst II, ATS Statistical Consulting Group University of California, Los Angeles https://joshuawiley.com/
jolo999
2011-Nov-07 14:07 UTC
[R] How to do a target value search analogous to Excel Solver
Works fine. Thanks for the quick reply!! -- View this message in context: http://r.789695.n4.nabble.com/How-to-do-a-target-value-search-analogous-to-Excel-Solver-tp3998347p3998729.html Sent from the R help mailing list archive at Nabble.com.