필터 지우기
필터 지우기

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

조회 수: 34 (최근 30일)
Cedrick De Block
Cedrick De Block 2021년 11월 1일
답변: Cris LaPierre 2021년 11월 1일
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일
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.

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by