[R] Optimization problem with nonlinear constraint
Hans W Borchers
hwborchers at googlemail.com
Wed Jul 28 17:10:59 CEST 2010
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
>
More information about the R-help
mailing list