Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-1

1 view (last 30 days)
I am stack to this error anyone can help me please:
"Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 0-by-1.
Error in Achievement (line 89)
[fi(j,i),W(j,i),f(j,i),F(j,i),beta(j,i),CL(j,i),CD(j,i),a1(j,i),Re_new(j,i),chord_dim(j,i),sigma(j,i)]
= ..."
The problems I think is in the definition of this function:
function [fi,W,f,F,beta,CL,CD,a1,Re_new,chord_dim,sigma] = iteration(a,a1,V0,omega,r,r_dim,Re,rho,mu,Nb,R,root,primary,tip,profile_rt,profile_p,profile_t,beta_c_opt)
fi=atan(((1-a)*V0)./((1+a1).*omega.*r_dim));
W=((1-a).*V0)./sin(fi);
f=Nb*(R-r_dim)./(2*r_dim.*sin(fi));
F=(2*acos(exp(-f))./pi);
if r<=root
[beta,CL,CD,~]=interpReynolds(Re,profile_rt);
opt=find(beta==fi-beta_c_opt);
beta=deg2rad(beta(opt)); CL=CL(opt); CD=CD(opt);
elseif r>=root && r<=primary
[beta_rt,CL_rt,CD_rt,~]=interpReynolds(Re,profile_rt);
opt_rt=find(beta_rt==fi-beta_c_opt); beta_rt=beta_rt(opt_rt); CL_rt=CL_rt(opt_rt); CD_rt=CD_rt(opt_rt);
[beta_p,CL_p,CD_p,~]=interpReynolds(Re,profile_p);
opt_p=find(beta_p==fi-beta_c_opt); beta_p=beta_p(opt_p); CL_p=CL_p(opt_p); CD_p=CD_p(opt_p);
[beta,~,CL,CD]=interpRadius(root,primary,beta_rt,beta_p,CL_rt,CL_p,CD_rt,CD_p,r,fi);
elseif r>=primary && r<=tip
[beta_p,CL_p,CD_p,~]=interpReynolds(Re,profile_p);
opt_p=find(beta_p==fi-beta_c_opt); beta_p=beta_p(opt_p); CL_p=CL_p(opt_p); CD_p=CD_p(opt_p);
[beta_t,CL_t,CD_t,~]=interpReynolds(Re,profile_t);
opt_t=find(beta_t==fi-beta_c_opt); beta_t=beta_t(opt_t); CL_t=CL_t(opt_t); CD_t=CD_t(opt_t);
[beta,~,CL,CD]=interpRadius(primary,tip,beta_p,beta_t,CL_p,CL_t,CD_p,CD_t,r,fi);
elseif r>=tip
[beta,CL,CD,~]=interpReynolds(Re,profile_t);
opt=find(beta==fi-beta_c_opt);
beta=deg2rad(beta(opt)); CL=CL(opt); CD=CD(opt);
end
sigma=4*V0*a*F/(((CL/tan(fi))+CD)*W);
chord_dim=2*pi*r_dim*sigma/Nb;
a1=sigma*W*(CL-CD/tan(fi))/(4*omega*r_dim*F);
Re_new=rho*chord_dim*W/mu;
end
This function is recalled by this part of the script:
i=r_opt;
z(i)=0;
while abs(Re_guess(j,i)-Re(j,i))>1e4
z(i)=z(i)+1;
[fi(j,i),W(j,i),f(j,i),F(j,i),beta(j,i),beta_c(j,i),CL(j,i),CD(j,i),a1(j,i),Re_new(j,i),chord_dim(j,i),sigma(j,i)] = ...
iteration2(a(j,i),a1(j,i),V0,omega(j),r(i),r_dim(i),Re(j,i),rho,mu,Nb,R,root,primary,tip,...
profile_rt,profile_p,profile_t);
Re_guess(j,i)=Re(j,i);
Re(j,i)=RF(j)*Re_new(j,i)+(1-RF(j))*Re(j,i);
end
beta_opt=beta(j,i);
beta_c_opt=beta_c(j,i)*ones(1,length(r));
for i=1:length(r)
i
z(i)=0;
while abs(Re_guess(j,i)-Re(j,i))>1e4
z(i)=z(i)+1;
[fi(j,i),W(j,i),f(j,i),F(j,i),beta(j,i),CL(j,i),CD(j,i),a1(j,i),Re_new(j,i),chord_dim(j,i),sigma(j,i)] = ...
iteration(a(j,i),a1(j,i),V0,omega(j),r(i),r_dim(i),Re(j,i),rho,mu,Nb,R,root,primary,tip,...
profile_rt,profile_p,profile_t,beta_c_opt(i));
Re_guess(j,i)=Re(j,i);
Re(j,i)=RF(j)*Re_new(j,i)+(1-RF(j))*Re(j,i);
end
end
chord(j,:)=chord_dim(j,:)/R;

Accepted Answer

Walter Roberson
Walter Roberson on 3 Oct 2021
Edited: Walter Roberson on 3 Oct 2021
You are using == to compare floating point numbers that are being computed different ways. Most of the time, because of floating point round-off, the values you want to compare will not be bit-for-bit identical, and == always only compares bit-for-bit identical when the same datatype is being compared (exception: -0 and 0 compare equal, and all the different kinds of nans are treated the same.)
You should use ismembertol() or check that abs() of the difference between the numbers is less than some tolerance. And even then you should be writing the code in a way that is robust for the case where there simply is no reasonable match.
You can reliably use == to compare floating point numbers that are integers in the range -2^53 to +2^53, but only if you can guarantee that they are integers. Not, for example, 29/7*7 which is not an integer .
Beyond that... things start to get a bit strange, and you should be careful about using ==
The major exception to this is that if you extract a value from an array by indexing or max() or min(), then you can be certain that it is a bit-for-bit identical copy of what is in the array, and you can == the extracted value to the array. It is safe, for example, to use
x = randi([3 9], 1, 5)
x = 1×5
3 7 3 5 7
minx = min(x)
minx = 3
x == minx
ans = 1×5 logical array
1 0 1 0 0
  6 Comments
Walter Roberson
Walter Roberson on 6 Oct 2021
dists = abs(beta(:) - reshape(fi-beta_c_opt),1,[]));
opt = min(dists, 2);
opt will now be a vector with the same number of elements that beta has, and each entry will be the linear index into fi-beta_c_opt of the closest value (even if the value is not very close on an absolute scale.)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!