[R] How to do a target value search analogous to Excel Solver

Joshua Wiley jwiley.psych at gmail.com
Mon Nov 7 13:45:49 CET 2011

```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
> 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/

```