%% Solutions for a set of different reduced order models
clc
clear all
close all

for Nsim =  1:20;
nfull = 16;
nred  = 1:16;
d01 = [];
d02 = [];
d0n = [];
    for i = 1:length(nred)
        [objval(i) ur(:,i) uf(:,i) xr xf Nsim d0] = ...
            yalmip_useCHS_trajectory_check(nfull,nred(i),Nsim)
        d01 = [d01; d0(1,1)];
        d02 = [d02; d0(2,1)];
        d0n = [d0n; d0];
        
        %run analyze worst case of different reduced order models
        [objvalsim(i),yfs,yrs] = analyze_dro(Nsim);
        diffobjvals(i) = objval(i) - objvalsim(i);
    end

objval_scaling = objval/Nsim;
objvalsim_scaling = objvalsim/Nsim;
d01 = double(d01);
d02 = double(d02);

% figure;
% plot(nred,objval_scaling)
% xlabel('states in reduced-order controller')
% ylabel('worst case error (outputs)')
% XLIM([1 16]);
% title(['Nsim' num2str(Nsim)])
% 
% figure;
% plot(nred,objvalsim_scaling)
% xlabel('states in reduced-order controller')
% ylabel('worst case error (outputs)')
% XLIM([1 16]);
% title(['Cloosed loop simulation Nsim' num2str(Nsim)])

%% save Nsimtest.mat nred objval objval_scaling
% save(['Nsim' num2str(Nsim) '.mat'])

% save analyze_check;
end
