Professional Documents
Culture Documents
%Initialize variables
A=zeros(1,3);
x=zeros(1,0);
y=zeros(1,0);
p=0;
coeffor=ones(1,4);
coefback=ones(1,4);
switch method
case 1
%Four digit airfoil method
FourDigit=input('\nType in NACA 4 digit airfoil number.\n?');
alpha=input('\nType in an angle of attack in degrees.\n?');
alpha=alpha*pi/180;
m=floor(FourDigit/1000)*1000;
p=floor(FourDigit/100)*100-m;
m=m/100000;
p=p/1000;
[TempA0,TempA1,TempA2,Tempx,Tempy]=FindA(0,-m/p^2,2*m/p,0,0,p);
A=A+[TempA0,TempA1,TempA2];
x=[x,Tempx];
y=[y,Tempy];
[TempA0,TempA1,TempA2,Tempx,Tempy]=FindA(0,-m/(1-p)^2,2*m*p/(1-
p)^2,(m-2*m*p)/(1-p)^2,p,1);
A=A+[TempA0,TempA1,TempA2];
x=[x,Tempx];
y=[y,Tempy];
case 2
%Two cubic equations of an airfoil
while
(coeffor(1)*p^3+coeffor(2)*p^2+coeffor(3)*p)~=(coefback(1)*p^3+coefback(2)*p^2+coef
back(3)*p+coefback(4)) | dot(coefback,ones(1,4))~=0
coeffor=input('\nType in coefficients for the forward
camber of the airfoil.\n ax^3 + bx^2 + cx\n ex.[0 1 2] = x^2 + 2x\n?');
p=input('\nEnter the point fraction of the chord where the
forward camber ends and the back camber begins.\nIf only one equation is used type
1.\n?');
if p~=1
coefback=input('\nType in coefficients for the back
camber of the airfoil.\n ax^3 + bx^2 + cx + d\n ex.[0 1 2 3] = x^2 + 2x + 3\n?');
end
if
(coeffor(1)*p^3+coeffor(2)*p^2+coeffor(3)*p)~=(coefback(1)*p^3+coefback(2)*p^2+coef
back(3)*p+coefback(4)) | dot(coefback,ones(1,4))~=0
disp('');
disp('Equations must connect and the y coordinate is
0 at x/c=1.');
end
end
[TempA0,TempA1,TempA2,Tempx,Tempy]=FindA(coeffor(1),coeffor(2),coeffor(3),0,0,p);
A=A+[TempA0,TempA1,TempA2];
x=[x,Tempx];
y=[y,Tempy];
[TempA0,TempA1,TempA2,Tempx,Tempy]=FindA(coefback(1),coefback(2),coefback(3),coefba
ck(4),p,1);
A=A+[TempA0,TempA1,TempA2];
x=[x,Tempx];
y=[y,Tempy];
case 3
x=[0 0];
y=[0 0];
while x(1)~=0 | y(1)~=0 | x(length(x))~=1 | y(length(y))~=0
x=input('\nPlease enter the x coordinates of the camber
line.\n ex.[0 .25 .5 .75 1]\n?');
y=input('\nPlease enter the y coordinates of the camber
line.\n ex.[0 .05 .1 .05 0]\n?');
if x(1)~=0 | y(1)~=0 | x(length(x))~=1 | y(length(y))~=0
disp('');
disp('Coordinates must begin at (0,0) and end at
(1,0) for this theory.');
end
end
for i=1:length(x)-1
m=(y(i+1)-y(i))/(x(i+1)-x(i));
b=-x(i)*m+y(i);
[TempA0,TempA1,TempA2]=FindA(0,0,m,b,x(i),x(i+1));
A=A+[TempA0,TempA1,TempA2];
end
end
%Plot camber line and arrow to show free stream angle of attack
plot(x,y);
hold on;
axis([-.5,1.5,-.1,.1]);
e=pi/18;
plot([-0.1,-0.1-0.3*cos(alpha)],[0,-0.15*sin(alpha)],'k')
plot([-0.1,-0.1-0.05*cos(e-alpha)],[0,0.025*sin(e-alpha)],'k')
plot([-0.1,-0.1-0.05*cos(e+alpha)],[0,-0.025*sin(e+alpha)],'k')
hold off;
%**********************************************************
function [A0,A1,A2,x,y]=FindA(a,b,c,d,x1,x2)
x=x1:(x2-x1)/20:x2;
y=a*x.*x.*x+b*x.*x+c*x+d;
%Conversion to theta coordinates
theta1=acos(1-2*x1);
theta2=acos(1-2*x2);