function [thetaHat,rul]=NLS_Battery(theta0) clear global; global DegraUnit ... TimeUnit time y thres ParamName thetaTrue signiLevel ns ny np %=== PROBLEM DEFINITION 1 (Required Variables) ============== WorkName='Battery_NLS'; DegraUnit='C/1 Capacity'; TimeUnit='Cycles'; time=[0:5:200]'; y=[1.00 0.99 0.99 0.94 0.95 0.94 0.91 0.91 0.87 0.86]'; thres=0.7; ParamName=['b'; 's']; thetaTrue=[0.003; 0.02]; 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)); degraPredi(k,:)=zHat(k,:)+trnd(dof,1,ns)*sigmaH; 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) =============== z=exp(-b.*t); %=========================================================== end