The size of X must match the size of Z or the number of columns of Z.
    3 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
clc
clear all
close all
%Geometry definition
L=0.3;                      %Length of the The rectangular bar in meter 
W=0.4;                      %Width of the The rectangular bar in meter
%Material properties 
alpha=11.234E-05;               %theraml diffusivity
% computional mesh
nx=31;                     %max divisions in x-direction
ny=41;                      %max divisions in y-direction
nt=100;                     %number of time step for transient simulation
dt=20;                     %time step size
x=linspace(0,L,nx);
y=linspace(0,W,ny);
dx=x(2)-x(1);
dy=y(2)-y(1);
convergence_criteria = 1e-4;    %Tolerance limitto stop the iteration at some point
error = 1e9;
%Temperature at boundary nodes
T = zeros(nx,ny);             % initialize temperature at all nodes
% Boundary conditions
T_top = 10;
T_bottom = 40;
T_right = 0;
T_left = 0;
T(1,:) = T_left;
T(end,:) = T_right;
T(:,1) = T_bottom;
T(:,end) = T_top;
T(1,1) = (T_bottom+T_left)/2;
T(end,1) = (T_bottom+T_right)/2;
T(1,end) = (T_left+T_top)/2;
T(end,end) = (T_top+T_right)/2;
%method details 
T_old  = T;  %previous iteration temperature  
T_prev = T;  %previous time step temperature
CFL_x = ((2*alpha*dt)/dx^2); %CFL along x
CFL_y = ((2*alpha*dt)/dy^2); %CFL along y
term_1 = (1 + CFL_x + CFL_y)^(-1);
term_2 = term_1*CFL_x/2;
term_3 = term_1*CFL_y/2;
solution_time = dt;    %tracking the solution time
jacobi_iteration = 1;
for k = 1:nt    %time marching
    while (error > convergence_criteria)    %Jacobi Iterative Method
        for i = 2:nx-1             %space marching along x
            for  j = 2:ny-1        %space marching along y
                H = (T_old(i+1,j) + T_old(i-1,j));
                V = (T_old(i,j+1) + T_old(i,j-1));
                T(i,j) = ((T_prev(i,j)*term_1) + (term_2*H) + (term_3*V)); 
            end
        end
        error = max(max(abs(T_old - T))); %calculating the error
        T_old = T;                        %updating the temperature for next iteration
        jacobi_iteration = 1 + jacobi_iteration;
    end
    error = 1;           %re-assigning the error
    T_prev = T;          %updating the temperature for the next time step  
    solution_time = dt + solution_time;
end
%ploting temperature contour
    figure(1)
    contourf(x,y,T.');
    colorbar
    colormap(jet);
    xlabel('X-Axis');
    ylabel('Y-Axis');
    title_text = sprintf('2D Implicit Unsteady Heat Diffusion, Jacobi, Solution Time: %.3f s',solution_time);
    title(title_text);
0 comentarios
Respuestas (1)
  Torsten
      
      
 el 27 de Dic. de 2022
        
      Editada: Torsten
      
      
 el 28 de Dic. de 2022
  
      Errors in coding and discretization have been corrected, I guess.
Why did you delete your previous question ? Quite impolite in my opinion.
clc
clear all
close all
%Geometry definition
L=0.3;                      %Length of the The rectangular bar in meter 
W=0.4;                      %Width of the The rectangular bar in meter
%Material properties 
alpha=11.234E-05;               %theraml diffusivity
% computional mesh
nx=31;                     %max divisions in x-direction
ny=41;                      %max divisions in y-direction
nt=100;                     %number of time step for transient simulation
dt=20;                     %time step size
x=linspace(0,L,nx);
y=linspace(0,W,ny);
dx=x(2)-x(1);
dy=y(2)-y(1);
convergence_criteria = 1e-4;    %Tolerance limitto stop the iteration at some point
error = 1e9;
%Temperature at boundary nodes
T = zeros(nx,ny);             % initialize temperature at all nodes
% Boundary conditions
T_top = 10;
T_bottom = 40;
T_right = 0;
T_left = 0;
T(1,:) = T_left;
T(end,:) = T_right;
T(:,1) = T_bottom;
T(:,end) = T_top;
T(1,1) = (T_bottom+T_left)/2;
T(end,1) = (T_bottom+T_right)/2;
T(1,end) = (T_left+T_top)/2;
T(end,end) = (T_top+T_right)/2;
%method details 
T_old  = T;  %previous iteration temperature  
T_prev = T;  %previous time step temperature
CFL_x = ((2*alpha*dt)/dx^2); %CFL along x
CFL_y = ((2*alpha*dt)/dy^2); %CFL along y
term_1 = (1 + CFL_x + CFL_y)^(-1);
term_2 = term_1*CFL_x/2;
term_3 = term_1*CFL_y/2;
solution_time = dt;    %tracking the solution time
jacobi_iteration = 1;
for k = 1:nt    %time marching
    while (error > convergence_criteria)    %Jacobi Iterative Method
        for i = 2:nx-1             %space marching along x
            for  j = 2:ny-1        %space marching along y
                H = (T_old(i+1,j) + T_old(i-1,j));
                V = (T_old(i,j+1) + T_old(i,j-1));
                T(i,j) = ((T_prev(i,j)*term_1) + (term_2*H) + (term_3*V)); 
            end
        end
        error = max(max(abs(T_old - T))); %calculating the error
        T_old = T;                        %updating the temperature for next iteration
        jacobi_iteration = 1 + jacobi_iteration;
    end
    error = 1;           %re-assigning the error
    T_prev = T;          %updating the temperature for the next time step  
    solution_time = dt + solution_time;
end
%ploting temperature contour
    figure(1)
    contourf(x,y,T.');
    colorbar
    colormap(jet);
    xlabel('X-Axis');
    ylabel('Y-Axis');
    title_text = sprintf('2D Implicit Unsteady Heat Diffusion, Jacobi, Solution Time: %.3f s',solution_time);
    title(title_text);
5 comentarios
  Torsten
      
      
 el 28 de Dic. de 2022
				I modified the code again to have x- and y-direction in T-array correctly.
Ver también
Categorías
				Más información sobre Pole and Zero Locations en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


