% Example in Doc sec 2.2.1 to 2.2.5  modified as in Sec. 2.2.6.1
fprintf(' Example in Doc, sec 2.2.1 to 2.2.5 modified as in Sec. 2.2.6.1 ')
clear all
uqlab
rng(100)
PriorOpts.Name = 'Model parameters prior';
PriorOpts.Marginals(1).Name = 'b';
PriorOpts.Marginals(1).Type = 'Constant';
PriorOpts.Marginals(1).Parameters = 0.15; % (m)
PriorOpts.Marginals(2).Name = 'h';
PriorOpts.Marginals(2).Type = 'Constant';
PriorOpts.Marginals(2).Parameters = 0.3; % (m)
PriorOpts.Marginals(3).Name = 'L';
PriorOpts.Marginals(3).Type = 'Constant';
PriorOpts.Marginals(3).Parameters = 5; % (m)
PriorOpts.Marginals(4).Name = 'E';
PriorOpts.Marginals(4).Type = 'Lognormal';
PriorOpts.Marginals(4).Moments = [30000 4500] ; % (MPa)
PriorOpts.Marginals(5).Name = 'p';
PriorOpts.Marginals(5).Type = 'Constant';
PriorOpts.Marginals(5).Parameters = 0.012; % (kN/m)
myPriorDist = uq_createInput(PriorOpts);

ModelOpts.Name = 'Forward model';
ModelOpts.mFile = 'uq_SimplySupportedBeam';
myForwardModel = uq_createModel(ModelOpts);
V_mid = [12.84; 13.12; 12.13; 12.19; 12.67]/1000; % (m)
myData.Name = 'Beam mid-span deflection';
myData.y = V_mid;
%
DiscrepancyOpts.Type = 'Gaussian';
DiscrepancyOpts.Parameters = 1e-6;

BayesOpts.Discrepancy = DiscrepancyOpts;


BayesOpts.Type = 'Inversion';
BayesOpts.Data = myData;
% 
myBayesianAnalysis1a = uq_createAnalysis(BayesOpts);
uq_print(myBayesianAnalysis1a)
uq_display(myBayesianAnalysis1a)

fprintf(' myBayesianAnalysis1a.Results.PostProc.Percentiles.Values(1,1) = %g\n',...
     myBayesianAnalysis1a.Results.PostProc.Percentiles.Values(1,1))
 

fprintf(' myBayesianAnalysis1a.Results.PostProc.Percentiles.Values(1,2) = %g\n',...
     myBayesianAnalysis1a.Results.PostProc.Percentiles.Values(1,2))

 
fprintf(' myBayesianAnalysis1a.Results.PostProc.Percentiles.Values:\n')
     myBayesianAnalysis1a.Results.PostProc.Percentiles.Values