[R] Optimization problem with nonlinear constraint
Ravi Varadhan
rvaradhan at jhmi.edu
Wed Jul 28 17:42:16 CEST 2010
Very nice, Hans! I didn't know of the existence of Lambert W function
(a.k.a Omega function) before. I didn't know that it occurs in the solution
of exponential decay with delay: dy/dy = a * y(t - 1). Apparently it is
more than 250 years old!
Thanks,
Ravi.
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Hans W Borchers
Sent: Wednesday, July 28, 2010 11:11 AM
To: r-help at stat.math.ethz.ch
Subject: Re: [R] Optimization problem with nonlinear constraint
Uli Kleinwechter <u.kleinwechter <at> uni-hohenheim.de> writes:
>
> Dear Ravi,
>
> As I've already written to you, the problem indeed is to find a solution
> to the transcendental equation y = x * T^(x-1), given y and T and the
> optimization problem below only a workaround.
I don't think optimization is the right approach for simply inverting
a simple function.
The inverse of the function x \to x * e^x is the Lambert W function.
So the solution in your case is:
W(log(T)*y*T) / log(T) # hope I transformed it correctly.
Now, how to compute Lambert's W ? Well, look into the 'gsl' package
and, alas, there is the function lambert_W0.
Your example:
----
y <- 3
T <- 123
library(gsl)
lambert_W0(log(T)*y*T)/log(T)
# [1] 1.191830
----
Regards, Hans Werner
>
> John C. Nash has been so kind to help me on here. In case anyone faces a
> similar problem in the future, the solution looks as follows:
>
> *****
>
> func1 <- function(y,x,T){
> out <- x*T^(x-1)-y
> return(out)
> }
>
> # Assign the known values to y and T:
> y <- 3
> T <- 123
>
> root <- uniroot(func1,c(-10,100),y=y,T=T)
> print(root)
>
> ********
>
> Somewhat simpler than I thought....
>
> Thanks again!
>
> Uli
>
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list