在R中传递fsolve多个参数

时间:2016-07-03 13:57:21

标签: r arguments

我在R中定义了一个函数,如下所示:

fff <- function(Q, Beta1, Beta2, delt, C, r, II, E, vars) {
   A1 = vars[1]
   ph = vars[2]
   B2 = vars[3]
   pl = vars[4]

   f = matrix(0, nrow=4,ncol=1)

   f[1] = -Q*A1*ph^Beta1 + B2*Q*ph^Beta2 + Q*ph/delt -Q*C/r - II
   f[2] = -Beta1*A1*Q*ph^(Beta1-1) + B2*Q*Beta2*ph^(Beta2-1) + Q/delt
   f[3] = -A1*Q*pl^Beta1 + B2*Q*pl^Beta2 + Q*pl/delt -Q*C/r + E
   f[4] = -Beta1*A1*Q*pl^(Beta1-1) + B2*Q*Beta2*pl^(Beta2-1) + Q/delt;

   return(f)
}

并希望使用fsolve解决这个问题,但无法弄清楚如何将各种变量和常量传递给fsolve。我尝试了以下多种变体:

vars0 = c(guessA1, guessPH,  guessB2,  guessPL)
# call fsolve with function, then initial guess, then constants ?
vars = fsolve( fff, vars0, Q, Beta1, Beta2, delt, C, r, II, E) 

但每次都会返回错误。任何帮助将不胜感激。

0 个答案:

没有答案