function []=monopln()
%This program computes 3-D using lifting line theory
%around a wing.

writetofile=0;
disp('Input all angles in degrees.');
b=input('Please input wing span.\n?');
cr=input('Please input root chord.\n?');
ct=input('Please input tip chord.\n?');
s=(cr+ct)*b/2;
ar=b^2/s;
tw=input('Please input tip twist relative to root (nose up is positive).\n?');
a=input('Please input the airfoil section lift curve slope(per radian).\n?');
al0=input('Please input the airfoil section zero lift angle.\n?');
alr=input('Please input the root section incidence.\n?');
n=input('Please input the number of points to solve for along the span.\n?');

if input('\nWould you like to print the information to a file?(y,n)\n?','s')=='y'
	filename=input('Enter a file name.\n?','s');
	filename=strcat(filename,'.dat');
	fid=fopen(filename,'w');
   writetofile=1;
end

odd=1:2:2*n-1;odd=odd';
phi=pi/(2*n):pi/(2*n):pi/2;phi=phi';
al=(alr+tw*cos(phi)-al0)*pi/180;
ch=cr-(cr-ct)*cos(phi);
bn=ch.*al.*sin(phi)*a/(4*b);
for j=1:n
   A(:,j)=sin(odd(j)*phi).*(sin(phi)+odd(j)*ch*a/(4*b));
end
x=inv(A)*bn;
Cl=pi*ar*x(1);
Cdi=odd'*(x.*x)*pi/ar;
EL_Cdi=Cl^2/(pi*ar);

m=10;
lc=zeros(m,1);
phi2=(0:(pi/2)/(m-1):pi/2)';
odd2=(1:2:2*n-1)';
lc=x'*sin(odd2*phi2');
lc=4*b*lc'./(cr-(cr-ct).*cos(phi2));

disp('    Monoplane Equation Results');
disp(sprintf('Aspect Ratio   =%2d',ar));
disp(sprintf('Taper Ratio    =%2d',ct/cr));
disp(sprintf('Root Incidence =%2d',alr));
disp(sprintf('Washout        =%2d\n',-tw));
disp('    phi Cl(local)  cos(phi)  Cl(local)/Cl(wing)');
disp('    --- ---------  --------  ------------------');
for i=1:length(phi2)
	disp(sprintf('    %2d  %8.5f  %8.5f  %8.5f',floor(phi2(i)*180/pi),lc(i),cos(phi2(i)),lc(i)/Cl));
end
disp(['                   Cl  =',num2str(Cl)]);
disp(['                   Cdi =',num2str(Cdi)]);
disp(['Elliptical Loading Cdi =',num2str(EL_Cdi)]);
if writetofile
	fprintf(fid,'    Monoplane Equation Results\n');
	fprintf(fid,'Aspect Ratio   =%2d\n',ar);
	fprintf(fid,'Taper Ratio    =%2d\n',ct/cr);
	fprintf(fid,'Root Incidence =%2d\n',alr);
	fprintf(fid,'Washout        =%2d\n\n',-tw);
	fprintf(fid,'    phi Cl(local)  cos(phi)  Cl(local)/Cl(wing)\n');
	fprintf(fid,'    --- ---------  --------  ------------------\n');
	for i=1:length(phi2)
		fprintf(fid,'    %2d  %8.5f  %8.5f  %8.5f\n',floor(phi2(i)*180/pi),lc(i),cos(phi2(i)),lc(i)/Cl);
	end
	fprintf(fid,'                   Cl  = %10.7f\n',Cl);
	fprintf(fid,'                   Cdi = %10.7f\n',Cdi);
	fprintf(fid,'Elliptical Loading Cdi = %10.7f\n',EL_Cdi);
	fclose(fid);
	disp(['Created filename',blanks(1),filename]);
end
