R - “缺少需要TRUE / FALSE的值”

时间:2015-05-12 11:32:01

标签: r

我正在尝试在R

中执行以下代码
library(nloptr)

m = 0.00060981
m2 = 0.000109362
m4 = 5.21538E-08
m6 = 4.25E-11
f=function(X){  
  Y = matrix(NA, ncol = 1, nrow = 4)
  mu = X[1]
  S2=X[2]
  S2u = X[3]
  lambda= X[4]
  Y[1] = (mu-(S2/2))-m
  Y[2] = (S2+(lambda*S2u))-m2
  Y[3] = ((3*(S2^2) + 6*(lambda^2)*(S2u^2)+3*(S2u^2)*(lambda) + 6*(lambda)*(S2u)*S2))-m4
  Y[4] = (15*(S2^3) +45*(S2^2)*S2u + 45*(lambda^2)*(S2u^2)*S2 +45*(lambda)*(S2u^2)*S2 +15*(lambda^3)*(S2u^3)+45*(lambda^2)*(S2u^3)+15*lambda*(S2u^3))-m6
  return(Y) 
}
g = function(X){
  return(norm(f(X),'f'))
}
initiale=c( 0.00197,0.022,0.0036,0.8999)
hin = function(X){
h=rep(NA,1)
h[2]>0
h[3]>0
h[1]<h[2]

h
}
ans=auglag(par=initiale,fn=g,hin=hin)

但是我得到了这个错误:

Error in if (sig > 1e+05) control.optim$reltol <- 1e-10 : 
  missing value where TRUE/FALSE needed

为什么我会收到此错误,以及如何修复代码?

1 个答案:

答案 0 :(得分:2)

我怀疑错误消息是func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { let cell = collectionView.dequeueReusableCellWithReuseIdentifier("CollectionViewCell", forIndexPath: indexPath) as! UICollectionViewCell return cell } func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { let cellId = indexPath.row % 5 let cell = tableView.dequeueReusableCellWithIdentifier("TableViewCell\(cellId)") as! UITableViewCell return cell } 函数

的结果
h

hin = function(X){ h=rep(NA,1) h[2]>0 h[3]>0 h[1]<h[2] h } 的值始终 h且永不改变。