Contents
% % ivy_air.m: determine ticket sales for Ivy Air %
specify problem data
c = [300; 220; 100; 160; 130; 80; 360; 280; 140]; % objective A = [ 1 1 1 0 0 0 1 1 1; % inequality constraints 0 0 0 1 1 1 1 1 1]; b = [30; 30]; Aeq = []; % equality constraints beq = []; lb = zeros(9,1); % simple bound constraints ub = [ 4; 8; 22; 8; 13; 20; 3; 10; 18];
call the optimizer
[x,fval,exitflag] = linprog(-c,A,b,Aeq,beq,lb,ub);
Optimization terminated.
print solution.
Make sure you always print the exitflag to make sure that linprog is able to compute a solution (see help linprog for exitflag values)
fprintf( 'linprog terminated with exitflag = %d \n', exitflag ) fprintf( 'total revenue = %12.6f \n', -fval ) fprintf( ' The solution is x = \n' ); disp(reshape(x,3,3)) % The call the optimizer % [x,fval,exitflag,output,lambda] = linprog(c,A,b,Aeq,beq,lb,ub); % generates addition output. The meaning of lambda and some of % fileds in 'output' will be discussed later.
linprog terminated with exitflag = 1
total revenue = 9790.000000
The solution is x =
4.0000 8.0000 3.0000
8.0000 9.0000 10.0000
5.0000 0.0000 0.0000