Here is the attached code.
I would appreciate if anyone could tell me exactly what is wrong with the code and what changes I need to make to the syntax to make it run.
The error according to MATLAB:
Index exceeds matrix dimensions.
Error in NACA_23012 (line 59)
xu(i)=x(i)-yt(i)*sin(theta(i));
%this is a MATLAB program written by Akintunde Akinneye to draw the plot
%of a NACA 23012 airfoil for a university undergraduate project
clear all;clc;%% coder inputs
%airfoil type
typeNACA='23012';% extrapolate values from the airfoil type using string
Linit=str2double(typeNACA(1));Pinit=str2double(typeNACA(2));Sinit=str2double(typeNACA(3));Tinit=str2double(typeNACA(4:5));%number of grid points
gridPts=500;%constants
a0= 0.2969;a1=-0.1260;a2=-0.3516;a3= 0.2843;a4=-0.1015; % For finite thick TE
%a4=-0.1036;For zero thick TE
%% computations
% Percentage of airfoil properties in NACA number
m=0.2025;k1=15.957;T=Tinit/100;%airfoil grid
x=linspace(0,1,gridPts)';%camber and gradients
yc=ones(gridPts,1);dyc_dx = ones(gridPts,1);theta = ones(gridPts,1);for i=1:1:gridPts if(x(i)>=0 && x(i)< m) yc(i)=(k1/6)*(x(i)^3-3*m*x(i)^2+m^2*(3-m)*x(i)); dyc_dx(i)= (k1/6)*(3*x(i)^2-6*m*x(i)+ m^2*(3-m)); elseif (x(i)>=m && x(i) <=1) yc(i)=((k1*m^3)/6) *(1-x(i)); dyc_dx(i)= ((k1*m^3)/6); end theta(i)=atan(dyc_dx(i));end%thickness distro
yt=ones(gridPts,1);for i=1:1:gridPts t0=a0*sqrt(x(i)); t1=a1*x(i); t2=a2*x(i)^2; t3=a3*x(i)^3; t4=a4*x(i)^4; yt=5*T*(t0+t1+t2+t3+t4);end%upper surface grid
xu=ones(gridPts,1);yu=ones(gridPts,1);for i=1:1:gridPts xu(i)=x(i)-yt(i)*sin(theta(i)); yu(i)=yc(i)+yt(i)*cos(theta(i));end %lower surface grid
xl=ones(gridPts,1);yl=ones(gridPts,1);for i=1:1:gridPts xl(i)=x(i)+yt(i)*sin(theta(i));yl(i)=yc(i)-yt(i)*cos(theta(i));end%plot the airfoil shape (with lines)
f1=figure(1);hold on; grid on;axis equal;plot(xu,yu,'r-');plot(xl,yl,'k-');
Best Answer