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?

1 view (last 30 days)
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');

Accepted Answer

VBBV
VBBV on 16 Nov 2022
Edited: VBBV on 16 Nov 2022
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 Comments
VBBV
VBBV on 16 Nov 2022
Edited: VBBV on 16 Nov 2022
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');

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!