function fit=fit_catalog_exponential(data,paths) % He Eq10 family retained. Explicit base-MATLAB nonlinear least squares. % Affine fits are retained ONLY as comparator and tank fitting infrastructure. comparison=r23.fit_catalog(data,paths); r23.write_json(fullfile(paths.run,'affine-comparator-fits.json'),comparison); fc=data.fuel_cell_module_candidates;ids=[1 2 4 5]; x=[fc(ids).nominal_power_W]';mass=[fc(ids).module_mass_kg]';y=x./mass; names=string({fc(ids).component_id})'; fun=@(b,x)b(1)-b(2)*exp(-x/b(3)); decode=@(q)[exp(q(1))+exp(q(2)),exp(q(2)),exp(q(3))]; bestcost=Inf;starts=0; for base=[50 200 400] for amplitude=[200 500 1000] for scale=[300 1000 5000] q0=log([base amplitude scale]); [q,fval]=fminsearch(@(q)objective(q),q0,optimset('Display','off','MaxIter',3000,'MaxFunEvals',6000,'TolX',1e-10,'TolFun',1e-12)); starts=starts+1;if fval=y-1e-9); f=struct('family','H3_module','curve_type','exponential_specific_power','n',numel(x),'dof',dof, ... 'sample_ids',names,'x',x,'module_mass_kg',mass,'y_PD_W_per_kg',y,'domain',[min(x),max(x)], ... 'equation','PD_W_per_kg = a - b*exp(-P_W/c)','a',a,'b',b,'c',c,'covariance',covariance, ... 'coefficient_CI95',[best'-tcrit*sqrt(diag(covariance)),best'+tcrit*sqrt(diag(covariance))], ... 'residuals',residual,'RMSE',sqrt(sigma2),'R_squared',1-sum(residual.^2)/sum((y-mean(y)).^2), ... 'xgrid',xg,'mean',yg,'mean_CI95',ci,'prediction_PI95',pi95,'envelope_intercept_shift',shift, ... 'envelope_a',a+shift,'envelope_b',b,'envelope_y',env,'sample_covered',coverage,'coverage_count',sum(coverage), ... 'maximum_relative_curve_change',max(abs(shift)./yg),'multistart_count',starts, ... 'scaled_J_singular_values',svd(J.*best),'envelope_method','minimum vertical/asymptote shift a only; b,c unchanged exactly', ... 'band_scope','95% pointwise first-order nonlinear-regression Student-t intervals; n=4,p=3,df=1; no simultaneous or physical guarantee', ... 'boundary','nominal H3 module mass/power; external installed masses and net continuous output not certified'); fit=struct('fc',f,'tank',comparison.tank,'primary_route','He p5 Eq10 exponential PD and Eq11 energy versus empty tank mass', ... 'method','base MATLAB nonlinear least squares with positive PD/monotone saturation; analytic Jacobian covariance and Student-t delta intervals', ... 'fc_correlation_handling',comparison.fc_correlation_handling, ... 'IE_exclusion','IE has three nominal points, nonmonotone PD and zero df for a free three-coefficient model; retained for discrete candidate calculation, not a fabricated95% regression', ... 'paper_original_bands','Original raw points and covariance absent; published coefficient reconstruction separate from these new-data intervals', ... 'physical_guarantee',false); % Same energy--empty-mass line as He Eq11, with all unit factors explicit. for k=1:numel(fit.tank) fit.tank(k).energy_equation_Wh='E = (a_H2 + b_H2*m_empty_kg)*120e6/3600'; fit.tank(k).energy_intercept_Wh=fit.tank(k).a*120e6/3600; fit.tank(k).energy_slope_Wh_per_kg=fit.tank(k).b*120e6/3600; fit.tank(k).loaded_fraction_equation='omega = (a+b*m_empty)/(m_empty+a+b*m_empty)'; end r23.write_json(fullfile(paths.run,'catalog-fits.json'),fit); writetable(table(names,x,mass,y,yf,residual,'VariableNames',{'sample_id','P_W','module_mass_kg','PD_W_per_kg','fitted_PD_W_per_kg','residual_W_per_kg'}),fullfile(paths.inputs,'fit-H3-exponential.csv')); writetable(table(xg,yg,ci(:,1),ci(:,2),pi95(:,1),pi95(:,2),env,'VariableNames',{'P_W','mean_PD','CI95_low','CI95_high','PI95_low','PI95_high','optimistic_PD_envelope'}),fullfile(paths.run,'fc-exponential-bands.csv')); fig=figure('Position',[100 100 1060 440]);tiledlayout(1,2,'Padding','compact'); nexttile;fill([xg;flipud(xg)],[pi95(:,1);flipud(pi95(:,2))],[.94 .90 .80],'EdgeColor','none');hold on; fill([xg;flipud(xg)],[ci(:,1);flipud(ci(:,2))],[.78 .86 .98],'EdgeColor','none'); plot(xg,yg,'b-');plot(xg,env,'r--');scatter(x,y,40,'k','filled');grid on; xlabel('Nominal module power (W)');ylabel('Specific power (W/kg)');title('He exponential family; new H3 data, df=1'); legend('95% prediction','95% mean confidence','Nonlinear fit','Minimal same-shape envelope','SKU data','Location','best'); nexttile;plot(xg,xg./yg,'b-');hold on;plot(xg,xg./env,'r--');scatter(x,mass,40,'k','filled');grid on; xlabel('Nominal module power (W)');ylabel('Module mass (kg)');title('Mass derived as P / PD; installed boundary still pending'); r23.save_figure(fig,paths,'fit-fc-He-exponential-main');close(fig); fprintf('EXP_PD a=%.10g b=%.10g c=%.10g shift=%.10g df=%d\n',a,b,c,shift,dof); function v=objective(q) if any(q<-20|q>20),v=1e10+sum(q.^2);return;end bb=decode(q);v=sum((fun(bb,x)-y).^2); end end