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
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
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;

カテゴリ

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

タグ

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by