%% Global parameters : 
global c10 c20 V0 c1f c2f R1 R2 b0 b1 b2
%% Parameters : 
c10 = 3.3;  c1f = 9.04;
c20 = 5.5;  c2f = 0.64;
V0  = 100;  
b0  = 63.42; b1  = -12.439; b2  = -7.836;
R1 = 1; R2 = 0;

diary SOLP_results_mintf.txt
%% Optimization : 
options = optimset('LargeScale','off','Display','iter');
options = optimset(options,'GradObj','on','GradConstr','on','DerivativeCheck','on');
options = optimset(options,'Algorithm','sqp'); 

optimparam.optvar = 3;
optimparam.objtype = [];
optimparam.ncolx = 5; 
optimparam.ncolu = 2; 
optimparam.li = 2*ones(3,1);
optimparam.tf = [];
optimparam.ui = 0.5*ones(1,3); 
optimparam.par = []; 
optimparam.bdu = [0 5]; 
optimparam.bdx = [0 25; 0 7; 0 100; 0 100]; 
optimparam.bdp = [];
optimparam.objfun = @objfun; 
optimparam.confun = @confun; 
optimparam.process = @process;
optimparam.options = options;

[optimout,optimparam]=dynopt(optimparam);
[tplot,uplot,xplot] = profiles(optimout,optimparam,50);
save optimresults optimout optimparam
save optimprofiles tplot uplot xplot 

tf = tplot(end)
Vw = xplot(end,4)

diary off

figure
plot(xplot(:,1),xplot(:,2),c10,c20,'go',c1f,c2f,'rx')
xlabel('c1')
ylabel('c2')
axis([0 25 0 6])
set(gcf, 'PaperUnits', 'centimeters')
set(gcf, 'PaperPosition', [3 10 11 8.25])
print -depsc 'SOLP_c1c2_mintf.eps'

figure
plot(tplot,uplot)
xlabel('t')
ylabel('alpha')
v = axis; v(3)=-0.1; axis(v);
set(gcf, 'PaperUnits', 'centimeters')
set(gcf, 'PaperPosition', [3 10 11 8.25])
print -depsc 'SOLP_alphat_mintf.eps'

figure
plot(tplot,xplot(:,4))
xlabel('t')
ylabel('vW')
axis([0 5 -3 50])
set(gcf, 'PaperUnits', 'centimeters')
set(gcf, 'PaperPosition', [3 10 11 8.25])
print -depsc 'SOLP_Vwt_mintf.eps'

figure
plot(tplot,xplot(:,1),tplot,xplot(:,2));
xlabel('t')
ylabel('c1c2')
legend('c_1','c_2','Location','NorthWest')
axis([0 5 0 25])
set(gcf, 'PaperUnits', 'centimeters')
set(gcf, 'PaperPosition', [3 10 11 8.25])
print -depsc 'SOLP_c1c2t_mintf.eps'
