struggling with error in code

2 ビュー (過去 30 日間)
Casper Stroem
Casper Stroem 2017 年 10 月 7 日
編集済み: per isakson 2017 年 10 月 10 日
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 件のコメント
per isakson
per isakson 2017 年 10 月 10 日
編集済み: per isakson 2017 年 10 月 10 日
Your code make me think that all the variables in the logical expressions in while expression are supposed to be scalars.
However,
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
turns a into a vector, which in turn causes the error.
per isakson
per isakson 2017 年 10 月 10 日
編集済み: per isakson 2017 年 10 月 10 日
"struggling" Don't you use the debugging features? See Debug a MATLAB Program

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

回答 (1 件)

Jyotish Robin
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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by