[Rcpp-devel] uniroot problem
Jeff Newmiller
jdnewmil at dcn.davis.ca.us
Sun Dec 29 06:20:21 CET 2019
I get 230 for all three runs, which looks right to me. I don't understand your concern .. maybe you need to plot Fn yourself.
On December 28, 2019 7:48:27 PM PST, Shaami <nzshaam at gmail.com> wrote:
>Any suggestion plz. What could be missing that I donot get function
>root to
>be zero at some points?
>
>On Tue, 24 Dec 2019, 1:45 PM Shaami, <nzshaam at gmail.com> wrote:
>
>> Dear Friends
>>
>> Could you please help with the following example? I do not get
>function
>> value at zero using uniroot() in R. Could you suggest something? I
>want
>> function value zero at any point like 2.4, 2.5, 2.6, 4.5, 5.9 etc.
>>
>> Thank You
>>
>> x = c(-100, -20, 100, 230, 500, 920, 1000)
>> a = c(1000, 12, 300, 0, 100, 300, 750)
>> Fn = function(t, x, a){
>> sum = 0
>> for(i in 1:length(x)){
>> sum = sum + punif(t, min=x[i]-a[i], max=x[i]+a[i])
>> }
>> return(sum)
>> }uniroot(function(t){Fn(t, x, a) - 2.4}, interval=c(min(x-a),
>max(x+a)))
>> uniroot(function(t){Fn(t, x, a) - 2.5}, interval=c(min(x-a),
>max(x+a)))
>> uniroot(function(t){Fn(t, x, a) - 2.8}, interval=c(min(x-a),
>max(x+a)))
>>
>>
--
Sent from my phone. Please excuse my brevity.
More information about the Rcpp-devel
mailing list