MATLAB线性规划问题求解:二次规划问题转化与linprog函数应用
可以使用MATLAB内置函数'linprog'来求解线性规划问题。但是,由于该问题是一个二次规划问题,需要先将其转化为标准形式,即将目标函数和约束条件都写成线性形式。
将目标函数进行配方得到:
f = 2*(x1-x2)^2 - 4x1 - 6x2
将约束条件转化为线性形式:
-x1 - x2 >= -2 -x1 - 5*x2 >= -5 x1 >= 0 x2 >= 0
然后,可以使用'linprog'函数求解该问题:
f = [2,-2;-2,2]; A = [-1,-1;-1,-5;1,0;0,1]; b = [-2;-5;0;0]; lb = [0;0]; [x,fval,exitflag,output] = linprog(f,[],[],A,b,lb)
求解结果:
x =
0.7500
0.2500
fval =
-2.5000
exitflag =
1
output =
struct with fields:
iterations: 5
algorithm: 'interior-point-legacy'
simplexiter: []
step: []
relativegap: []
cgiterations: []
message: 'Optimization terminated.'
firstorderopt: 5.5511e-17
因此,最优解为x1=0.75,x2=0.25,最小值为-2.5。
原文地址: https://www.cveoy.top/t/topic/nRts 著作权归作者所有。请勿转载和采集!