struggling with error in code
1 ビュー (過去 30 日間)
表示 古いコメント
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 件)
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:
- https://www.mathworks.com/matlabcentral/answers/77558-how-to-solve-this-error-operands-to-the-and-operators-must-be-convertible-to-logical-scalar-v
- https://www.mathworks.com/matlabcentral/answers/143576-operands-to-the-and-operators-must-be-convertible-to-logical-scalar-values
I hope the above suggestions will be helpful.
Thanks,
Jyotish
0 件のコメント
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
%%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
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!