这是我的R代码:
#install.packages("linprog")
library(linprog)
roi=c(0.04,0.02,0.03,0.11,0.03,0.2,0.17,0.24,0.03,0.04,0.04)
bvet=c(100000,0,0,0,0,0,0,0,0,0,0)
Amat=rbind(
c(1,1,1,1,1,1,1,1,1,1,1),
c(0.96,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04),
c(-0.02,0.98,-0.02,-0.02,-0.02,-0.02,-0.02,-0.02,-0.02,-0.02,-0.02),
c(-0.03,-0.03,0.97,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03),
c(-0.11,-0.11,-0.11,0.89,-0.11,-0.11,-0.11,-0.11,-0.11,-0.11,-0.11),
c(-0.03,-0.03,-0.03,-0.03,0.97,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03),
c(-0.2,-0.2,-0.2,-0.2,-0.2,0.8,-0.2,-0.2,-0.2,-0.2,-0.2),
c(-0.17,-0.17,-0.17,-0.17,-0.17,-0.17,0.83,-0.17,-0.17,-0.17,-0.17),
c(-0.24,-0.24,-0.24,-0.24,-0.24,-0.24,-0.24,0.83,-0.24,-0.24,-0.24),
c(-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,-0.03,0.97,-0.03,-0.03,-0.03),
c(-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,0.96,-0.04),
c(-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,-0.04,0.96)
)
LP=solveLP(roi,bvet,Amat,TRUE)
我收到此错误:
Error in solveLP(roi, bvet, Amat, TRUE) :
Matrix A must have as many rows as constraints (=elements of vector b) and as many columns as variables (=elements of vector c).
我多次检查了我的代码,同样的问题仍然存在。