[R] R optimization and curve()?
Ray Brownrigg
Ray.Brownrigg at ecs.vuw.ac.nz
Tue Oct 12 23:48:07 CEST 2010
On Wed, 13 Oct 2010, jcress410 wrote:
> u <- function(x) {
> x1 <- x[1]
> x2 <- x[2]
> (x1^alpha)*(x2^(1-alpha))
> }
> utility <- function(x) x[1]^(alpha)*x[2]^(1-alpha)
> p <- c(2,1)
> i <- -100
> alpha <- .3
> umax <- function(p,i,u) {
> res <- constrOptim(c(.5,.5), u, grad=NULL, ui=-p, ci=i, mu = 1e-04,
> control=list(fnscale=-1))
> return(res)
> }
> curve(umax, c(c(2,1),c(2,1)), c(10,100))
I don't see any question here.
However you must RTFM.
1) The returned value of umax() is a list. How do you expect curve() to plot a list?
2) curve() requires that the function umax() must be vectorisable wrt its first parameter,
i.e. you pass it a numeric vector and it returns a numeric vector of the same length.
3) you have to realise that curve() will only graph a 1-dimensional function
HTH,
Ray
More information about the R-help
mailing list