我正在运行以下命令:
>simplex(a = a, A2 = A2, b2 = b2, A3 = A3, b3 = b3)
我得到错误:
Error in pivot(tableau, prow, pcol) :
NAs are not allowed in subscripted assignments
这是我的R脚本:
library("boot") # For simplex
set.seed(100)
i <- 6
X <- rnorm(i, mean = 4, sd = 1)
e <- rnorm(i, mean = 0, sd = 1)
Y <- 5*X + e
sum <- 0
Y_a <- matrix(0,1,floor(i/2))
for(miss in 1:floor(i/2)){
sum <- sum + Y[miss*2]
Y_a[miss] <- Y[miss*2]
}
Y_p <- 5*rnorm(floor(i/2), mean = 4, sd = 1) + rnorm(floor(i/2), mean = 0, sd = 1)
a <- matrix(0,1,2*floor(i/2))
for(miss in 1:floor(i/2)){
a[miss] <- 1
}
A3 <- t(apply(a,1, rev))
A2 <- matrix(0,2*floor(i/2),2*floor(i/2))
for(miss in 1:floor(i/2)){
index <- 2*miss
index_ <- index - 1
A2[index_,miss] <- 1
A2[index_,miss+floor(i/2)] <- 1
A2[index,miss] <- 1
A2[index,miss+floor(i/2)] <- -1
}
b2 <- matrix(0,2*floor(i/2),1)
b2[(1:(2*floor(i/2)))%%2==1] <- Y_p
b2[(1:(2*floor(i/2)))%%2==0] <- -Y_p
simplex(a = a, A2 = A2, b2 = b2, A3 = A3, b3 = sum)
变量&#34; i&#34;大于5,否则我得到错误:
Error in simplex1(c(a, rep(0, m1 + 2 * m2 + m3)), cbind(rbind(A1, A2, :
number of items to replace is not a multiple of replacement length
In addition: Warning message:
In simplex1(c(a, rep(0, m1 + 2 * m2 + m3)), cbind(rbind(A1, A2, :
number of items to replace is not a multiple of replacement length
我无法理解这些错误是否意味着LP问题无法解决或意味着调用函数的方式存在错误。
提前致谢。
答案 0 :(得分:2)
论坛?simplex
的{{1}}文档指出
长度为m2的向量,给出&gt; =的右侧 限制。如果给出并忽略A2,则该参数是必需的 除此以外。 b2中的所有值都必须为非负值。请注意 约束x> = 0是自动包含的,因此不应该 在这里重复。
尝试确保b2
始终为非负面。