% Weight Sizing for a Jet
% By: Patrick LeGresley
% January 21, 1999
%
% Based on Airplane Design, Part I by Roskam
%
% Last modified March 3, 1999

clear all
close all

% Define/Specify Inputs

wf_warmup = 0.99;         % Weight fraction for warmup segment
wf_taxi = 0.99;           % Weight fraction for taxi segment
wf_takeoff = 0.995;       % Weight fraction for takeoff segment
wf_climb = 0.98;          % Weight fraction for climb segment
wf_descent = 0.99;        % Weight fraction for descent segment
wf_landtaxi = 0.992;      % Weight fraction for landing, taxi, and shutdown segment

m_tfo = 0.005;            % Weight of trapped fuel and oil divided by takeoff weight

c_j_cruise = 0.65;        % Cruise specific fuel consumption (lbs/lb/hr)
LD_cruise = 14;           % Lift-to-drag ratio for cruise segment
V_cruise = 350;           % Cruise Speed (knots)
R_cruise = 1500;          % Range (nm)

c_j_loiter = 0.65;        % Loiter specific fuel consumption (lbs/lb/hr)
LD_loiter = 14;           % Lift-to-drag ratio for loiter segment
E_loiter = 0.75;          % Time of loiter (hours)

A = -0.2009;              % Regression coefficients for takeoff versus empty weight
B = 1.1037;               % Based on military transport jet data

W_payload = 10400;        % Payload weight including crew (lbs)
W_guess = 35000;          % Initial guess for takeoff weight (lbs) to begin iteration
epsilon = 0.01;           % Tolerance value for solving for takeoff weight

composite = 0.95;         % Factor to account for weight savings from composite structure

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Calculate Cruise Fuel Fraction using Breguet Range Equation
wf_cruise = 1/exp(R_cruise/((V_cruise/c_j_cruise)*LD_cruise));

% Calculate Loiter Fuel Fraction using Breguet Endurance Equation
wf_loiter = 1/exp(E_loiter/((1/c_j_loiter)*LD_loiter));

% Calculate Mission Fuel Fraction
M_ff = wf_warmup*wf_taxi*wf_takeoff*wf_climb*wf_cruise*wf_loiter*wf_descent*wf_landtaxi;


% Calculate Takeoff Weight by Iteration

W_e_tentative = 100;      % Initialize weight values to start loop
W_e_allowable = 0;

while abs(W_e_tentative-W_e_allowable) > epsilon
   
   W_oe_tentative = W_guess - (1-M_ff)*W_guess - W_payload;
   W_e_tentative = W_oe_tentative - m_tfo*W_guess;
   
   % Find the allowable value for W_e
   W_e_allowable=composite*10^((log10(W_guess)-A)/B);

   % Modify initial weight guess
   W_guess = W_guess + (W_e_allowable - W_e_tentative)/2;

end

% Calculate takeoff weight, trapped fuel and oil weight, fuel weight, and empty weight
W_to = W_guess;
W_tfo = m_tfo*W_to;
W_fuel = (1-M_ff)*W_to;
W_e = W_to - W_fuel - W_tfo - W_payload;


% Calculate takeoff weight sensitivities

C = (1 - (1 - M_ff) - m_tfo);
D = W_payload;

% Calculate sensitivity of takeoff weight to payload weight
payloadsensitivity = B*W_to*(D - C*(1-B)*W_to)^-1;

% Calculate sensitivity of takeoff weight to empty weight
emptyweightsensitivity = B*W_to*(10^((log10(W_to)-A)/B))^-1;

F = -B*W_to^2*(C*W_to*(1-B)-D)^-1*M_ff;

% Calculate sensitivity of takeoff weight to range
rangesensitivity = F*c_j_cruise*(V_cruise*LD_cruise)^-1;

% Calculate sensitivity of takeoff weight to sfc
sfcsensitivity = F*R_cruise*(V_cruise*LD_cruise)^-1;

% Calculate sensitivity of takeoff weight to lift-to-drag ratio
LDsensitivity = -F*R_cruise*c_j_cruise*(V_cruise*LD_cruise^2)^-1;

% Output
fprintf('\n');
fprintf('Takeoff Weight    %1.0f lbs\n', W_to);
fprintf('Empty Weight      %1.0f lbs\n', W_e);
fprintf('Fuel Weight       %1.0f lbs\n', W_fuel);
fprintf('\n');
fprintf('Sensitivity of Takeoff Weight to Payload Weight    %1.1f\n', payloadsensitivity);
fprintf('Sensitivity of Takeoff Weight to Empty Weight      %1.1f\n', emptyweightsensitivity);
fprintf('\n');
fprintf('For Cruise Segment, Sensitivity to:\n');
fprintf('  Range                    %5.1f lb/nm\n', rangesensitivity);
fprintf('  sfc                      %1.1f hp-hr\n', sfcsensitivity);
fprintf('  L/D                      %1.1f lbs\n', LDsensitivity);
fprintf('\n');
