Hi! I want to use R to calculate the variable x which is in a complex equation in below: 2 ?[exp(-x/2)*(x^k)/(2^k*k!)]=0.05 k=0 how to solve this equation to get the exact x in R? Thank you very much. -- View this message in context: http://r.789695.n4.nabble.com/How-to-solve-this-complex-equation-tp4702997.html Sent from the R help mailing list archive at Nabble.com.
On 10/02/15 14:04, Ssuhanchen wrote:> Hi! > > I want to use R to calculate the variable x which is in a complex equation > in below: > > 2 > ?[exp(-x/2)*(x^k)/(2^k*k!)]=0.05 > k=0 > > how to solve this equation to get the exact x in R?Is this homework? Sure looks like it. Talk to your prof. Or do a bit of work on learning how to use R --- which is presumably the point of the exercise. cheers, Rolf Turner -- Rolf Turner Technical Editor ANZJS Department of Statistics University of Auckland Phone: +64-9-373-7599 ext. 88276 Home phone: +64-9-480-4619
no, it is not my homework. I would like to know if there is relevant function to solve this equation in R? Could you please give me a hint or suggestion please. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/How-to-solve-this-complex-equation-tp4702997p4703006.html Sent from the R help mailing list archive at Nabble.com.
> -----Original Message----- > I want to use R to calculate the variable x which is in a complex equation in > below: > > 2 > ?[exp(-x/2)*(x^k)/(2^k*k!)]=0.05 > k=0 > > how to solve this equation to get the exact x in R?For a _numerical_ solution, if f(x) is your function, use uniroot to find a root of (f(x) - 0.05) That will normally need you to define a new function g(x) = f(x)-0.05 and apply uniroot to g(x) S Ellison ******************************************************************* This email and any attachments are confidential. Any use, copying or disclosure other than by the intended recipient is unauthorised. If you have received this message in error, please notify the sender immediately via +44(0)20 8943 7000 or notify postmaster at lgcgroup.com and delete this message and any copies from your computer and network. LGC Limited. Registered in England 2991879. Registered office: Queens Road, Teddington, Middlesex, TW11 0LY, UK
Got it! Thanks! I find a useful function, uniroot.all, in package "rootSolve". I hope it will also be helpful to everybody. -- View this message in context: http://r.789695.n4.nabble.com/How-to-solve-this-complex-equation-tp4702997p4703015.html Sent from the R help mailing list archive at Nabble.com.
?uniroot -----Original Message----- From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Ssuhanchen Sent: Tuesday, February 10, 2015 3:32 AM To: r-help at r-project.org Subject: Re: [R] How to solve this complex equation no, it is not my homework. I would like to know if there is relevant function to solve this equation in R? Could you please give me a hint or suggestion please. Thanks! -- View this message in context: http://r.789695.n4.nabble.com/How-to-solve-this-complex-equation-tp4702997p4703006.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.
The functional form given in the post written by Ssuhanchen captures my eyes. It is the cumulative distribution function of Poisson when the number of counts is less than or equal to 2 with unknown parameter mu=x/2. Since it is a nonlinear function, there may be multiple solutions but the solution should be greater than 0 (if I am in the right track). I am assuming this functional form is originated from the Poisson. Under this assumption, one solution is found as below: > rt <- uniroot(function(x) ppois(2, lambda=x)-0.05, interval=c(0.5,1), extendInt="yes") Warning messages: 1: In ppois(2, lambda = x) : NaNs produced 2: In ppois(2, lambda = x) : NaNs produced 3: In ppois(2, lambda = x) : NaNs produced > ppois(2, lambda=rt$root) [1] 0.0500001 > rt$root [1] 6.295791 Thus, the solution x would be rt$root*2 (Note that I did not try to find other solutions). I hope this helps. Chel Hee Lee On 2/10/2015 2:29 AM, Rolf Turner wrote:> On 10/02/15 14:04, Ssuhanchen wrote: >> Hi! >> >> I want to use R to calculate the variable x which is in a complex >> equation >> in below: >> >> 2 >> ?[exp(-x/2)*(x^k)/(2^k*k!)]=0.05 >> k=0 >> >> how to solve this equation to get the exact x in R? > > Is this homework? Sure looks like it. Talk to your prof. Or do a > bit of work on learning how to use R --- which is presumably the point > of the exercise. > > cheers, > > Rolf Turner >