% AIAA Design Project
% Optimization Code

% Jennifer Owens
% Last Update: May 1, 1999

clc
clear all;
close all;
flops(0);

tic

% _____________________________________________________________________
% List All Design Variables
% _____________________________________________________________________

% WING GEOMETRY:
% b_wing, Span (ft)
% S_ref, Reference Area (ft^2)
% taper_wing, Taper ratio 
% sweep_wing_25c, Quarter-chord sweep angle  (deg)
% tc_avg_wing, Average Thickness-to-chord ratio
% x_wing, Distance from nose to leading edge (along x-axis) (ft)
% flap_to_chord, Flap chord ratio
% eta_i_flap, Flap inboard station
% eta_o_flap, Flap outboard station
% flap_angle_to, Flap angle for takeoff (deg)
% flap_angle_cr, Flap angle for cruise (deg)
% flap_angle_land, Flap angle for landing (deg)
% slat_angle_to, Slat angle for takeoff (deg)
% slat_angle_cr, Slat angle for cruise (deg)
% slat_angle_land, Slat angle for landing (deg)

% HORIZONTAL TAIL GEOMETRY:
% b_ht, Span (ft)
% Sht_ref, Reference Area (ft^2)
% taper_ht, Taper ratio
% sweep_ht_25c, Quarter-chord sweep angle
% tc_avg_ht, Average Thickness-to-chord ratio
% x_ht, Distance from nose to leading edge (along x-axis) (ft)

% VERTICAL TAIL:
% b_vt, Span (ft)
% Svt_ref, Reference Area (ft^2)
% taper_vt, Taper ratio
% sweep_vt_25c, Quarter-chord sweep angle
% tc_avg_vt, Average Thickness-to-chord ratio
% x_vt = 50, Distance from nose to leading edge (along x-axis) (ft)

% MISSION PROFILE:
% h = 30000, Cruise altitude (ft)
% V = 350, Cruise speed, (in knots)

% OVERALL GEOMETRY
% L_total, Length of aircraft (ft)
% W_total, Width of aircraft (ft)
% H_total, Height of aircraft (ft)

% PERFORMANCE
% R_bl, Block Range (nm)
% S_g_to, Takeoff groundroll (ft)
% S_g_land, Landing groundroll (ft)

% STABILITY & CONTROL
% cg_max, Maximum CG excursion (in % of mac)
% SM_min, Minimum Static Margin (in % of mac)
% Sht_reqd, Minimum horizontal tail area required for takeoff rotation (ft^2)
% V_mc, Minimum control speed (ft/sec)

% PROPULSION:
% T_to_uninst, Takeoff uninstalled thrust (lb)
% P_to_uninst, Takeoff uninstalled power (hp)
% y_eng, Distance from centerline to outboard engine (ft)
% L_eng, Engine Length (ft)
% D_eng, Engine Diameter (ft)
% N_e, Number of Engines

% LANDING GEAR GEOMETRY:
% x_nosegear, Distance from nose to nose gear (ft)
% x_maingear, Distance from nose to main gear (ft)
% y_maingear, Distance from centerline to main gear (ft)
% toff_angle_deg, Tipover angle (deg) 
% tov_angle_deg, Turnover angle (deg)
% upsw_angle_deg, Fuselage clearance angle (deg)
% pctwt_nose, Percent weight on nose

% WEIGHTS:
% W_to, Takeoff Weight (lb)
% W_payload, Payload Weight (lb)
% W_e, Empty Weight (lb)

% _____________________________________________________________________


% _____________________________________________________________________
% Define Initial Guesses
% _____________________________________________________________________


S_ref = 1150;
x_wing = 15;
flap_angle_to = 10;
Sht_ref = 225;
Svt_ref = 275;
T_to_uninst = 25000;
x_maingear = 25;
W_to = 50000;
W_e = 25000;
h = 35000;
V = 350;


% Put Initial Values into a vector
x0 = [S_ref,x_wing,flap_angle_to,Sht_ref,Svt_ref,T_to_uninst,x_maingear,W_to,W_e,h,V];

% Options
options(14) = 1000;

% Lower bounds
xlb = [500, 10, 0, 50, 50, 15000, 10, 35000, 15000, 20000, 350];

% Upper bounds
xub = [2000, 35, 15, 500, 500, 70000, 35, 60000, 30000, 45000, 500];

% Run the constrained optimization routine
x = constr('optimize_fixedwing',x0,options,xlb,xub)

toc
flops