%ascorrea

function dragpolar
count=1;
cd0=input('Input cd0: ');
cl_alfa=input('Input cL_alfa(1/rad): ');
cL0=input('Input cL0: ');
sweep_LE=input('Input leading edge sweep (deg): ');
ar=input('Input aspect ratio: ');
cd_correction=input('Input Cd correction due to Transonic: ');
alphadeg=[-12:2];
alpha=(pi/180)*(alphadeg);

cL_alfa=cl_alfa*(ar/(ar+(2*(ar+4)/(ar+2))));

        for i=1:length(alpha)
        C_L(i)=cL_alfa*(alpha(i))+cL0;
        e=4.61*(1-.045*ar^.68)*cosd(sweep_LE)^.15-3.1;
        cd_i(i)=C_L(i)^2/(pi*ar*e);
        C_d(i)=cd0+cd_i(i)+cd_correction;
        end
        
        graphname='Drag Polar';

hold on
figure(count)
hold on
axisX0=linspace(0,max(cd));
axisY0=zeros(1,length(axisX0));
figure(count)
hold on
plot(axisX0, axisY0,'k--');
figure(count)
hold on
plot(C_d, C_L);
figure(count)
hold on
plot(C_d, C_L, '.');
title(graphname);
xlabel('C_d');
ylabel('C_L');
axis([0, .08, -1, 1.5]);
for i=1:length(alphadeg)
    alphalabel=num2str(alphadeg(i));
    label=['  \alpha =' alphalabel];
text(C_d(i), C_L(i), label)
end
count=count+1;