why do I get the error "Error using atan2 Inputs must be real"

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

답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 11월 1일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

질문:

2021년 11월 1일

답변:

2021년 11월 1일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by