clc;
clear;
close all;

pL = 1000;

pmin=[0 0];
pmax=[900 800];

alpha=[0.1 0.3];
beta=[10 9];
gamma=[2000 1800];

Cost=@(p) sum(alpha.*p.^2+beta.*p+gamma);

p1=linspace(0,pL,10000);
p2=pL-p1;
z=zeros(size(p1));
for i=1:numel(z)
    z(i)=Cost([p1(i) p2(i)]);
end

A=[-1 -1];
b=-pL;

H=2*diag(alpha);
f=beta;

p=quadprog(H,f,A,b,[],[],pmin,pmax);
zmin=Cost(p');

plot3(p1,p2,z);
hold on;
plot3(p(1),p(2),zmin,'r*');
grid on;
xlabel('p_1');
ylabel('p_2');
zlabel('z');
