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

    %% Return the Objective Function Value  
% Calculate the solution and objective function value for a simple linear
% program.   

% Copyright 2015 The MathWorks, Inc.


%% 
% The inequality constraints are 
%
% $$ 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];

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

%% 
% Solve the problem and return the objective function value. 
[x,fval] = linprog(f,A,b)