I'm trying to execute the following code in 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)
But i'm getting this ERROR :
但是我得到了这个错误:
Error in if (sig > 1e+05) control.optim$reltol <- 1e-10 :
missing value where TRUE/FALSE needed
Why am I getting this error, and how to fix the code?
为什么我会收到此错误,以及如何修复代码?
1 个解决方案
#1
I suspect the error message is a result of the h
function
我怀疑错误信息是h函数的结果
hin = function(X){
h=rep(NA,1)
h[2]>0
h[3]>0
h[1]<h[2]
h
}
The value of h
is always NA
and never changes.
h的值始终为NA且永不改变。
#1
I suspect the error message is a result of the h
function
我怀疑错误信息是h函数的结果
hin = function(X){
h=rep(NA,1)
h[2]>0
h[3]>0
h[1]<h[2]
h
}
The value of h
is always NA
and never changes.
h的值始终为NA且永不改变。