% m24_lp.m - baby linear programming example % Define the problem: f = [1; 2]; % objective function A = [1 -1; -1 -1; 0 1]; b = [0 0 1]'; % constraints % Plot the problem: hold off [m,n] = size(A); xx = [-2 2]; for j = 1:m yy = (b(j)-A(j,1)*xx)/A(j,2); plot(xx,yy), hold on end axis(1.3*[-1 1 -1 1]), axis square, shg, pause % Solve the problem and plot the result: X = linprog(f,A,b); plot(X(1),X(2),'.-r','markersize',35)