clc; clearvars; close all;
%% INPUTS
% Geometrical
W = 40E-2; H = 20E-2;
% Boundary Conditions
T_b = 300;
% Transient Conditions
T_initial = 300;
T_inf = 50;
duration = 12;
h=50;
% Material Properties
k_slab = 28; alpha_slab = 12.5E-6; C_slab = k_slab/alpha_slab;
%% MESH
M = 5; N = 3;
DX = W/(M-1); DY = H/(N-1);
Xp = zeros(M,N); Yp = zeros(M,N);
for i = 1:M
for j = 1:N
if i == 1
Xp(i,j) = 0;
else
Xp(i,j) = Xp(i-1,j) + DX;
end
if j == 1
Yp(i,j) = 0.0;
else
Yp(i,j) = Yp(i,j-1) + DY;
end
end
end
figure
plot(Xp, Yp, 'ko', 'MarkerFaceColor', 'r', 'LineWidth', 1.5)
hold on
for i = 2:M
plot([Xp(i,1)-DX/2 Xp(i,1)-DX/2], [0 H], '–k', 'LineWidth', 1);
hold on
end
for j = 2:N
plot([0 W], [Yp(1,j)-DY/2 Yp(1,j)-DY/2], '–k', 'LineWidth', 1);
hold on
end
xlabel('X-position \rightarrow'); ylabel('Y-position \rightarrow');
https://hizliresim.com/Ioc8pg
merhaba soru ile ilgili taslak olacak şekilde 2 boyutu zamana bağlı kod yazdım fakat döngü dönmüyor ve hep aynı cevabı çıkartıyor bunun sebebi ne oalbilir?
Merhaba,
Kodunuzun tamamı bu mu bilmiyorum ama zaman döngüsünü göremedim. 1'den M'ye ve 1'den N'ye giden döngüler x ve y doğrultularını tarıyor ama zaman döngüsü yok gibi. Bu yüzden aynı sonuç çıkıyordur.
clc; clearvars; close all;
% Geometrical
W = 4E-2; H = 2E-2;
% Boundary Conditions
T_boundary =10;
% Transient Conditions
T_initial = 300;
duration = 12;
% Material Properties
h_slab=200;
k_slab = 28; alpha_slab = 12.5E-6; C_slab = k_slab/alpha_slab;
%% MESH
M = 5; N = 3;
DX = W/(M-1); DY = H/(N-1);
Xp = zeros(M,N); Yp = zeros(M,N);
for i = 1:M
for j = 1:N
if i == 1
Xp(i,j) = 0;
else
Xp(i,j) = Xp(i-1,j) + DX;
end
if j == 1
Yp(i,j) = 0.0;
else
Yp(i,j) = Yp(i,j-1) + DY;
end
end
end
figure
plot(Xp, Yp, 'ko', 'MarkerFaceColor', 'r', 'LineWidth', 1.5)
hold on
for i = 2:M
plot([Xp(i,1)-DX/2 Xp(i,1)-DX/2], [0 H], '–k', 'LineWidth', 1);
hold on
end
for j = 2:N
plot([0 W], [Yp(1,j)-DY/2 Yp(1,j)-DY/2], '–k', 'LineWidth', 1);
hold on
end
xlabel('X-position \rightarrow'); ylabel('Y-position \rightarrow');
%% Fourier number
dt = 2; %0.5*DX^2/alpha_slab
N_time = duration/dt;
%% ITERATIVE SOLVER
% Set the initial value
T = ones(M,N)*T_initial; T0 = ones(M,N)*T_initial;
Tinf = 50;
% LOOP
for dt =1:duration
for i=1:M
for j=1:N
if i==1 || i==M
ap = 1;
b = T_initial;
T(i,j) = b/ap;
elseif j==N
aw = k_slab*DY/2*DX;
ae = k_slab*DY/2*DX;
as= k_slab*DX/DY;
an = h_slab*DX;
ap0 = C_slab*DX^2/dt;
b = ap0*T0(i,j);
T(i,j) = (aw*(T0(i-1,j) – T0(i,j)) + ae*(T0(i+1,j) – T0(i,j))+as*(T0(i,j-1) – T0(i,j))+an*(Tinf-T0(i,j))+ b)/ap0;
elseif j==1
aw = k_slab*DY/2*DX;
ae = k_slab*DY/2*DX;
an = k_slab*DX/DY;
ap0 = C_slab*DX^2/dt;
b = ap0*T0(i,j);
T(i,j) = (aw*(T0(i-1,j) – T0(i,j)) + ae*(T0(i+1,j) – T0(i,j))+an*(T0(i,j+1) – T0(i,j))+ b)/ap0;
else
aw = k_slab*DY/DX;
ae = k_slab*DY/DX;
an = k_slab*DX/DY;
as = k_slab*DX/DY;
ap0 = C_slab*DX/dt;
b = ap0*T0(i,j);
T(i,j) = (aw*(T0(i-1,j) – T0(i,j)) + ae*(T0(i+1,j) – T0(i,j))+an*(T0(i,j+1) – T0(i,j))+as*(T0(i,j-1) – T0(i,j))+b)/ap0;
end
end
end
end
T