控制中的LMI/點選此處繼續/YALMIP
外觀
YALMIP
本書主要使用的工具。本章將提供一些使用Yalmip解決最佳化問題的示例。
YAMLIP的下載連結:[1]。點選頂部的“下載”並按照檔案中的說明操作。YALMIP可以在沒有額外軟體支援的情況下解決一些簡單問題。
對於最佳化問題,我們需要定義約束條件、目標函式、變數。
例如,為了找到一條直線來分離圖中的兩個資料,並使實現誤差最小。
% It's good practice to start by clearing YALMIPs internal database
% Every time you call sdpvar etc, an internal database grows larger
yalmip('clear')
% Define variables
x = sdpvar(10,1);
% Define constraints
Constraints = [sum(x) <= 10, x(1) == 0, 0.5 <= x(2) <= 1.5];
for i = 1 : 7
Constraints = [Constraints, x(i) + x(i+1) <= x(i+2) + x(i+3)];
end
% Define an objective
Objective = x'*x+norm(x,1);
% Set some options for YALMIP and solver
options = sdpsettings('verbose',1,'solver','quadprog','quadprog.maxiter',100);
% Solve the problem
sol = optimize(Constraints,Objective,options);
% Analyze error flags
if sol.problem == 0
% Extract and display value
solution = value(x)
else
display('Hmm, something went wrong!');
sol.info
yalmiperror(sol.problem)
end