function [thetaHat,rul]=NLS_Crack(theta0) clear global; global DegraUnit ... TimeUnit time y thres ParamName thetaTrue signiLevel ns ny np %=== PROBLEM DEFINITION 1 (Required Variables) ============== WorkName='Crack_NLS'; DegraUnit='Crack size (m)'; TimeUnit='Cycles'; time=[0:100:3500]'; y=[0.0100 0.0109 0.0101 0.0107 0.0110 0.0123 0.0099 0.0113... 0.0132 0.0138 0.0148 0.0156 0.0155 0.0141 0.0169 0.0168]'; thres=0.05; ParamName=['m'; 'C'; 's']; thetaTrue=[3.8; log(1.5e-10); 0.001]; signiLevel=5; ns=5e3; %============================================================ % % % PROGNOSIS using NLS ny=length(y); np=size(ParamName,1); %% Deterministic Estimation Optio=optimset('algorithm',{'levenberg-marquardt',0.01}); [thetaH,~,resid,~,~,~,J]=lsqnonlin(@FUNC,theta0,[],[],Optio); sse=resid'*resid; %% Distribution of Theta dof=ny-np+1; sigmaH=sqrt(sse/dof); W=eye(ny)*1/sigmaH^2; thetaCov=inv(J'*W*J); sigTheta=sqrt(diag(thetaCov)); mvt=mvtrnd(thetaCov,dof,ns)'; thetaHat=repmat(thetaH,1,ns)+mvt.*repmat(sigTheta,1,ns); thetaHat(np,:)=sigmaH*ones(1,ns); %% Final Sampling Results for k=1:length(time(ny:end)); %% Degradation Prediction zHat(k,:)=MODEL(thetaHat,time(ny-1+k)); mu=zHat(k,:); C=chi2rnd(ny-1,1,ns); s=sqrt((ny-1)*thetaHat(np,:).^2./C); zeta=sqrt(log(1+(s./mu).^2)); eta=log(mu)-0.5*zeta.^2; degraPredi(k,:)=lognrnd(eta,zeta); end; % % % POST-PROCESSING degraTrue=[]; %% True Degradation if ~isempty(thetaTrue); degraTrue=MODEL(thetaTrue,time); end rul=POST(thetaHat,degraPredi,degraTrue); %% RUL & Result Disp Name=[WorkName ' at ' num2str(time(ny)) '.mat']; save(Name); end function objec=FUNC(theta) global time y ny z=MODEL(theta,time(1:ny)); objec=(y-z); end function z=MODEL(theta,t) global ParamName np for j=1:np-1; eval([ParamName(j,:) '=theta(j,:);']); end %===== PROBLEM DEFINITION 2 (model equation) =============== a0=0.01; dsig=75; z=(t.*exp(C).*(1-m./2).*(dsig*sqrt(pi)).^m ... +a0.^(1-m./2)).^(2./(2-m)); loca=imag(z)~=0; z(loca)=1; %=========================================================== end