[R] uniroot function question

Berend Hasselman bhh at xs4all.nl
Thu Dec 15 08:17:56 CET 2011


kchkchkch wrote
> 
> Heh.  Yes, 
> Berend Hasselman wrote
>> 
>> Shouldn't the line with uniroot be (why try as function?)
>> 
>> sol = uniroot(fcn, lower = p1, upper = 1)
>> 
>> Before the line with  for(i in 1:n) insert the following
>> 
>> fcn = function(p2) p1*f(p1) + (.20/5.66)*(exp(5.66*(p2 - p0)) -
>> exp(5.66*(p1 - p0))) + (1 - p2)*f(p2) - as.numeric(f.integral$value) 
>> curve(fcn, from=0, to=1)
>> 
>> And it should be obvious what the problem is.
>> 
>> Berend
>> 
>  I had been trying various solutions (so I'd been "trying" stating the
> functions a bunch of different ways)--hence the "try" in there.
> 
> but then I fixed it as you suggested--name the function correctly (insert
> eyeroll at myself here), and move the fcn = line to outside the for
> loop--and I still get the same error.
> 

Yes of course.
But you are misinterpreting what I wrote.

I said to insert two lines (NOT move) before the start of the for loop. The
second line to insert was curve() which will draw a plot of your function
for the first case. And you will see that the function fcn does not cross
the horizontal axis which it should do if it is to have a root for fcn(x)=0.
So you need to take a closer look at your function.

Berend

--
View this message in context: http://r.789695.n4.nabble.com/uniroot-function-question-tp4195737p4198877.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list