Filter löschen
Filter löschen

Matrix Size Mismatch for Heat Conduction - 1x1 vs 50x100x101

2 Ansichten (letzte 30 Tage)
Chizembi Sakulanda
Chizembi Sakulanda am 5 Okt. 2023
I am looking to calculte the heat transfer across an axysymmetric 2D cylinder. I've discreteised the governing equations using the explicit control-volume finite difference method. Howeever, for one of my surfaces, there seems to be a matrix mismatch because when I run the code I get the error message
"Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 50-by-100-by-101."
Here is the portion of the code with the T(i,j,step+1) portion that has been flagged
% Create grids
dr = R / Nr;
dz = L / Nz;
r = linspace(dr/2, R-dr/2, Nr);
z = linspace(dz/2, L-dz/2, Nz);
% Initialize 3D arrays for temperature and concentration
T = ones(Nr, Nz, num_steps+1); % Temperature array
rho = ones(Nr, Nz, num_steps+1) * rho_initial; % Concentration array
%Initial conditions
T(i,j,step) = Tint;
for step = 1:num_steps
t = step * dt;
for i = 2:Nr-1
for j = 2:Nz-1
At least one END is missing. The statement beginning here does not have a matching end.
T(i,j,step+1) = (dt*k*(r(i) - 1/2))/(rho*Cpg*dr^2*r(i))*T(i-1,j,step) + (dt*k*(r(i) + 1/2))/(rho*Cpg*dr^2*r(i))*T(i+1,j,step) + ...
(2*dt*k)/(rho*Cpg*dz^2)*T(i,j,step) + (2*h*dt)/(rho*Cpg*dz)*Tinf + (1 - (dt*k*(r(i) - 1/2))/(rho*Cpg*dr^2*r(i)) - ...
(dt*k*(r(i) + 1/2)/(rho*Cpg*dr^2*r(i)) - (2*dt*k)/(rho*Cpg*dz^2) - (2*h*dt)/(rho*Cpg*dz)))*T(i,j,step) + Q_gen*(dt/rho*Cpg);

Antworten (1)

Walter Roberson
Walter Roberson am 5 Okt. 2023
T and rho are both 3D matrices.
T(i,j,step+1) = (dt*k*(r(i) - 1/2))/(rho*Cpg*dr^2*r(i))*T(i-1,j,step) + (dt*k*(r(i) + 1/2))/(rho*Cpg*dr^2*r(i))*T(i+1,j,step) + ...
(2*dt*k)/(rho*Cpg*dz^2)*T(i,j,step) + (2*h*dt)/(rho*Cpg*dz)*Tinf + (1 - (dt*k*(r(i) - 1/2))/(rho*Cpg*dr^2*r(i)) - ...
(dt*k*(r(i) + 1/2)/(rho*Cpg*dr^2*r(i)) - (2*dt*k)/(rho*Cpg*dz^2) - (2*h*dt)/(rho*Cpg*dz)))*T(i,j,step) + Q_gen*(dt/rho*Cpg);
This code uses all of rho in multiple places, instead of indexing rho similar to the way that you index T

Kategorien

Mehr zu Heat and Mass Transfer finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by