Skip to content
Prev 300625 / 398506 Next

finding the values to minimize sum of functions

Hi Linh,

Here is an approach:

f <- function(v) {
  v <- v/sum(v)
  (v[1]^2) + (2 * v[2]^2) + (3*v[3]^2)
}

(res <- optim(c(.6, .3, .1), f))

res$par/sum(res$par)

This is a downright lazy way to implement the constraint.  The main
idea is to combine all three functions into one function that takes a
vector of parameters (v, in this case).

Cheers,

Josh
On Thu, Jul 19, 2012 at 10:24 AM, Linh Tran <Tranlm at berkeley.edu> wrote: