求解线性规划中R-误差的应用
这是我的R代码:求解线性规划中R-误差的应用,r,optimization,linear-programming,R,Optimization,Linear Programming,这是我的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
#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).
我检查了我的代码多次,同样的问题仍然存在。用
bvet
的元素数检查Amat
的行数。Amat
中有12行,但bvet
和roi
中都有11个条目。这不可行。但在“Amat”中,我能使用不同数量的约束吗?谢谢Rhertel…它起作用了!!