%This is the main MATLAB file for the 3rd example reported in IECR paper
%Author: Maryam Ghadrdan
%Date: July 2013

% In this function, the model is purturbed around the nominal point to get 
% the sensitivity matrix. This is saved in Fconv_all.txt
CalcF2_compSet('\twoproductcolumn_pref.HSC')

%This function 
transF_2prodConv_Estim_xAsU('\twoproductcolumn_pref.HSC','allmat_2est_Ol_xAsU_pref_point1Noise_11_6_2013','C3 comp in top','C2 comp in bot')

%find the optimal H matrix for combining measurements
load allmat_2est_Ol_xAsU_pref_point1Noise.mat
Mary_combination_2prod('allmat_2est_Ol_xAsU_pref_point1Noise.mat',Gy,F, ...
    'comb_2prod_Hopt_fewMeas_point1Noise.mat',4)

%transfer the H data to Hysys file
transHoptToHYSYS('comb_2prod_Hopt_fewMeas_point1Noise.mat', ...
                 '\TWOPRODUCTCOLUMN_DYN2_PREF_2STABIL_POINT1NOISE.hsc', 4)

% first save the HSC file above as trial and then run the code below to get
% the estimated top and bottom compositions for different disturbances
display('Validation')
step_f = .1;
step_za = .04;
step_zb = .02;
step_zc = .02;
step_zd = .04;
vrng = 0.01;
Prngf = .1;
Prng = .04;

Validation_2prod('\TWOPRODUCTCOLUMN_DYN2_PREF_2STABIL_POINT1NOISE.hsc', ...
    step_f, step_za,step_zb,step_zc,step_zd,vrng,Prngf,Prng,2)
