Re: [R] finding x values to meet a y

From: Martin Maechler <>
Date: Tue 08 Aug 2006 - 18:05:21 EST

>>>>> "AOlinto" == Antonio Olinto <> >>>>> on Mon, 7 Aug 2006 19:49:42 -0300 writes:

    AOlinto> Hi,
    AOlinto> I'd like to find which values of x will give me a y.

    AOlinto> In other words, in the example of a gaussian curve, I want to find the values of     AOlinto> x that will give me a density, let's say, of 0.02.

    AOlinto> curve(((1/(sqrt(2*pi)*10))*exp(-((x-50)^2)/(2*10^2))),xlim=c(0,100))

In other words, you are trying to *invert a function* numerically, i.e.,

find x such that f(x) = y0

Now, this is trivially the same as finding the "root" (or "zero") of the function f~(x) = f(x) - y0

==> Use *the* R root finding function :

    uniroot() [or polyroot() if f(.) is a polynomial]

Martin Maechler, ETH Zurich mailing list PLEASE do read the posting guide and provide commented, minimal, self-contained, reproducible code. Received on Tue Aug 08 21:17:14 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 08 Aug 2006 - 22:17:40 EST.

Mailing list information is available at Please read the posting guide before posting to the list.