Unable to perform assignment because the left and right sides have a different number of elements.
1 次查看(过去 30 天)
显示 更早的评论
When the code is run, this error generates:
>> twentycells
Unable to perform assignment because the left and
right sides have a different number of elements.
Error in twentycells (line 34)
D(1) = U-su;
I attached the codes below to assist in debunking the error.
Thank you in advance!
% name constant inputs:
ncells = 20;
hin = 50;
hinz = 100;
Tin = 100;
Tinz = 200;
Diam = 0.08;
L = 1;
k = 100;
P = pi*Diam;
Ac = (pi/4)*Diam.^2;
% calculate delta x (DX)
DX = L/ncells;
% mark cell centers
X(1) = 0;
for i = 2:ncells
X(i) = X(i-1) + DX;
end
% seperate math eqns to make coefficient calculations easier
Z = k/DX;
Y = (hinz*DX)/2;
W = k+Y;
V = (hinz*k)/W;
U = -V*Tinz;
sp = -hin*P*DX/Ac;
su = hin*P*T*DX/Ac;
% tridiagonal coefficients at left and right B/C's
B(1) = -Z-V+sp;
C(1) = Z;
D(1) = U-su;
A(ncells) = Z;
B(ncells) = -Z+sp;
D(ncells) = -su;
2 个评论
Andrés Castro
2020-2-27
Hi Alexandra:
In your code you have a mistake in su variable. The variable T is unrecognized. For this reason when you want to compute D(1), it isn't allowed.
Regards!
回答(1 个)
Jeremy
2020-2-27
Where is the definition of T? I am guessing that T is a vector, which makes su = hin*P*T*DX/Ac; a vector, and then you're trying to assign a vector to a scalar value with D(1) = U-su;
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!