clear all
clc
close all
%Initializing UQLab and Random Number Generator
clearvars
rng(100,'twister')
uqlab
%Calling Limit State Function

f1.mString = '5*X(:,1)+4*X(:,2)+0*X(:,3)+0*X(:,4)-40*X(:,5)+20*X(:,6)';
f1.isVectorized = true;
limitstate1 = uq_createModel(f1);

f2.mString = '5*X(:,1)+0*X(:,2)+4*X(:,3)+0*X(:,4)-40*X(:,5)+40*X(:,6)';
f2.isVectorized = true;
limitstate2 = uq_createModel(f2);

f3.mString = '0*X(:,1)+4*X(:,2)+0*X(:,3)+5*X(:,4)+-40*X(:,5)+-30*X(:,6)';
f3.isVectorized = true;
limitstate3 = uq_createModel(f3);

f4.mString = '0*X(:,1)+0*X(:,2)+4*X(:,3)+5*X(:,4)+-40*X(:,5)+-10*X(:,6)';
f4.isVectorized = true;
limitstate4 = uq_createModel(f4);   

fullsystem.mString = 'min(0*X(:,1)+4*X(:,2)+0*X(:,3)+5*X(:,4)-40*X(:,5)-30*X(:,6),0*X(:,1)+0*X(:,2)+4*X(:,3)+5*X(:,4)-40*X(:,5)-10*X(:,6))';
fullsystem.isVectorized = true;
systemfailure = uq_createModel(fullsystem);

%Variable Definition
Variables.Marginals(1).Name = 'R1'; 
Variables.Marginals(1).Type = 'Gaussian';
Variables.Marginals(1).Moments = [1500 400];

Variables.Marginals(2).Name = 'R2'; 
Variables.Marginals(2).Type = 'Gaussian';
Variables.Marginals(2).Moments = [1500 400];

Variables.Marginals(3).Name = 'R3'; 
Variables.Marginals(3).Type = 'Gaussian';
Variables.Marginals(3).Moments = [1500 400];

Variables.Marginals(4).Name = 'R4'; 
Variables.Marginals(4).Type = 'Gaussian';
Variables.Marginals(4).Moments = [1500 400];

Variables.Marginals(5).Name = 'X1'; 
Variables.Marginals(5).Type = 'Gaussian';
Variables.Marginals(5).Moments = [100 20];

Variables.Marginals(6).Name = 'X2'; 
Variables.Marginals(6).Type = 'Gaussian';
Variables.Marginals(6).Moments = [50 15];

%Input Object Creation
myInput = uq_createInput(Variables);

uq_selectModel(systemfailure)
MCOpts.Type = 'Reliability';
MCOpts.Method = 'MCS';
MCOpts.Simulation.MaxSampleSize = 1e6;
MCAnalysis = uq_createAnalysis(MCOpts);
uq_display(MCAnalysis)
