Matlab error: ??? Error using ==> interp1 at 259 The values of X should be distinct.
3 views (last 30 days)
Show older comments
I'm trying to find the values of z that correspond to the x values in xib but I keep getting this error and I don't know what it means. I am not very good at programming so please answer in layman's terms as much as possible. Below is my code:
clear
clc
%Part 1: Airfoil Geometry
%Plot x vs. z for a 15% thick airfoil
e = 0.04725;
a = 0.563;
k = 1.889;
theta = 0:1:360;
r1 = sqrt((a*cosd(theta)-a).^2+(a*sind(theta)).^2);
r2 = sqrt((a*cosd(theta)-e*a).^2+(a*sind(theta)).^2);
b = size(theta);
p = a*cosd(theta)-a;
theta1 = atan(a*sind(theta)./(p))+pi;
for d = 1:b(2)
c = a*cosd(theta(d))-e*a;
if c > 0 && theta(d) < 100
n1 = 0;
elseif c < 0
n1 = 1;
else n1 = 2;
end
theta2(d) = atan(a*sind(theta(d))./(a*cosd(theta(d))-e*a))+n1*pi;
end
x = ((r1.^k)./(r2.^(k-1))).*(cos(k*theta1).*(cos((k-1)*(theta2)))+sin(k*theta1).*(sin((k-1)*theta2)))+1;
z = ((r1.^k)./(r2.^(k-1))).*(sin(k*theta1).*(cos((k-1)*(theta2)))-cos(k*theta1).*(sin((k-1)*theta2)));
figure(1), plot(x,z), grid
axis equal;
title('Airfoil Geometry at 15% Thickness'), xlabel('X'), ylabel('Z')
%Part 2: Airfoil Pressure Distribution
alpha = 0;
A = cos((k-1)*theta1).*cos(k*theta2)+sin((k-1)*theta1).*sin(k*theta2);
B = sin((k-1)*theta1).*cos(k*theta2)-cos((k-1)*theta1).*sin(k*theta2);
D0 = a*(1-k+k*e);
D1 = A.*(a*cosd(theta)-D0)-B*a.*sind(theta);
D2 = A.*(a*sind(theta))+B.*(a*cosd(theta)-D0);
u = 2*((r2.^k)./(r1.^(k-1))).*(sind(alpha)-sind(alpha-theta))./(D1.^2+D2.^2).*(D1.*sind(theta)+D2.*cosd(theta));
w = -2*((r2.^k)./(r1.^(k-1))).*(sind(alpha)-sind(alpha-theta))./(D1.^2+D2.^2).*(D1.*cosd(theta)-D2.*sind(theta));
Cp = 1-(u.^2+w.^2);
figure(2), plot(x,Cp), grid
axis equal;
title('Airfoil Pressure Distribution on a 15% Thick Airfoil at Zero AOA')
xlabel('X'), ylabel('Cp(X)')
%Part 3: Discretizing the Airfoil Geometry and Linear Interpolation
N = 11;
dx = 4/N;
xib = 1:-dx:-1;
r = size(xib);
xit = xib(r(2)):dx:1;
xi = horzcat(xib, xit);
X = x(1,361:-1:180);
X(1)=1;
Z = z(1,361:-1:180);
Z(1)=0;
zi = interp1(X,Z,xib);
0 Comments
Answers (1)
Wayne King
on 4 Mar 2013
The problem is your last X value is -1.0012, which is repeated from the 3rd to the last
X(end-2:end)
So note that
zi = interp1(X(1:end-1),Z(1:end-1),xib);
Does not error.
See Also
Categories
Find more on Airfoil tools in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!