Search code examples
rmathematical-optimization

Multivariate Non-linear minimization in R


I need to minimize the objective function shown below, the variables in green boxes will be introduced to the formula and the variables in red boxes needed to be optimized and there will be a starting value for each. as of yet the optimization is not constrained. I put the formula here not to wait for a code but for the responses to have an idea about the function. What I've done so far: I searched the threads, I've tried the nlm command on a toy function:

fn =function(x,a) {sum(100*a+(2*x^2+5*x-7))}
nlm(fn , a<-c(10),x<- c(100), hessian=TRUE)

but I couldn't get the value for the optimum (a) and I doubt that I've some errors in the formula, I am using this formula as a starting point to tackle the formula below. What I am looking for is can any one point me to the suitable function in R that I will start from.

The Obj. Function


Solution

  • Generally calling R functions with assignment operators in the argument list will produce failure. This is one area where <- is NOT the same as =. I wouldn't have thought this would work :

     nlm(fn , a =c(10), x = c(100), hessian=TRUE)  # and it didn't
    

    The error message is informative, telling you there is a missing parameter p:

    > fn =function(x,p) {sum(100*p[1]+(2*x^2+5*x-7))}
    > nlm(fn , p=c(10),x = c(100), hessian=TRUE)
    $minimum
    [1] -4988507
    
    $estimate
    [1] -50090
    
    $gradient
    [1] 100
    
    $hessian
         [,1]
    [1,]    0
    
    $code
    [1] 5
    
    $iterations
    [1] 6