clc;clear;close
%definice omezeni a ucelovych fci pro scenare

c1=[1;2];
lb1=[0;1];
ub1=[2;3];

c2=[2;1];
lb2=[1;0];
ub2=[3;2];

p1=1/2;p2=1/2; %vahy scenaru

%Algoritmus


maxj=100; %max pocet iteraci
epsilon=0.001;

%inicializace
w1=w1_old=[0;0];
w2=w2_old=[0;0];
xh=xh_old=[0;0];
xhcell=cell(maxj,1);
x1cell=cell(maxj,1);
x2cell=cell(maxj,1);
delta=1000;
rho=1.2;
j=0;
%hl. cast

while (delta>epsilon)
j++;

%resime ulohu v jednotlivych scenarich
x0=[0;0];
[x1, obj, info, iter, nf, lambda] = sqp (x0,@(x) fobj1(x,c1,w1_old,rho,xh_old),[],[],lb1,ub1);
x0=[0;0];
[x2, obj, info, iter, nf, lambda] = sqp (x0,@(x) fobj2(x,c2,w2_old,rho,xh_old),[],[],lb2,ub2);

%spocitame x se striskou
xh=p1*x1+p2*x2;
xhcell{j}=xh;
x1cell{j}=x1;
x2cell{j}=x2;
%overime, zda uz muzeme algoritmus pro danou toleranci ukoncit
delta=sqrt(norm(xh_old-xh)^2+p1*norm(x1-xh)^2+p2*norm(x2-xh)^2);
w1=w1_old+rho*(x1-xh);
w2=w2_old+rho*(x2-xh);

%preznacime promenne pro dalsi iteraci cyklu
w1_old=w1;
w2_old=w2;
xh_old=xh;
end

figure(1);
%osy
plot([0,0],[0,6],'color','black');hold on;
plot([0,6],[0,0],'color','black');hold on;

%C_s
plot([1,3,3,1,1],[0,0,2,2,0],'color','green');hold on;
plot([0,2,2,0,0],[1,1,3,3,1],'color','blue');hold on;

%primky v 0
plot([2,-2],[-4,4],'color','magenta');hold on;
plot([4,-4],[-2,2],'color','magenta');hold on;
axis([-2,5,-2,5],'equal');
%body
plot(xh(1),xh(2),'o','color','red','markersize',10);
plot([x1cell{1}(1),x2cell{1}(1)], [x1cell{1}(2),x2cell{1}(2)],'o','color','red','markersize',5);hold on;
plot([x1cell{2}(1),x2cell{2}(1)], [x1cell{2}(2),x2cell{2}(2)],'o','color','red','markersize',5);hold on;
plot([x1cell{3}(1),x2cell{3}(1)], [x1cell{3}(2),x2cell{3}(2)],'o','color','red','markersize',5);hold on;
h1 = quiver (0,0, -2,-1,'color',[143/256,143/256,143/256]);hold on;
h2 = quiver (0,0, -1,-2,'color',[143/256,143/256,143/256]);

print figure1.jpg




