www.gusucode.com > optim 案例源码 matlab代码程序 > optim/ExaminetheSolutionExample.m

    %% Obtain More Output to Examine the Solution  Process
% Obtain the exit flag and output structure to better understand the solution
% process and quality.   

%% 
% For this example, use these linear inequality constraints:
%
% $$ x(1) + x(2) \le 2$$
%
% $$x(1) + x(2)/4 \le 1$$
%
% $$x(1) - x(2) \le 2$$
%
% $$-x(1)/4 - x(2) \le 1$$
%
% $$-x(1) - x(2) \le -1$$
%
% $$-x(1) + x(2) \le 2.$$ 
A = [1 1
    1 1/4
    1 -1
    -1/4 -1
    -1 -1
    -1 1];

b = [2 1 2 1 -1 2];    

%% 
% Use the linear equality constraint $x(1) + x(2)/4 = 1/2$.
% 
Aeq = [1 1/4];
beq = 1/2;  

%% 
% Set these bounds:
%
% $$-1 \le x(1) \le 1.5$$
%
% $$-0.5 \le x(2) \le 1.25 .$$ 
lb = [-1,-0.5];
ub = [1.5,1.25];  

%% 
% Use the objective function $-x(1) - x(2)/3$.
f = [-1 -1/3];

%% 
% Set options to use the |'dual-simplex'| algorithm. 
options = optimoptions('linprog','Algorithm','dual-simplex');  

%% 
% Solve the linear program and request the function value, exit flag, and
% output structure. 
[x,fval,exitflag,output] = linprog(f,A,b,Aeq,beq,lb,ub,options)

%%  
% * |fval|, the objective function value, is larger than <docid:optim_ug.buus4rk-1_2>,
% because there are more constraints.  
% * |exitflag| = 1 indicates that the solution is reliable.  
% * |output.iterations| = 0 indicates that |linprog| found the solution
% during presolve, and did not have to iterate at all.