R: (How) can the nlm function be used for optimization with multiple variables

前端 未结 1 974
走了就别回头了
走了就别回头了 2021-01-06 16:02

Can the nlm function be used for optimization with multiple variables? How would that work?

For instance: I want to find x and y so that f(x,y) is minimized. How wou

相关标签:
1条回答
  • 2021-01-06 16:36

    Make a function that receives a vector:

    f <- function(X) {
      x <- X[1]
      y <- X[2]
      (x-3.14)^2 + (y-6.28)^2
    }
    nlm(f,c(0.1,0.1))
    
    0 讨论(0)
提交回复
热议问题