why do I get the error "Error using atan2 Inputs must be real"
34 views (last 30 days)
Show older comments
c = 1;
tau = 0.12;
Npanel = 200;
for i = 1:Npanel/2+1
eta(i) = pi*(i-1)/(Npanel/2) ;
x(i) = c*(cos(eta(i)+1)/2);
end
x = sort(x) ;
T = 10*tau*c*(0.2969*sqrt(x/c)-0.126*(x/c)-0.3537.*(x/c).^2+0.2843*(x/c).^3-0.1015*(x/c).^4);
X_u = x - T/2.*sin(atan(0)) ;
X_l = x + T/2.*sin(atan(0)) ;
Y_u = Y_bar + T/2.*cos(atan(0));
Y_l = Y_bar -T/2.*cos(atan(0));
X_u(1) = [] ;
Y_u(1) = [] ;
X = [fliplr(X_l) X_u];
Y = [fliplr(Y_l) Y_u];
for i=1:Npanel
X_bar(i) = (X(i+1)+X(i))/2;
Y_bar(i) = (Y(i+1)+Y(i))/2;
theta(i) = atan2((Y(i+1)-Y(i)),(X(i+1)-X(i)));
l(i,1) = sqrt((X(i+1)-X(i)).^2 + (Y(i+1)-Y(i)).^2);
end
0 Comments
Answers (1)
Cris LaPierre
on 1 Nov 2021
As the error states, you are trying to use atan2 on complex data, which is not allowed.
The issue starts with how x is calculated. I had to make up a value for Y_bar, but the resulting values were all negative. Then, in your calculating T, you take the sqrt of x. The sqrt of a negative number results in a complex number.
I'm not sure what you want, but function like abs, real, and imag may help you out.
0 Comments
See Also
Categories
Find more on File Operations 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!