clc
clear all
%% data input
load('D2.2.mat')
y1 = St; y2 = De;
x1 = T; x2 = L; x3 = M; x4 = F;
%% do not include cross terms for deformation simulation
X1=[ones(size(y1)) x1 x2 x3 x4 x1.^2 x2.^2 x3.^2 x4.^2 ];
[b1,bint1,r1,rint1,stats1] = regress(y2,X1);
Yp=b1(1)+b1(2)*x1 + b1(3)*x2 + b1(4)*x3 + b1(5)*x4 + b1(6)*x1.^2 +...
b1(7)*x2.^2 + b1(8)*x3.^2 +b1(9)*x4.^2;
%% including cross terms for stress simulation
% X1=[ones(size(y1)) x1 x2 x3 x4 x1.*x2 x1.*x3 x1.*x4 x2.*x3...
% x2.*x4 x3.*x4 ];
% [b1,bint1,r1,rint1,stats1] = regress(y1,X1);
%
% Yp=b1(1)+b1(2)*x1 + b1(3)*x2 + b1(4)*x3 + b1(5)*x4 + b1(6)*x1.*x2 +...
% b1(7)*x1.*x3 + b1(8)*x1.*x4 + b1(9)*x2.*x3 + b1(10)*x2.*x4 + b1(11)*x3.*x4;
%% visualization
subplot(1,2,1)
plot(y2,'-b*','MarkerSize',8)
hold on
plot(Yp,'-bo','MarkerSize',8)
legend('Real output','Estimate output')
%% reliability carculation based on monte carlo simulation
number = 100000;% 抽样次数
TMC = 0.03 + 0.0004*randn(number,1); x1 = TMC;
LMC = 0.3 + 0.006*randn(number,1); x2 = LMC;
MMC = 12391 + 247.82*randn(number,1); x3 = MMC;
FMC = 43341 + 866.82*randn(number,1); x4 = FMC;
YMCp=b1(1)+b1(2)*x1 + b1(3)*x2 + b1(4)*x3 + b1(5)*x4 + b1(6)*x1.^2 +...
b1(7)*x2.^2 + b1(8)*x3.^2 +b1(9)*x4.^2;%deformation prediction
% YMCp=b1(1)+b1(2)*x1 + b1(3)*x2 + b1(4)*x3 + b1(5)*x4 + b1(6)*x1.*x2 +...
% b1(7)*x1.*x3 + b1(8)*x1.*x4 + b1(9)*x2.*x3 + b1(10)*x2.*x4 + b1(11)*x3.*x4;%stress prediction
subplot(1,2,2)
histfit(YMCp,75)
Ya = 270e6;%allowable value for stress
Yaa = 9e-4;%allowable value for deformation
R = sum(YMCp<Yaa)/number