% Jennifer Owens
% Last Modified May 1, 1999

% 1999 AIAA Graduate Team Aircraft Design Competition
% The Cardinal Project
% Cost Estimation
function [LCC,DOC] = cost_opt(tiltwing,h,V,N_e,V_C,W_to,W_e,W_f_used,...
   R_bl,R_cruise,W_eng_single,t_cl,T_to,output)

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DEFINE ALL CONSTANTS
%tiltwing = 1;						% 1 for tiltwing, anything else for jet

% Airplane Weights
%W_e = 34588;						% Airplane Empty Weight
%W_to = 59922;						% Takeoff Weight
W_eng = N_e*W_eng_single;						% Weight of the engines (total)
%W_f_used = 10000;					% Weight of mission fuel used

% Airplane Constants
%h = 30000;							% Cruise altitude (feet)
%V_C = 157;							% Design cruise speed (keas)
P_to = T_to;						% Total Shaft Horsepower at Takeoff (lb)
%T_to = 30000;						% Total installed thrust at takeoff (lb)
%R_bl = 1500;						% Block distance in nautical miles (depends on routes flown)
%R_cruise = 1450;					% Cruise Range (in nmi)
V_cruise = V;					% Cruise Speed (in knots)
RD = 2500;							% Rate of descent (ft/min)

% Flight Profile Times
t_pft = 15;							% flight test hours before delivery to customer (2-20::ga-mil)
t_gm = 17/60;						% Time spent in ground maneuvers (hours)
%t_cl = 0.25;						% Time required to climb & accelerate to the cruise speed (hrs)

% Maintenance Hours
H_em_turboprop = 4000;			% Hours between turboprop engine overhaul
H_em_turbofan = 4000;			% Hours between turbofan engine overhaul

% Labor Rates
R_er_1989 = 62;					% Engineering Dollar Rate per hour (1989 data, fig 3.3)
										% for airframe engineering activity
R_mr_1989 = 34;					% Manufacturing labor rate in dollars per manhour(fig 3.4)				
R_tr_1989 = 44;					% Tooling labor rate (fig 3.5)
R_l_ap = 15;						% Labor rate for airframe & systems maintenance workers (table 5.5)
R_l_eng = 15;						% Labor rate for engine maintenance workers (table 5.5)

% Cost Escalation Factors
CEF_1989 = 3.19;					% Cost Escalation Factor for 1989
CEF_1990 = 3.38;					% Cost Escalation Factor for 1990
CEF_1999 = 4.47;					% Cost Escalation Factor for 1999

% Multiplicative Factors
F_diff = 2;							% Judgement factor for difficulty (1-2.5)
F_cad = 0.8;						% Judgement factor for CAD experience (1.2-0.8)
F_mat = 1.5;						% Correction factor for materials (1-3::Al-Comp)
F_obs = 1;							% Depends on the importance of having low observables
										% (1-3::commercial-stealth)
F_tsf = 0.1 ;						% Factor for addition of new facilities (0-0.2::none-lots)
F_pro_r = 0.1;						% Profit factor (typ 0.1)
F_fin_r = 0.1;						% Depends on interest rates (0.1-0.2)
F_int = 1500;						% Interior Cost Factor in USD/passenger (0-3000::mil-bizjet)
F_ftoh = 4.0;						% Overhead factor (typ 4)
F_fin_m = 0.1;						% Depends on interest rates (0.1-0.2)
F_pro_m = 0.1;						% Based on market (typ 0.1 for 10% profit)
F_dap = 0.85;						% Airframe depreciation factor
F_deng = 0.85;						% Engine depreciation factor
F_dprp = 0.85;						% Propellor depreciation factor
F_dav = 1;							% Avionics depreciation factor
F_dapsp = 0.85;					% Airplane spares depreciation factor
F_dengsp = 0.85;					% Engine spares depreciation factor
F_apsp = 0.1;						% Airplane spare parts factor
F_engsp = 0.5;						% Engine spare parts factor
f_amb_lab = 1.2;					% Overhead distribution factor for labor cost
f_amb_mat = 0.55;					% Overhead distribution factor for material cost
ATF = 1;								% Airplane type factor
ESPPF = 1.5;						% Engine Spare Parts Price Factor
K_avionics = 0.3;					% Factor for avionics cost
f_ins_hull = 0.015;				% Hull insurance rate ($/$/airplane/year) (0.005 - 0.030)
f_ioc = 0.2;						% fraction of DOC by which IOC is estimated

% Known Costs
C_ops_fto = 1600;					% Operating Cost for flight test operations ($/hr)
FP = 0.18;							% Price of fuel ($/lb)
OLP = 2;								% Price of oil & lubricants ($/lb)
C_apnf = 0;							% Navigation fee charged per airplane per flight

% Crew Data
n_c1 = 1; 							% Number of captains
n_c2 = 1;							% Number of first officers
K1 = 0.26;							% Factor to account for vacation, training, insurance, taxes
K2 = K1;								% Factor to account for vacation, training, insurance, taxes
SAL1_1989 = 40000;				% Captain's Salary
SAL2_1989 = 20000;				% First officer's salary
AH1 = 800;							% Number of flight hours per year for the crew member
AH2 = AH1;							% Number of flight hours per year for the crew member
TEF1_1990 = 7;						% Travel Expense factor 
TEF2_1990 = TEF1_1990;			% Travel Expense factor 

% Depreciation Periods
DP_ap = 10;							% Airframe depreciation period
DP_eng = 7;							% Engine depreciation period
DP_prp = 7;							% Propellor depreciation period
DP_av = 5;							% Avionics depreciation period
DP_apsp = 10;						% Airplane spares depreciation period
DP_engsp = 7;						% Engine spares depreciation period

% Quantities of Airplane Components
N_rdte = 4;							% Number of airplanes produced for RDTE phase (2-8)
N_e = 4;								% Number of engines per airplane
N_p = 2;								% Number of propellors per airplane
N_st = 2;							% Number of static test airplanes
N_r_r = 0.33;						% RDTE production rate in units per month (0.33 typ)
N_m = 750;							% Number of airplanes produced to production standard
N_program = N_m + N_rdte;		% Number of airplanes produced during the airplane program
N_pax = 24;							% Number of passengers
N_r_m = 6;							% MAN/ACQ Production rate in units per months
N_e = 4;								% Number of engines per airplane
N_acq = N_m;						% Number of Airplanes acquired by the customer
N_yr = 20;							% Number of years the airplanes will be in operation

if tiltwing == 1
   % Engine Price
   EP = (10^(2.5262 + 0.9465*(log10(P_to/N_e))))*CEF_1999/CEF_1989;
   % Propellor Price (composite propellors)
   PP = (10^(0.7746 + 1.1432*(log10(P_to/N_e))))*CEF_1999/CEF_1989;
   % Airplane Market Price
	AMP_1989 = 10^(1.1846 + 1.2625*(log10(W_to)));
	AMP_1999 = AMP_1989*CEF_1999/CEF_1989;
else
   % Engine Price
   EP = (10^(2.3044 + 0.8858*(log10(T_to/N_e))))*CEF_1999/CEF_1989;
   % Propellor Price (composite propellors)
   PP = 0;
   % Airplane Market Price
	AMP_1989 = 10^(3.3191 + 0.8043*(log10(W_to)));
	AMP_1999 = AMP_1989*CEF_1999/CEF_1989;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Component Costs
% Roskam Part VIII, Appendix B
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Engine Pricing, RDTE Phases (only used for 400 < SHP < 5000 lb)
if tiltwing == 1
	C_e_r = (10^(2.5262 + 0.9465 *(log10(P_to/N_e))))*CEF_1999/CEF_1989;
else
   C_e_r = (10^(2.3044 + 0.8858 *(log10(T_to/N_e))))*CEF_1999/CEF_1989;
end

% Propellor Prices, RDTE Phases (assuming composite propellors)
C_p_r = (10^(0.7746 + 1.1432 *(log10(P_to/N_e))))*CEF_1999/CEF_1989;

% Avionics Prices, RDTE Phases
C_avionics_r = K_avionics*AMP_1999;

% Engine prices, Manufacturing/Acquisition Phases
C_e_m = C_e_r;

% Propellor prices, Manufacturing/Acquisition Phases
C_p_m = C_p_r;

% Avionics prices, Manufacturing/Acquisition
C_avionics_m = C_avionics_r;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Research, Development, Test, and Evaluation Cost (prototyping too)
% Roskam Part VIII, Chapter 3
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Airframe Engineering & Design Costs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% AMPR Weight Calculation
W_ampr = 10^(0.1936 + 0.8645*(log10(W_to)));

% Engineering Dollar rate charged per manhour for the airframe engineering
% activity.  
R_er_1999 = R_er_1989*(CEF_1999/CEF_1989);

% Total number of manhours required to complete RDTE
% From Roskam VIII, page 24
MHR_aed_r = (0.0396*W_ampr^0.791)*(V_C^1.526)*(N_rdte^0.183)...
   *F_diff*F_cad;

% Airframe Engineering & Design Cost (Roskam VIII pg 24)
C_aed_r = MHR_aed_r*R_er_1999;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Development Support & Testing Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C_dst_r = (0.008325*W_ampr^0.873)*(V_C^1.890)*(N_rdte^0.346)...
   *CEF_1999*F_diff;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Flight Test Airplanes Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Cost of engines and avionics for the airplanes & airframes required
% for RDTE
C_ea_r = ((C_e_r*N_e)+C_avionics_r)*(N_rdte - N_st);

% Manufacturing labor rate in dollars per manhour
R_mr_1999 = R_mr_1989*(CEF_1999/CEF_1989);

% Total number of manufacturing manhours in RDTE
MHR_man_r = (28.984*W_ampr^0.740)*(V_C^0.543)*...
   (N_rdte^0.524)*F_diff;

% Manufacturing Cost of the flight test airplanes
C_man_r = MHR_man_r*R_mr_1999;

% Cost of materials to manufacture the flight test airplane
C_mat_r = (37.632*F_mat*W_ampr^0.689)*(V_C^0.624)*...
   (N_rdte^0.792)*CEF_1999;

% Tooling Labor rate
R_tr_1999 = R_tr_1989*(CEF_1999/CEF_1989);

% Tooling manhours for RDTE
MHR_tool_r = (4.0127*W_ampr^0.764)*(V_C^0.899)*(N_rdte^0.178)*...
   (N_r_r^0.066)*F_diff;

% Cost of tooling for RDTE
C_tool_r = MHR_tool_r*R_tr_1999;

% Cost of quality control cost for RDTE
C_qc_r = 0.13*C_man_r;

% Flight test airplanes cost
C_fta_r = C_ea_r + C_man_r + C_mat_r + C_tool_r + C_qc_r;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Flight Test Operations Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C_fto_r = (0.001244*W_ampr^1.160)*(V_C^1.371)*...
   ((N_rdte - N_st)^1.281)*CEF_1999*F_diff*F_obs;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


% Research, Development, Test, and Evaluation Cost (prototyping too)
% Roskam Part VIII, Chapter 3
C_rdte = (C_aed_r + C_dst_r + C_fta_r + C_fto_r)...
   /(1 - F_tsf - F_pro_r - F_fin_r);
% End of RDTE Phase Costs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Test and Simulation Facilities Cost
C_tsf_r = F_tsf*C_rdte;
% RDTE Profit
C_pro_r = F_pro_r*C_rdte;
% RDTE Financing
C_fin_r = F_fin_r*C_rdte;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Manufacturing and Acquisition Cost
% Roskam Part VIII, Chapter 4
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Airframe Engineering & Design Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Total amount of engineering manhours required for all N_program airplanes
MHR_aed_program = (0.0396*W_ampr^0.791)*(V_C^1.526)*...
   (N_program^0.183)*F_diff*F_cad;

% Airfrane engineering & design cost
C_aed_m = MHR_aed_program*R_er_1999-C_aed_r;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Airplane Program Production Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Cost of engine and avionics
C_ea_m = (C_e_m*N_e + C_p_m*N_p + C_avionics_m)*N_m;

% Cost of interior
C_int_m = F_int*N_pax*N_m*(CEF_1999/CEF_1990);

% Manhours required to manufacture N_program airplanes
MHR_man_program = (28.984*W_ampr^0.740)*(V_C^0.543)*...
   (N_program^0.524)*F_diff;

% Manufacturing labor cost
C_man_m = MHR_man_program*R_mr_1999 - C_man_r;

% Materials Cost
C_mat_program = (37.632*F_mat*W_ampr^0.689)*(V_C^0.624)...
   *(N_program^0.792)*CEF_1999;

C_mat_m = C_mat_program - C_mat_r;

% Tooling Manhours required
MHR_tool_program = (4.0127*W_ampr^0.764)*(V_C^0.899)*...
   (N_program^0.178)*(N_r_m^0.066)*F_diff;

% Tooling Cost
C_tool_m = MHR_tool_program*R_tr_1999 - C_tool_r;

% Quality Control Cost
C_qc_m = 0.13*C_man_m;

% Airplane Program Production Cost
C_apc_m = C_ea_m + C_int_m + C_man_m + C_mat_m + C_tool_m + C_qc_m;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Production Flight Test Operations Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C_fto_m = N_m*C_ops_fto*t_pft*F_ftoh;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Manufacturing Cost
C_man = (C_aed_m + C_apc_m + C_fto_m)/(1-F_fin_m);

% Cost for Manufacturing & Acquisition Financing
C_fin_m = F_fin_m*C_man;

% Profit made by manufacturer
C_pro = F_pro_m*C_man;

% Acquisition Cost
C_acq = C_man + C_pro;

% Unit Price per airplane
AEP = (C_man + C_pro + C_rdte)/N_m;

%End of Manufacturing & Acquisition Phase
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Operating Cost for Commercial Airplanes
% Roskam Part VIII, Chapter 5
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Assumption: All airplanes are acquired in one particular year at
% one particular price

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Values useful for the following calculations.....
% Cruise Time
t_cr = (R_cruise - 250*t_cl)/V_cruise;

% Descent Time
t_de = h/RD/60;

% Block Time
t_bl = t_gm + t_cl + t_cr + t_de;

% Annual Utilization in block hours
% Assuming that half the flights are cargo, and half are passenger
U_ann_bl =0.5*(1E3*(3.4546*t_bl + 2.994 - (12.289*t_bl*t_bl - 5.6626...
   *t_bl + 8.964)^(1/2))) + 0.5*(1E3*(6.053*t_bl + 5.70 - (37.771...
   *t_bl*t_bl + 13.494*t_bl + 32.490)^(1/2)));

% Block speed (knots)
V_bl = R_bl/t_bl;

% Average flight time
t_flt = t_cl + t_cr + t_de;

% Average flight speed
V_flt = V_cruise*(t_cr/t_flt);

% Annual Utilization in flight hours
U_ann_fl = U_ann_bl*V_bl/V_flt;

% Total annual block miles
R_bl_ann = V_bl*U_ann_bl;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Direct Operating Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DIRECT OPERATING COSTS FOR FLYING --------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Crew cost per nautical mile
% Captain Salary
SAL1_1999 = SAL1_1989*CEF_1999/CEF_1989;

% Captain Travel Expense Factor
TEF1_1999 = TEF1_1990*CEF_1999/CEF_1990;

% First Officer Salary
SAL2_1999 = SAL2_1989*CEF_1999/CEF_1989;

% First Officer Travel Expense Factor
TEF2_1999 = TEF2_1990*CEF_1999/CEF_1989;

% Crew cost per nautical mile
C_crew = n_c1*((1+K1)/V_bl)*(SAL1_1999/AH1)+(TEF1_1999/V_bl) + n_c2...
   *((1+K2)/V_bl)*(SAL2_1999/AH2)+(TEF2_1999/V_bl);

% Petroleum, oil, and lubricants cost per nautical mile
% Weight of fuel 
W_f_bl = W_f_used;

% Weight of oil & lubricants
% Assuming turbine engines
W_ol_bl = 0.7*N_e*t_bl;

% Fuel & Oil Cost
C_pol = W_f_bl/R_bl*FP + W_ol_bl/R_bl*OLP;

% Cost of airframe insurance
C_ins = f_ins_hull*AMP_1999/(U_ann_bl*V_bl); 

% Direct Operating Cost of flying
DOC_flt = C_crew + C_pol + C_ins;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DIRECT OPERATING COSTS FOR MAINTENANCE----------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Weight of the airframe
W_a = W_e - W_eng;

% Number of airframe and system maintenance manhours per block hour
MHR_map_bl = 3 + 0.067*W_a/1000;

% Labor Cost of airframes & systems maintenance
C_lab_ap = 1.03*MHR_map_bl*R_l_ap/V_bl;

% Number of engine maintenance manhours per block hour
if tiltwing == 1
   MHR_meng_bl = ((0.4956 + 0.0532*(P_to/N_e)/1000)*(1100/...
      H_em_turboprop) + 0.10);
else
   MHR_meng_bl = ((0.7180 + 0.0317*(T_to/N_e)/1000)*(1100/...
      H_em_turbofan) + 0.10);
end

% Labor cost of engine maintenance
C_lab_eng = 1.03*1.3*N_e*MHR_meng_bl*R_l_eng/V_bl;

% Airframe Price
AFP = AEP - N_e*EP;

% Airframe & Systems maintenance materials cost per airplane block hour
C_mat_apblhr = 30.0*(CEF_1999/CEF_1989)*ATF + 0.79E-5*AFP;

% Cost of maintenance materials for airframes & systems
C_mat_ap = 1.03*C_mat_apblhr/V_bl;

% Attained period between overhaul factor
if tiltwing == 1
   H_em = H_em_turboprop;
else
   H_em = H_em_turbofan;
end

K_H_em = 0.021*(H_em/100) + 0.769;

% Engine maintenance materials cost per engine per airplane block hour
C_mat_engblhr = (5.43E-5*EP*ESPPF - 0.47)/K_H_em;

% Cost of maintenance materials for engines
C_mat_eng = 1.03*1.3*N_e*C_mat_engblhr/V_bl;

% Applied Maintenance Burden per nautical mile
C_amb = 1.03*(f_amb_lab*(MHR_map_bl*R_l_ap + N_e*...
   MHR_meng_bl*R_l_eng) + f_amb_mat*(C_mat_apblhr + N_e*C_mat_engblhr))/V_bl;

% Direct Operating Cost for Maintenance
DOC_maint = C_lab_ap + C_lab_eng + C_mat_ap + C_mat_eng + C_amb;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DIRECT OPERATING COSTS FOR DEPRECIATION---------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Avionics Systems price per airplane
ASP = K_avionics*AMP_1999;								

% Cost of airplane depreciation
C_dap = F_dap*(AEP - N_e*EP - N_p*PP - ASP)/(DP_ap*U_ann_bl*V_bl);

% Cost of engine depreciation
C_deng = F_deng*N_e*EP/(DP_eng*U_ann_bl*V_bl);

% Cost of propellor depreciation
C_dprp = F_dprp*N_p*PP/(DP_prp*U_ann_bl*V_bl);

% Cost of avionics depreciation
C_dav = F_dav*ASP/(DP_av*U_ann_bl*V_bl); 

% Cost of spare parts depreciation
C_dapsp = F_dapsp*F_apsp*(AEP-N_e*EP)/(DP_apsp*U_ann_bl*V_bl);

% Cost of depreciation of engine spare parts
C_dengsp = F_dengsp*F_engsp*N_e*EP*ESPPF/(DP_engsp*U_ann_bl*V_bl);

% Direct Operating Cost for Depreciation
DOC_depr = C_dap + C_deng + C_dprp + C_dav + C_dapsp + C_dengsp;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% DIRECT OPERATING COSTS FOR LANDING, NAVIGATION, REGISTRY TAXES----------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Airplane landing fee per landing
C_aplf = 0.002*W_to;

% DOC for landing fees
C_lf = C_aplf/(V_bl*t_bl);

% Navigation fees
C_nf = C_apnf/(V_bl*t_bl);

f_rt = 0.001 + 1E-8*W_to;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Direct Operating Cost
DOC = (DOC_flt + DOC_maint + DOC_depr + C_lf + C_nf)/(1 - f_rt - 0.07);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Indirect Operating Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
IOC = f_ioc*DOC;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% Construct Pie Chart for Operating Cost Breakdown
DOC_lnr = C_lf + C_nf + (f_rt*DOC);
DOC_fin = 0.07*DOC;
OPS = [DOC_flt DOC_maint DOC_depr DOC_lnr DOC_fin IOC];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Program Operating Cost
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Program direct operating costs
C_ops_dir = DOC*R_bl_ann*N_yr;

% Program indirect operating costs
C_ops_ind = IOC*R_bl_ann*N_yr;

% Program Operating Cost
C_OPS = C_ops_dir*N_acq + C_ops_ind*N_acq;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% End of Operating Costs
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Life Cycle Costs (includes RDTE, ACQ, OPS, DISP)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
LCC = (C_rdte + C_acq + C_OPS)/(1-.01);

C_DISP = 0.01*LCC;
Cycle = [C_rdte C_acq C_OPS C_DISP];

if output == 1
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   % OUTPUTS
   %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   
   % RDTE Cost Breakdown
   fprintf('___________________________________________________________________________\n');
   fprintf('				RDTE PHASES\n')
   fprintf('___________________________________________________________________________\n\n');
	disp(sprintf('Airframe Engineering & Design:	$%8.0f',C_aed_r));
   disp(sprintf('Development Support & Testing:	$%8.0f',C_dst_r));
   disp(sprintf('Flight Test Airplanes:		$%8.0f',C_fta_r));   
   disp(sprintf('Flight Test Operations:		$%8.0f',C_fto_r));
   disp(sprintf('Test & Simulation Facilities:	$%8.0f',C_tsf_r));
   disp(sprintf('RDTE Profit:			$%8.0f',C_pro_r));
   disp(sprintf('RDTE Financing:			$%8.0f',C_fin_r));
   disp(sprintf('TOTAL RDTE COSTS:		$%8.0f',C_rdte));
   fprintf('___________________________________________________________________________\n\n');
   
   fprintf('___________________________________________________________________________\n');
   fprintf('			MANUFACTURING & AQUISITION PHASE\n')
   fprintf('___________________________________________________________________________\n\n');
	disp(sprintf('Airframe Engineering & Design:			$%8.0f',C_aed_m));
   disp(sprintf('Airplane Program Production:			$%8.0f',C_apc_m));
   disp(sprintf('Production Flight Test Operations:		$%8.0f',C_fto_m));
   disp(sprintf('Financing the Manufacturing Phase:		$%8.0f',C_fin_m));
   disp(sprintf('Profit Made by Manufacturer:			$%8.0f',C_pro));
   disp(sprintf('TOTAL MANUFACTURING & ACQUISITION COSTS:	$%8.0f',C_acq));
   fprintf('___________________________________________________________________________\n\n');   
   
   fprintf('___________________________________________________________________________\n');
   fprintf('				OPERATING COSTS\n')
   fprintf('___________________________________________________________________________\n\n');
	disp(sprintf('Flying:						$%8.0f',DOC_flt*R_bl_ann*N_yr*N_acq));
   disp(sprintf('Maintenance:					$%8.0f',DOC_maint*R_bl_ann*N_yr*N_acq));
   disp(sprintf('Depreciation:					$%8.0f',DOC_depr*R_bl_ann*N_yr*N_acq));
   disp(sprintf('Landing Fees, Navigation, and Registry Taxes:	$%8.0f',DOC_lnr*R_bl_ann*N_yr*N_acq));
   disp(sprintf('Financing:					$%8.0f',DOC_fin*R_bl_ann*N_yr*N_acq));
   disp(sprintf('Indirect Operating Costs:			$%8.0f',IOC*R_bl_ann*N_yr*N_acq));
   disp(sprintf('TOTAL OPERATING COSTS:				$%8.0f',C_OPS));
   fprintf('___________________________________________________________________________\n\n');
   
   
   fprintf('___________________________________________________________________________\n');
   fprintf('				LIFE CYCLE COSTS\n')
   fprintf('___________________________________________________________________________\n\n');
   disp(sprintf('RDTE Cost (US$):				$%8.0f',C_rdte));
	disp(sprintf('Manufacturing & Acquisition Cost (US$):	$%8.0f',C_acq));
   disp(sprintf('Operating Cost (US$):			$%8.0f',C_OPS));
   disp(sprintf('Direct Operating Cost (US$/nm):			$%3.2f',DOC));
   disp(sprintf('Indirect Operating Cost (US$/nm):			$%3.2f',IOC));
   disp(sprintf('Disposal Cost (US$):				$%8.0f',C_DISP));
   disp(sprintf('LIFE-CYCLE COST:				$%8.0f\n',LCC));
   fprintf('___________________________________________________________________________\n\n');
   
   disp(sprintf('Fuel Price ($/lb):		$%1.2f',FP));
   disp(sprintf('Engine Price:			$%8.0f',EP));
   disp(sprintf('Airplane Estimated Price:	$%8.0f',AEP));
   disp(sprintf('Airplane Market Price:		$%8.0f',AMP_1999));   
   
   figure(10)
	pie(OPS)
	t1 = sprintf('Operating Costs: %1.2f US$/nm',DOC+IOC);
	title(t1);
	legend('Flying','Maintenance','Depreciation',...
   	'Landing Fees, Navigation,Registry Taxes','Financing','Indirect');
   
   figure(11)
	pie(Cycle)
	legend('RDTE Phases','Acquisition','Operating Costs','Disposal');
   
end

