Question: I have to use the source panel method to calculate the Cp about a given airfoil. I have done my best to follow my professors

I have to use the source panel method to calculate the Cp about a given airfoil. I have done my best to follow my professors instructions, but my Matlab code is giving me incorrect results. Can someone help me troubleshoot this code?
oad Original Airfoil Points
data = load('Airfoil_Data.mat');
x = data.unnamed(:,1);
y = data.unnamed(:,2);
V_0=1;
alpha = deg2rad([-5]);
Interpolate new points
ds = sqrt(diff(x).^2+ diff(y).^2);
s =[0; cumsum(ds)];
N =128;
s_new = linspace(0, s(end), N +1);
x_new = interp1(s, x, s_new, 'linear');
y_new = interp1(s, y, s_new, 'linear');
points=[x_new(:), y_new(:)];
figure;
plot(x, y,'-o', 'DisplayName', 'Original Airfoil');
hold on;
plot(x_new, y_new, '-x', 'DisplayName', 'Interpolated Airfoil');
legend;
xlabel('x');
ylabel('y');
title('Original and Interpolated Airfoil');
grid on;
axis equal;
Control Points
x_control = zeros(N,1);
y_control = zeros(N,1);
for i =1:N
next_point = mod(i, N)+1;
x_control(i)=(points(i,1)+ points(next_point, 1))/2;
y_control(i)=(points(i,2)+ points(next_point, 2))/2;
end
controlPoints =[x_control, y_control];
% Plot the airfoil and control points
figure;
plot(points(:,1), points(:,2),'-o', 'DisplayName', 'Airfoil'); % Airfoil points
hold on;
plot(controlPoints(:,1), controlPoints(:,2),'xr', 'DisplayName', 'Control Points'); % Control points
legend;
xlabel('x');
ylabel('y');
title('Airfoil and Control Points');
grid on;
axis equal;
Panel Lengths
deltaS = zeros(N,1);
for i =1:N
next_point = mod(i, N)+1;
dx = points(next_point, 1)- points(i,1);
dy = points(next_point, 2)- points(i,2);
deltaS(i)= sqrt(dx^2+dy^2);
end
Panel Angle w/ respect to x axis
theta = zeros(N,1);
for i =1:N
next_point = mod(i, N)+1;
dx = points(next_point, 1)- points(i,1);
dy = points(next_point, 2)- points(i,2);
theta(i)= atan2(dy, dx);
if theta(i)<0
theta(i)= theta(i)+2*pi;
end
end
Length from control point to control point
r = zeros(N, N);
for i =1:N
for j =1:N
dzeta = controlPoints(j,1)- controlPoints(i,1);
deta = controlPoints(j,2)- controlPoints(i,2);
r(i, j)= sqrt(dzeta^2+ deta^2);
end
end
Angle between control point i and j w/ respect to the x axis
phi = zeros(N, N);
for i =1:N
for j =1:N
dzeta = controlPoints(j,1)- controlPoints(i,1);
deta = controlPoints(j,2)- controlPoints(i,2);
phi(i, j)= atan2(deta, dzeta);
if phi(i, j)<0
phi(i, j)= phi(i, j)+2*pi;
end
end
end
Circulation and Normal influence coefficients
C = zeros(N, N);
C_bar = zeros(N, N);
for i =1:N
for j =1:N
if i ~= j
C(i, j)=(sin(theta(i)- phi(i, j))/(2* pi * r(i, j)))* deltaS(j);
C_bar(i, j)=(cos(theta(i)- phi(i, j))/(2* pi * r(i, j)))* deltaS(j);
else
C(i, j)=0;
C_bar(i, j)=0;
end
end
end
Source Strength
RHS = zeros(N,1);
for i =1:N
RHS(i)= V_0* sin(theta(i)- alpha);
end
A = zeros(N, N);
for i =1:N
for j =1:N
if i == j
A(i, j)=1/2;
else
A(i, j)= C(i, j);
end
end
end
q = A \ RHS;
Tangential Velocity
Vt = zeros(N,1);
for i =1:N
Vt(i)= V_0* cos(theta(i)- alpha);
for j =1:N
if i ~= j
Vt(i)= Vt(i)- q(j)* C_bar(i, j);
end
end
end
Pressure Coefficient
% Ensure Cp is computed
Cp =1-(Vt / V_0).^2; % Vectorized computation of Cp
% Plot Cp distribution
figure;
plot(controlPoints(:,1), Cp,'-o'); % Cp vs. x-coordinates of control points
xlabel('x (Chordwise Position)');
ylabel('C_p');
title('Pressure Coefficient Distribution');
grid on;

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Mechanical Engineering Questions!