error: Unable to perform assignment because the size of the left side is 1-by-49 and the size of the right side is 1-by-51 at line 23, where is the problem?

조회 수: 2 (최근 30일)
clear all;
close all;
geometry of domain
Nx = 51;
Ny = 51;
dx = 1/(Nx-1);
dy = 1/(Ny-1);
W = 0:dx:1;
H = 0:dy:1;
boundary and initial condition
T(10,25) = 2.5;
T(13,13) = -0.5;
T(5,38) = -2.5;
TL = 1;
TR = cos(6*3/2*3.14*H);
TT = 1;
TB = 1+W;;
T(1,2:Ny-1) = TL;
T(2:Nx-1,Ny) = TT;
T(Nx,2:Ny-1) = TR;
T(2:Nx-1,1) = TB;
T(1,1) = (TL+TB)/2;
T(Nx,1) = (TR+TB)/2;
T(1,Ny) = (TL+TT)/2;
T(Nx,Ny) = (TR+TT)/2;
Computation
Epsilon = 1e-7;
Error = 5;
Iteration = 0;
while(Error>Epsilon)
Iteration = Iteration + 1;
T_old = T;
for j = 2:Ny-1
for i = 2:Nx-1
T(i,j) = (T(i+1,j)+T(i-1,j)+T(i,j+1)+T(i,j-1))/4;
end
end
Error = sqrt(sumsqr(T-T_old));
end
plotting the results
colormap("jet");
contourf(W,H,T');
colorbar
title('Temperature Distribution');
xlabel('width');
ylabel('height');

채택된 답변

VBBV
VBBV 2022년 11월 16일
편집: VBBV 2022년 11월 16일
T(Nx,2:Ny-1) = TR(2:Ny-1);
T(2:Nx-1,1) = TB(2:Nx-1).';
Vectors TR and TB are of different sizes
  댓글 수: 6
VBBV
VBBV 2022년 11월 16일
편집: VBBV 2022년 11월 16일
If you had tried you wouldn't get same error in same line
clear all;
close all;
% geometry of domain
Nx = 51;
Ny = 51;
dx = 1/(Nx-1);
dy = 1/(Ny-1);
W = 0:dx:1;
H = 0:dy:1;
% boundary and initial condition
T(10,25) = 2.5;
T(13,13) = -0.5;
T(5,38) = -2.5;
TL = 1;
TR = cos(6*3/2*3.14*H);
TT = 1;
TB = 1+W;
T(1,2:Ny-1) = TL;
T(2:Nx-1,Ny) = TT;
T(Nx,2:Ny-1) = TR(2:Ny-1);
T(2:Nx-1,1) = TB(2:Nx-1).';
T(1,:) = (TL+TB)/2;
T(:,1) = (TR+TB)/2;
T(1,Ny) = (TL+TT)/2;
T(Nx,:) = (TR+TT)/2;
% Computation
Epsilon = 1e-7;
Error = 5;
Iteration = 0;
while(Error>Epsilon)
Iteration = Iteration + 1;
T_old = T;
for j = 2:Ny-1
for i = 2:Nx-1
T(i,j) = (T(i+1,j)+T(i-1,j)+T(i,j+1)+T(i,j-1))/4;
end
end
Error = sqrt(sumsqr(T-T_old));
end
% plotting the results
colormap("jet");
contourf(W,H,T');
colorbar
title('Temperature Distribution');
xlabel('width');
ylabel('height');

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 PDE Solvers에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by