# struggling with error in code

1 ビュー (過去 30 日間)
Casper Stroem 2017 年 10 月 7 日

Hi all I am trying to run the code below and get an error i do not know what means.
clear all
close all
clc
Vo = linspace(5,25,41);
lambda = 7.5;
beta=(0:8:0.5);
r=27.46;
R = 30.56;
B = 3;
rho = 1.225;
omega = 2.0;
Vcutin = 5;
Vcutout = 25;
ratedP = 2500000;
alpha=4;
c=0.1:0.1:3;
%%Initializing Data
old_a = 0;
old_a_prime = 0;
a = 0;
a_prime = 0;
ac = 1/3;
corr = 0.1;
tolerance = 0.001;
%%BEM Iterations
while (((abs(old_a-a) > tolerance) || (abs(old_a_prime-a_prime) > tolerance)) || (a == 0))
old_a = a;
old_a_prime = a_prime;
phi = atan((1-a)*R/((1+a_prime)*lambda*r));
phideg = phi*180/pi;
theta=phideg-alpha;
Cl = 0.8;
Cd=0.012;
Cn = Cl*cos(phi) + Cd*sin(phi);
Ct = Cl*sin(phi) - Cd*cos(phi);
F_new=(2/pi)*acos(exp(-(B/2)*(R-r/r*sin(phi))));
sigma=c.*B/(2*pi*r); %solidity
%Tip loss correction
f = B*(R-r)/(2*r*sin(phi));
F = 2*acos(exp(-f))/pi;
%Glauert correction for high 'a' value
if(a > ac)
CT = (1-a)^2 * Cn*sigma/(sin(phi)^2);
a_star = a - (4*a*(1-0.25*(5-3*a)*a)-(CT/F))/(9*(a^2)-10*a+4);
a = corr*a_star + (1-corr)*a;
else
a = 1./((4*F*(sin(phi)^2)./(sigma'*Cn))+1);
end
a_prime = 1./((4*F*(sin(phi)^2)*cos(phi)./(sigma'*Ct))-1);
end
for i=0.1:0.1:3
Cp_local=(B*lambda^2*(r/R)*(1-a)*(1+a_prime)*(c(i)/R)*Ct/(2*pi*sind(phi)*cosd(phi)));
end
Operands to the || and && operators must be convertible to logical scalar values.
Error in question7 (line 28)
while (((abs(old_a-a) > tolerance) || (abs(old_a_prime-a_prime) > tolerance)) || (a == 0))
##### 2 件のコメント表示非表示 1 件の古いコメント
per isakson 2017 年 10 月 10 日
"struggling" Don't you use the debugging features? See Debug a MATLAB Program

サインインしてコメントする。

### 回答 (2 件)

Jyotish Robin 2017 年 10 月 10 日
Hi Casper!
This error is seen if the operands being evaluated by the short-circuit and && operators are empty or non-scalar arrays. Use the logical and (&), or (|) operators for non-scalar operands.
Refer to the link below for information on logical operators.
and, & :
or, | :
There are some ML Answers posts which discuss similar queries. You can have a look at the following:
I hope the above suggestions will be helpful.
Thanks,
Jyotish
##### 0 件のコメント表示非表示 -1 件の古いコメント

サインインしてコメントする。

VBBV 2021 年 12 月 26 日
clear all
close all
clc
Vo = linspace(5,25,41);
lambda = 7.5;
beta=(0:0.5:8);
r=27.46;
R = 30.56;
B = 3;
rho = 1.225;
omega = 2.0;
Vcutin = 5;
Vcutout = 25;
ratedP = 2500000;
alpha=4;
c=0.1:0.1:3
c = 1×30
0.1000 0.2000 0.3000 0.4000 0.5000 0.6000 0.7000 0.8000 0.9000 1.0000 1.1000 1.2000 1.3000 1.4000 1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000 2.2000 2.3000 2.4000 2.5000 2.6000 2.7000 2.8000 2.9000 3.0000
%%Initializing Data
old_a = 0;
old_a_prime = 0;
a = 0;
a_prime = 0;
ac = 1/3;
corr = 0.1;
tolerance = 0.001;
%%BEM Iterations
while (((abs(old_a-a) > tolerance) | (abs(old_a_prime-a_prime) > tolerance)) | (a == 0))
old_a = a;
old_a_prime = a_prime;
phi = atan((1-a)*R./((1+a_prime).*lambda*r));
phideg = phi*180/pi;
theta=phideg-alpha;
Cl = 0.8;
Cd=0.012;
Cn = Cl*cos(phi) + Cd*sin(phi);
Ct = Cl*sin(phi) - Cd*cos(phi);
F_new=(2/pi)*acos(exp(-(B/2)*(R-r/r*sin(phi))));
sigma=c.*B/(2*pi*r); %solidity
%Tip loss correction
f = B*(R-r)/(2*r*sin(phi));
F = 2*acos(exp(-f))/pi;
%Glauert correction for high 'a' value
if(a > ac)
CT = (1-a)^2 * Cn*sigma./(sin(phi).^2);
a_star = a - (4*a*(1-0.25*(5-3*a)*a)-(CT./F))./(9*(a^2)-10*a+4);
a = corr*a_star + (1-corr)*a;
else
a = 1./((4*F.*(sin(phi).^2)./(sigma'.*Cn))+1);
end
a_prime = 1./((4*F.*(sin(phi).^2).*cos(phi)./(sigma.'.*Ct))-1);
end
for i=1:length(c)
Cp_local(:,:,i)=(B*lambda^2*(r/R)*(1-a).*(1+a_prime).*(c(i)/R).*Ct./(2*pi*sind(phi).*cosd(phi)));
plot(Cp_local(:,:,i),'-b'); xlabel('axial induction ');ylabel('Cp_local')
hold on
end

サインインしてコメントする。

### Community Treasure Hunt

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

Start Hunting!

Translated by