Unable to perform assignment because the left and right sides have a different number of elements.

1 view (last 30 days)
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;

Answers (1)

Jeremy
Jeremy on 27 Feb 2020
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;

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!