[Rd] uniroot arguments (PR#9140)
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Fri Aug 11 15:38:24 CEST 2006
trish at maigret.psy.ohio-state.edu writes:
> <<insert bug report here>>
>
> When invoking "uniroot" with any argument named "u", uniroot exits
> with error: "Error in f(lower, ...) : argument "u" is missing, with no
> default". This error occurs whether or not "u" determines the root.
>
> Giving "u" a default value results in garbage from uniroot.
>
> ## Define a function with a root:
> > test<-function(x,a) (x-a)^3
>
> ## Find the root:
> > uniroot(test,c(0,1),a=.75)
> $root
> [1] 0.7500141
>
> $f.root
> [1] 2.793453e-15
>
> $iter
> [1] 22
>
> $estim.prec
> [1] 6.103516e-05
>
> ## All is well. Change argument "a" to "u":
> > test<-function(x,u) (x-u)^3
> ## Plot it:
> > plot(seq(0,1,by=.1),test(seq(0,1,by=.1),u=.75),type='l')
>
> ## All is well. Find the root:
> > uniroot(test,c(0,1),u=.75)
> Error in f(lower, ...) : argument "u" is missing, with no default
>
> ## Define a new function with the same root:
> > test<-function(x,a,u) (x-a)^3 /u
> ## Plot it:
> > plot(seq(0,1,by=.1),test(seq(0,1,by=.1),a=.75,u=.2),type='l')
>
> ## All is well. Find the root:
> > uniroot(test,c(0,1),a=.75,u=.2)
> Error in f(lower, ...) : argument "u" is missing, with no default
>
> ## Give u a default value:
> > test<-function(x,a,u=.2) (x-a)^3 /u
> ## Find the root:
> > uniroot(test,c(0,1),a=.75,u=.2)
> Error in uniroot(test, c(0, 1), a = 0.75, u = 0.2) :
> f() values at end points not of opposite sign
>
> ## Oh, really?
> > test(0,.75,.2)
> [1] -2.109375
> > test(1,.75,.2)
> [1] 0.078125
This is partial matching playing tricks on you. Annoying, but not a bug:
> test<-function(x,a,u=.2) (x-a)^3 /u
> uniroot(test,c(0,1),a=.75,u=.2,upper=1)
$root
[1] 0.7500141
$f.root
[1] 1.396726e-14
$iter
[1] 21
$estim.prec
[1] 6.103516e-05
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-devel
mailing list