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');
0 个评论
采纳的回答
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
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 Center 和 File Exchange 中查找有关 PDE Solvers 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!