Displaying 20 results from an estimated 2000 matches similar to: "uniroot() problem"
2023 Feb 18
1
uniroot violates bounds?
I wrote first cut at unirootR for Martin M and he revised and put in
Rmpfr.
The following extends Ben's example, but adds the unirootR with trace
output.
c1 <- 4469.822
c2 <- 572.3413
f <- function(x) { c1/x - c2/(1-x) }; uniroot(f, c(1e-6, 1))
uniroot(f, c(1e-6, 1))
library(Rmpfr)
unirootR(f, c(1e-6, 1), extendInt="no", trace=1)
This gives more detail on the iterations,
2018 Jul 30
2
trace in uniroot() ?
In looking at rootfinding for the histoRicalg project (see gitlab.com/nashjc/histoRicalg),
I thought I would check how uniroot() solves some problems. The following short example
ff <- function(x){ exp(0.5*x) - 2 }
ff(2)
ff(1)
uniroot(ff, 0, 10)
uniroot(ff, c(0, 10), trace=1)
uniroot(ff, c(0, 10), trace=TRUE)
shows that the trace parameter, as described in the Rd file, does not seem to
be
2023 Feb 20
1
uniroot violates bounds?
Le 18/02/2023 ? 21:44, J C Nash a ?crit?:
> I wrote first cut at unirootR for Martin M and he revised and put in
> Rmpfr.
>
> The following extends Ben's example, but adds the unirootR with trace
> output.
>
> c1 <- 4469.822
> c2 <- 572.3413
> f <- function(x) { c1/x - c2/(1-x) }; uniroot(f, c(1e-6, 1))
> uniroot(f, c(1e-6, 1))
> library(Rmpfr)
>
2018 Aug 13
1
trace in uniroot() ?
Despite my years with R, I didn't know about trace(). Thanks.
However, my decades in the minimization and root finding game make me like having
a trace that gives some info on the operation, the argument and the current function value.
I've usually found glitches are a result of things like >= rather than > in tests etc., and
knowing what was done is the quickest way to get there.
2012 Apr 07
1
Uniroot error
Dear All
I am trying to find a uniroot of a function within another function (see
example) but I am getting an error message (f()values at end points not of
opposite sign). I was wondering if you would be able to advise how redefine
my function so that I can find the solution. In short my first function
calculates the intergrale which is function of "t" , I need to find the
uniroot of
2007 Jan 31
2
what is the purpose of an error message in uniroot?
Hi all,
This is probably a blindingly obvious question: Why does it matter in
the uniroot function whether the f() values at the end points that you
supply are of the same sign?
For example:
f <- function(x,y) {y-x^2+1}
#this gives a warning
uniroot(f,interval=c(-5,5),y=0)
Error in uniroot(f, interval=c(-5, 5), y = 0) : f() values at end
points not of opposite sign
#this doesn't give a
2007 Apr 25
4
How to solve difficult equations?
This below is not solvable with uniroot to find "a":
fn=function(a){
b=(0.7/a)-a
(1/(a+b+1))-0.0025
}
uniroot(fn,c(-500,500)) gives
"Error in uniroot(fn, c(-500, 500)) : f() values at end points not of
opposite sign"
I read R-help posts and someone wrote a function:
http://finzi.psych.upenn.edu/R/Rhelp02a/archive/92407.html
but it is not very precise. Is there any
2006 Oct 27
1
making uniroot a bit more robust?
Hi,
I wonder if it would make sense to make uniroot detect zeros at the
endpoints, eg
if f(lower)==0, return lower as the root, else
if f(upper)==0, return upper as the root, else
stop if f(upper)*f(lower) > 0 (currently it stops if >=), else
proceed to the algorithm proper.
Currently I am using a wrapper function to implement this, and I found
it useful. But I didn't want to send a
2008 Apr 12
1
R and Excel disagreement - Goal Seek versus uniroot
Dear friends - occurring in Windows R2.6.2
I am modeling physical chemistry in collaboration with a friend who has
preferred working in Excel. I used uniroot, and find a solution to a two
buffer problem in acid-base chemistry which I believe is physiologically
sensible. Using "goal seek" in Excel my friend found another plausible
root, quite close to zero, and a plot of the function
2011 Apr 03
1
How do I modify uniroot function to return .0001 if error ?
I am calling the uniroot function from inside another function using these
lines (last two lines of the function) :
d <- uniroot(k, c(.001, 250), tol=.05)
return(d$root)
The problem is that on occasion there's a problem with the values I'm
passing to uniroot. In those instances uniroot stops and sends a message
that it can't calculate the root because f.upper * f.lower is greater
2018 Aug 13
0
trace in uniroot() ?
I tend to avoid the the trace/verbose arguments for the various root
finders and optimizers and instead use the trace function or otherwise
modify the function handed to the operator. You can print or plot the
arguments or save them. E.g.,
> trace(ff, print=FALSE, quote(cat("x=", deparse(x), "\n", sep="")))
[1] "ff"
> ff0 <- uniroot(ff, c(0, 10))
2023 Feb 18
0
uniroot violates bounds?
c1 <- 4469.822
c2 <- 572.3413
f <- function(x) { c1/x - c2/(1-x) }; uniroot(f, c(1e-6, 1))
uniroot(f, c(1e-6, 1))
provides a root at -6.00e-05, which is outside of the specified
bounds. The default value of the "extendInt" argument to uniroot() is
"no", as far as I can see ...
$root
[1] -6.003516e-05
$f.root
[1] -74453981
$iter
[1] 1
$init.it
[1] NA
2008 Jul 31
3
Code to calculate internal rate of return
Hi all.
I am an R newbie and trying to grasp how the simple optimization routines in
R work. Specifically, I would like some guidance on how to set up a code to
calculate the internal rate of return on an investment project
(http://en.wikipedia.org/wiki/Internal_rate_of_return).
My main problem (I think) is that I want a generic code where N (number of
periods) can be easily changed and set
2008 Dec 02
3
How to solve following equation?
I need to solve a equation like this :
a = b/(1+x) + c/(1+x)^2 + d/(1+x)^3
where a,b,c,d are known constant. Is there any R-way to do that?
Thanks in advance
--
View this message in context: http://www.nabble.com/How-to-solve-following-equation--tp20785063p20785063.html
Sent from the R help mailing list archive at Nabble.com.
2012 Nov 01
1
What does uniroot return when an error occurs
Hi,
I'm using the uniroot function, and would like to detect an error which
occurs, for instance, when the values at endpoints are not of opposite
signs. For example:
uniroot( function(x) x^2+1, lower=1, upper=2 ).
I want to say something like:
if "error in uniroot(...)" return NA else return uniroot$root
Thanks a lot!
Asaf
--
View this message in context:
2020 Oct 06
0
Solving a simple linear equation using uniroot give error object 'x' not found
On 06/10/2020 11:00 a.m., Sorkin, John wrote:
> Colleagues,
> I am trying to learn to use uniroot to solve a simple linear equation. I define the function, prove the function and a call to the function works. When I try to use uniroot to solve the equation I get an error message,
> Error in yfu n(x,10,20) : object 'x' not found.
>
> I hope someone can tell we how I can fix
2011 Apr 02
1
uniroot speed and vectorization?
curiosity---given that vector operations are so much faster than
scalar operations, would it make sense to make uniroot vectorized? if
I read the uniroot docs correctly, uniroot() calls an external C
routine which seems to be a scalar function. that must be slow. I am
thinking a vectorized version would be useful for an example such as
of <- function(x,a) ( log(x)+x+a )
uniroot( of, c(
2013 May 30
2
RFC: a "safe" uniroot() function for future R
With main R releases only happening yearly in spring, now is
good time to consider *and* discuss new features for what we
often call "R-devel" and more officially is
R Under development (unstable) (.....) -- "Unsuffered Consequences"
Here is one such example I hereby expose to public scrutiny:
A few minutes ago, I've committed the following to R-devel
(the
2012 Jun 22
4
Uniroot error message with in intergration
Dear all
I am trying to calculate the value of n using uniroot. Here is the message
I am having:
<<<
Error in uniroot(integ, lower = 0, upper = 1000, n) :
'interval' must be a vector of length 2 >>>
Please would you be able to give me an indication on why I am having this
error message.
Many thanks
EXAMPLE BELOW:
## t = statistics test from t -distribution
2011 Dec 14
1
uniroot function question
I have one equation, two unknowns, so I am trying to build the solution set
by running through possible values for one unknown, and then using uniroot
to solve for the accompanying second solution, then graphing the two
vectors.
p0 = .36
f = function(x) 0.29 * exp(5.66*(x - p0))
f.integral = integrate(f, p0, 1)
p1 = p0 + .01
i = 1
n = (1 - p0)/.01
p1.vector = rep(0,n)
p2.vector = rep(0,n)
for (i