1D Heat Equation Explicit Scheme

1 Ansicht (letzte 30 Tage)
Gabriel Quattromani
Gabriel Quattromani am 24 Apr. 2022
Beantwortet: Alan Stevens am 25 Apr. 2022
Hi, I am trying to write a program to find the minimum depth required to avoid pipes at a depth of xm from freezing, after a temperature of -15oC for 60 days.
I am getting the error message "Index in position 1 is invalid. Array indices must be positive integers or logical values."
Here is my code.
clear all
p=2050; % density(kg/m^3)
k=0.52; % conductivity(W/m-K)
c=1840; % specific heat capacity(J/kg-K)
T_ini=20; % initial temperature(K)
T_inf=-15; % external temperature(K)
alpha=k/(p*c); % Let thermal diffusivity be alpha
M=100; % number of time steps
t=60;
DELTA_t=t/(M); % time step duration(s)
for j=1:M
time(j)=(j-1)*DELTA_t;
end
N=10;
L=0.05;
DELTA_x=L/(N);
x=0:DELTA_x:L;
%Initial wall temperatures T(i,1)
for i=1:N+1
T(i,1)=T_ini;
T(i,N)=0;
end
% Step trough time
for j=1:(M-1)
for i=1:(N)
if (alpha*DELTA_t)/(DELTA_x^2)<=0.5
T(i,j+1)=T(i,j)+((alpha*DELTA_t)/((DELTA_x)^2))*(T(i+1,j)-2*T(i,j)+T(i-1,j));
end
end
end

Akzeptierte Antwort

Alan Stevens
Alan Stevens am 25 Apr. 2022
Look at
for i=1:(N)
if (alpha*DELTA_t)/(DELTA_x^2)<=0.5
T(i,j+1)=T(i,j)+((alpha*DELTA_t)/((DELTA_x)^2))*(T(i+1,j)-2*T(i,j)+T(i-1,j));
end
You have a term T(i-1,j). When i is 1 this would be T(0,j), but Matlab indices must start at 1, not 0.

Weitere Antworten (0)

Kategorien

Mehr zu Thermal Analysis finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by