필터 지우기
필터 지우기

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

조회 수: 2 (최근 30일)
Chizembi Sakulanda
Chizembi Sakulanda 2023년 10월 5일
댓글: Chizembi Sakulanda 2023년 10월 5일
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);

답변 (1개)

Walter Roberson
Walter Roberson 2023년 10월 5일
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

카테고리

Help CenterFile Exchange에서 Heat and Mass Transfer에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by