function out=upper_analysis(fit,p,data,paths) % Bounded catalogue/family sizing scenario. Explicitly not a human-wide limit. diameters=[p.diameter_22 p.diameter_28 p.diameter_30]; maxfc=max(arrayfun(@(f)r23.fc_mass(f,f.domain(2)),fit.fc)); maxtank=max(arrayfun(@(f)f.domain(2)+f.envelope_a+f.envelope_b*f.domain(2),fit.tank)); Mclosure=(maxfc+maxtank+p.payload+p.buffer_mass)/(1-p.nonenergy_fraction); Mgrid=linspace(2,Mclosure+1,1000)';Vgrid=linspace(0,p.speed_max,101); allT=nan(numel(Mgrid),3);sel=cell(numel(Mgrid),3);opts=struct([]); for d=1:3 for i=1:numel(Mgrid),[allT(i,d),sel{i,d}]=at(Mgrid(i),p.fixed_speed,diameters(d));end vals=allT(:,d);inds=find(isfinite(vals)); if isempty(inds),continue;end candidates=inds((vals(inds)>=vals(max(inds-1,1)) | ~isfinite(vals(max(inds-1,1)))) & ... (vals(inds)>=vals(min(inds+1,numel(vals))) | ~isfinite(vals(min(inds+1,numel(vals)))))); [~,im]=max(vals);candidates=unique([candidates;im]); for ii=candidates' a=Mgrid(max(ii-2,1));b=Mgrid(min(ii+2,numel(Mgrid))); [mo,minusT]=fminbnd(@(m)cost(m,p.fixed_speed,diameters(d)),a,b,optimset('TolX',1e-8,'Display','off')); [tv,sv]=at(mo,p.fixed_speed,diameters(d)); if isfinite(tv) z=sv;z.M_kg=mo;z.speed_m_s=p.fixed_speed;z.diameter_m=diameters(d);z.endurance_h=tv; z.optimizer_cost=minusT; if isempty(opts),opts=z;else,opts(end+1)=z;end end end end assert(~isempty(opts),'No feasible sizing case.'); [~,ib]=max([opts.endurance_h]);best=opts(ib); bestcurve=max(allT,[],2,'omitnan');bestcurve(all(~isfinite(allT),2))=NaN; T=table(Mgrid,allT(:,1),allT(:,2),allT(:,3),bestcurve,'VariableNames',{'mass_kg','T22_h','T28_h','T30_h','reselected_D_envelope_h'}); writetable(T,fullfile(paths.run,'mass-scan.csv')); speedT=nan(size(Vgrid));speedP=nan(size(Vgrid)); for i=1:numel(Vgrid),[speedT(i),sv]=at(best.M_kg,Vgrid(i),best.diameter_m);if isfinite(speedT(i)),speedP(i)=sv.Pbus_W;end,end writetable(table(Vgrid',speedT',speedP','VariableNames',{'airspeed_m_s','endurance_h','bus_power_W'}),fullfile(paths.run,'speed-scan.csv')); % Independent 2-D grid plus multi-start bounded search in M,V per geometry. coarseM=linspace(2,Mclosure,180);joint=struct('endurance_h',-Inf);starts=[]; for d=1:3 for v=linspace(0,p.speed_max,25) vv=arrayfun(@(m)scalar(m,v,diameters(d)),coarseM);[tt,jj]=max(vv); if isfinite(tt),starts(end+1,:)=[coarseM(jj),v,d];end end end for j=1:size(starts,1) d=starts(j,3);x0=starts(j,1:2); [x,~]=fminsearch(@(x)bounded_cost(x,diameters(d)),x0, ... optimset('Display','off','TolX',1e-8,'TolFun',1e-9,'MaxIter',400)); [tv,sv]=at(x(1),x(2),diameters(d)); if isfinite(tv) && tv>joint.endurance_h,joint=sv;joint.M_kg=x(1);joint.speed_m_s=x(2);joint.diameter_m=diameters(d);joint.endurance_h=tv;end end out=struct('task_id','SIM-R3-001','stage','upper_bound_phase1','full_contract_completed',false, ... 'model_version','R23-HE2.0.0','matlab_release',version('-release'),'scope','He exponential-family grouped-catalogue optimistic sizing; not a universal engineering ceiling', ... 'human_engineering_absolute_limit_proved',false,'fixed_speed_optimum',best,'joint_mass_speed_optimum',joint, ... 'closure_mass_domain_upper_kg',Mclosure,'diameter_candidates_m',diameters, ... 'optimization_candidates',opts,'independent_multistart_count',size(starts,1), ... 'fit_results','reports/05_simulation/R23-001/runs/SIM-R3-001-he-v2/catalog-fits.json', ... 'input_manifest','reports/04_models/R23-001/inputs/snapshot-manifest.json', ... 'engineering_parameters','reports/04_models/R23-001/parameters.csv'); out.boundary_notes={ ... 'Power is a nominal module scenario; installed net continuous power, propulsion/thermal maps and complete BOM remain R2 handoff inputs.', ... '22/28/30 inch geometries are reselected; 22 and30 are geometric relaxations with incomplete matched continuous hardware evidence.', ... 'He mass fractions and forward drag/tip speed are explicit research assumptions, not a structural scale law or hardware certification.', ... 'The compact mass bound is derived from declared fractional closure and finite FC/tank fit domains. It is not a scan endpoint assertion.', ... 'Within fixed total disk area, induced power scales M^(3/2), while usable hydrogen cannot grow faster than available mass; tail endurance tends to zero under stated assumptions.', ... 'Allowing unrestricted rotor/structure scaling can invalidate a finite inner optimum. Current evidence cannot establish an all-human engineering bound.', ... 'Mean confidence and individual prediction bands are pointwise OLS statements; optimistic intercept envelopes cover admitted samples only and are not physical guarantees.'}; r23.write_json(fullfile(paths.report,'upper-bound-summary.json'),out); fig=figure('Position',[100 100 1040 450]);tiledlayout(1,2,'Padding','compact'); nexttile;plot(Mgrid,allT);hold on;plot(Mgrid,bestcurve,'k--','LineWidth',2);scatter(best.M_kg,best.endurance_h,60,'r','filled');grid on; xlabel('Take-off mass (kg)');ylabel('Steady endurance (h)');title(sprintf('Fixed airspeed %.1f m/s; bounded catalogue model',p.fixed_speed)); legend('22 in geometry','28 in geometry','30 in geometry','Reselected geometry','Refined best','Location','best'); nexttile;yyaxis left;plot(Vgrid,speedT);ylabel('Steady endurance (h)');yyaxis right;plot(Vgrid,speedP);ylabel('Bus power (W)'); xlabel('Airspeed (m/s)');grid on;title(sprintf('Fixed optimized mass %.3f kg, D=%.1f in',best.M_kg,best.diameter_m/0.0254)); r23.save_figure(fig,paths,'mass-and-speed-scans');close(fig); % Fixed-area tail mechanism, with deliberately relaxed energy cap (not a design). mt=logspace(0,3,300)';At=p.rotor_count*pi*(max(diameters)/2)^2; Pideal=(p.nonenergy_fraction*mt*p.g).^(3/2)/sqrt(2*p.rho*At); Tcap=mt*p.LHV*p.eta_fc./Pideal/3600; writetable(table(mt,Pideal,Tcap,'VariableNames',{'mass_kg','ideal_induced_lower_W','all_mass_as_H2_energy_bound_h'}),fullfile(paths.run,'fixed-area-tail-bound.csv')); fig=figure('Position',[100 100 680 440]);loglog(mt,Tcap);grid on;xlabel('Mass (kg)');ylabel('Deliberately loose energy / induced-power bound (h)'); title('Fixed-area tail decreases as M^{-1/2}; no structural scaling proof');r23.save_figure(fig,paths,'fixed-area-tail-bound');close(fig); fprintf('UPPER_FIXED_M=%.8g kg T=%.8g h D=%.4g m\n',best.M_kg,best.endurance_h,best.diameter_m); fprintf('UPPER_JOINT_M=%.8g kg V=%.8g m/s T=%.8g h\n',joint.M_kg,joint.speed_m_s,joint.endurance_h); function v=scalar(M,V,D),[v,~]=at(M,V,D);if ~isfinite(v),v=-Inf;end,end function c=cost(M,V,D),v=scalar(M,V,D);if ~isfinite(v),c=1e5+abs(M);else,c=-v;end,end function c=bounded_cost(x,D) if x(1)<2||x(1)>Mclosure||x(2)<0||x(2)>p.speed_max c=1e5+sum(abs(x)); else c=cost(x(1),x(2),D); end end function [t,s]=at(M,V,D) Pbus=r23.power(M,V,D,p);t=NaN;s=struct; for fci=1:numel(fit.fc) fc=fit.fc(fci);if Pbusfc.domain(2),continue;end mfc=r23.fc_mass(fc,Pbus); available=(1-p.nonenergy_fraction)*M-p.payload-p.buffer_mass-mfc; for ti=1:numel(fit.tank) tf=fit.tank(ti);me=(available-tf.envelope_a)/(1+tf.envelope_b); if metf.domain(2),continue;end h=tf.envelope_a+tf.envelope_b*me; if h<=0,continue;end tt=h*p.hydrogen_usable*p.LHV*p.eta_fc/Pbus/3600; if ~isfinite(t)||tt>t t=tt;s=struct('Pbus_W',Pbus,'mfc_kg',mfc,'empty_tank_kg',me,'loaded_hydrogen_kg',h, ... 'usable_hydrogen_kg',h*p.hydrogen_usable,'fc_family',fc.family,'tank_family',tf.family, ... 'mass_closure_residual_kg',M-(p.nonenergy_fraction*M+p.payload+p.buffer_mass+mfc+me+h)); end end end end end