[Rd] uniroot arguments (PR#9140)

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Aug 11 15:39:58 CEST 2006


You seem not to understand that 'u' matches 'upper' by the standard 
argument-matching rules.

test<-function(x,u) (x-u)^3
debug(uniroot)
uniroot(test,c(0,1), u=.75)

Browse[1]> match.call()
uniroot(f = test, interval = c(0, 1), upper = 0.75)

Please learn to use R's debugging facilities (see `Writing R Extensions') 
to help you find your own errors.

Sending one empty report (9139) and one incorrect report on an obselete 
version of R was not kind: please study the section on 'BUGS' in the FAQ.

On Fri, 11 Aug 2006, trish at maigret.psy.ohio-state.edu wrote:

> 
> <<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
> 
> 
> 
> 
> --please do not edit the information below--
> 
> Version:
>  platform = i686-redhat-linux-gnu
>  arch = i686
>  os = linux-gnu
>  system = i686, linux-gnu
>  status = 
>  major = 2
>  minor = 2.1
>  year = 2005
>  month = 12
>  day = 20
>  svn rev = 36812
>  language = R
> 
> Locale:
> C
> 
> Search Path:
>  .GlobalEnv, package:methods, package:stats, package:graphics, package:grDevices, package:utils, package:datasets, Autoloads, package:base
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-devel mailing list