Read a file, store in variable.
2 次查看(过去 30 天)
显示 更早的评论
This is the program I'm trying to create (very new to Matlab). I have the main program that is using airfoil geometry to calculate pressure distribution and use the pressure distribution later on in other equations.
So far: I have generated equation for NACA 4 and 5 series airfoil based on the input series number from the user. However, I want another option to have user generate their own x and y coordinates of the airfoil and I need to be able to use those values in the program.
function [xs]=FSP()
%closes all windows, clears everything
writeofile=0;
fprintf('\n');
fprintf('Enter option: 1= 4 series, 2=5 series 3= upload');
if ~nargin
option = input ('\n select option:');
if option ==1
FourDigit=input('\n Type in NACA 4 series: ');
alpha = input ('\n Type in angle of attack in degree: ');
elseif option ==2
FiveDigit= input('\n Type in NACA 5 series: ');
alpha = input ('\n Type in angle of attack in degree: ');
elseif option ==3
%
%
end
end
N=100; % Number of points generated.
if option == 1
[x,y]= Airfoil4 (N,N,FourDigit);
% [xmid,ymid,Cp]=HessSmithPanel (x,y,alpha);
% [xU,yU,CpU]=UpperSurface (xmid,ymid,Cp,N);
elseif option ==2
[x,y]= Airfoil5 (N,N,FiveDigit);
% [xmid,ymid,Cp]=HessSmithPanel (x,y,alpha);
% [xU,yU,CpU]=UpperSurface (xmid,ymid,Cp,N);
elseif option ==3
end
figure
plot (x,y);
axis([-.1 1.1 -.4 .4]);
That is part of the main program that is currently working for 4 and 5 series, it gets the x and y coordinates in an array and plots them for future usage. I need the third option of data collection working similar to that.
This is an example of NACA 5 series
function [x,y]=Airfoil5(nU,nL,NACA)
xU=zeros(nU,1);
cU=zeros(nU,1);
dcU=zeros(nU,1);
betaU=zeros(nU,1);
xL=zeros(nL,1);
cL=zeros(nL,1);
dcL=zeros(nL,1);
betaL=zeros(nL,1);
L=floor(NACA/10000);
P=floor(NACA/1000)-L*100;
R=floor(NACA/100)-L*100-P*10;
XX=NACA-L*10000-P*1000-R*100;
maxt=XX/100;
xf=P/20;
Cli=3*L/20;
%cmax=cmax*.01;
%pcmax=pcmax*.1;
%maxt=maxt*.01;
syms m;
sol=solve(xf==m*(1-sqrt(m/3)),m);
m = double(real(sol(2)));
Q=(3*m-7*m^2+8*m^3-4*m^4)/sqrt(m*(1-m))-3/2*(1-2*m)*(pi/2-asin(1-2*m));
k1=6*Cli/Q;
if R == 0
for i=1:nU
xU(i)=.5*(1-cos(pi*(i-1)/nU));
end
for i=1:nL
xL(i)=.5*(1+cos(pi*(i-1)/nL));
end
tU=5*maxt*(.2969*sqrt(xU)-xU.*(.126+xU.*(.35372-xU.*(.2843-xU*.1015))));
tL=5*maxt*(.2969*sqrt(xL)-xL.*(.126+xL.*(.35372-xL.*(.2843-xL*.1015))));
for i=1:nU
if xU(i)<m
cU(i)=(k1/6)*(xU(i)*xU(i)*xU(i)-3*m*xU(i)*xU(i)+m^2*(3-m)*xU(i));
dcU(i)=(k1/6)*(3*xU(i)*xU(i)-6*m*xU(i)+m^2*(3-m));
else
cU(i)=k1*m^3*(1-xU(i))/6;
dcU(i)=-k1*m^3/6;
end
betaU=atan(dcU);
end
for i=1:nL
if xL(i)<m
cL(i)=(k1/6)*(xL(i)*xL(i)*xL(i)-3*m*xL(i)*xL(i)+m^2*(3-m)*xL(i));
dcL(i)=(k1/6)*(3*xL(i)*xL(i)-6*m*xL(i)+m^2*(3-m));
else
cL(i)=k1*m^3*(1-xL(i))/6;
dcL(i)=-k1*m^3/6;
end
betaL=atan(dcL);
end
else
k2=(3*(0.217-.15)^2-0.217^3)/(1-0.217)^3;
for i=1:nU
xU(i)=.5*(1-cos(pi*(i-1)/nU));
end
for i=1:nL
xL(i)=.5*(1+cos(pi*(i-1)/nL));
end
tU=5*maxt*(.2969*sqrt(xU)-xU.*(.126+xU.*(.35372-xU.*(.2843-xU*.1015))));
tL=5*maxt*(.2969*sqrt(xL)-xL.*(.126+xL.*(.35372-xL.*(.2843-xL*.1015))));
for i=1:nU
if xU(i)<m
cU(i)=(k1/6)*((xU(i)-m)^3-k2*(1-m)^3*xU(i)-m^3*xU(i)+m^3);
dcU(i)=(k1/6)*(3*(xU(i)-m)^2-k2*(1-m)^3-m^3);
else
cU(i)=(k1/6)*(k2*(xU(i)-m)^3-k2*(1-m)^3*xU(i)-m^3*xU(i)+m^3);
dcU(i)=(k1/6)*(3*k2*(xU(i)-m)^2-k2*(1-m)^3-m^3);
end
betaU=atan(dcU);
end
for i=1:nL
if xL(i)<m
cL(i)=(k1/6)*((xL(i)-m)^3-k2*(1-m)^3*xL(i)-m^3*xL(i)+m^3);
dcL(i)=(k1/6)*(3*(xL(i)-m)^2-k2*(1-m)^3-m^3);
else
cL(i)=(k1/6)*(k2*(xL(i)-m)^3-k2*(1-m)^3*xL(i)-m^3*xL(i)+m^3);
dcL(i)=(k1/6)*(3*k2*(xL(i)-m)^2-k2*(1-m)^3-m^3);
end
betaL=atan(dcL);
end
end
x=xL+tL.*sin(betaL);
y=cL-tL.*cos(betaL);
x=[x;xU-tU.*sin(betaU);x(1)];
y=[y;cU+tU.*cos(betaU);y(1)];
So I need the third option to develop similarly like NACA 5 series and store the data from the text file into the variable x and y.
Here is the text file.
AG19
0.999992 0.000244
0.994067 0.000848
0.982082 0.002113
0.968544 0.003504
0.954708 0.004914
0.940826 0.006276
0.926943 0.007613
0.913056 0.008933
0.899168 0.010245
0.885282 0.011547
0.871396 0.012840
0.857515 0.014123
0.843633 0.015399
0.829754 0.016658
0.815876 0.017909
0.801995 0.019144
0.788118 0.020364
0.774240 0.021567
0.760358 0.022757
0.746480 0.023934
0.732598 0.025098
0.718714 0.026246
0.704832 0.027382
0.690952 0.028505
0.677070 0.029611
0.663191 0.030702
0.649316 0.031769
0.635436 0.032803
0.621559 0.033813
0.607686 0.034792
0.593811 0.035742
0.579936 0.036661
0.566066 0.037549
0.552198 0.038403
0.538328 0.039225
0.524462 0.040010
0.510601 0.040760
0.496741 0.041474
0.482880 0.042149
0.469025 0.042788
0.455177 0.043387
0.441328 0.043948
0.427484 0.044466
0.413649 0.044946
0.399815 0.045383
0.385986 0.045776
0.372169 0.046125
0.358355 0.046428
0.344545 0.046682
0.330750 0.046887
0.316965 0.047037
0.303185 0.047134
0.289421 0.047171
0.275674 0.047146
0.261933 0.047054
0.248213 0.046888
0.234514 0.046643
0.220830 0.046310
0.207177 0.045881
0.193554 0.045344
0.179962 0.044689
0.166424 0.043904
0.152931 0.042974
0.139504 0.041884
0.126159 0.040617
0.112901 0.039151
0.099774 0.037462
0.086793 0.035521
0.074020 0.033292
0.061500 0.030726
0.049351 0.027778
0.037754 0.024395
0.027090 0.020576
0.018069 0.016536
0.011377 0.012750
0.006933 0.009581
0.004065 0.007011
0.002186 0.004880
0.000960 0.003044
0.000235 0.001406
0.000001 -0.000094
0.000368 -0.001552
0.001471 -0.002908
0.003259 -0.004084
0.005777 -0.005206
0.009368 -0.006368
0.014713 -0.007619
0.022632 -0.008896
0.033028 -0.009988
0.044948 -0.010773
0.057612 -0.011265
0.070626 -0.011515
0.083847 -0.011575
0.097208 -0.011488
0.110664 -0.011286
0.124193 -0.010995
0.137773 -0.010634
0.151402 -0.010216
0.165062 -0.009753
0.178754 -0.009253
0.192471 -0.008724
0.206209 -0.008174
0.219965 -0.007607
0.233740 -0.007028
0.247527 -0.006440
0.261333 -0.005847
0.275149 -0.005250
0.288979 -0.004652
0.302827 -0.004054
0.316687 -0.003459
0.330560 -0.002868
0.344449 -0.002282
0.358351 -0.001705
0.372267 -0.001137
0.386195 -0.000582
0.400136 -0.000039
0.414079 0.000487
0.428014 0.000997
0.441936 0.001488
0.455848 0.001958
0.469754 0.002410
0.483648 0.002838
0.497536 0.003246
0.511417 0.003632
0.525297 0.003999
0.539171 0.004338
0.553041 0.004649
0.566907 0.004932
0.580771 0.005183
0.594629 0.005404
0.608483 0.005597
0.622333 0.005758
0.636177 0.005888
0.650015 0.005989
0.663852 0.006060
0.677688 0.006098
0.691521 0.006104
0.705354 0.006082
0.719189 0.006029
0.733027 0.005945
0.746863 0.005833
0.760702 0.005691
0.774544 0.005518
0.788385 0.005316
0.802230 0.005089
0.816081 0.004833
0.829932 0.004550
0.843784 0.004242
0.857640 0.003908
0.871495 0.003551
0.885353 0.003171
0.899212 0.002768
0.913070 0.002347
0.926931 0.001903
0.940790 0.001439
0.954652 0.000956
0.968488 0.000451
0.982076 -0.000064
0.994074 -0.000511
1.000008 -0.000710
The text file generally contains the name of the airfoil and then the columns of x coordinate and y coordinate. I need to be able to take each of this coordinate and save them in the x and y variable like I have it in the airfoil5 function. I also need to have the N variable in the FSP funcction to be changed to the number of x-y coordinates that are coming in from the airfoil text file.
Any help would be greatly appreciated, Thank you.
0 个评论
回答(1 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Airfoil tools 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!