2015-06-29 46 views
1

使用單面我運行下面的命令:獲得「NAS還沒有下標賦值允許」,而R中

>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) 

我得到上述錯誤時,變量 「i」 大於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

'simplex'的'b2'參數的文檔說:'b2中的所有值必須是非負數.'但是您有3個負值。我不確定這是不是罪魁禍首,但這是一個開始。 –

+0

感謝羅馬人,它似乎是罪魁禍首:)。在確保b2爲正數並將負數b2給出方程得到b1後,我得到了答案。 – vivkul

+0

羅馬可以請你把它作爲答案。 – vivkul

回答

2

?simplex的說法b2文檔指出

A vector of length m2 giving the right hand side of the >= constraints. This argument is required if A2 is given and ignored otherwise. All values in b2 must be non-negative. Note that the constraints x >= 0 are included automatically and so should not be repeated here.

嘗試確保b2總是非負。

相關問題