1D Heat Conduction using Eulers Explicit discretisation
Show older comments
I am trying to solve a problem regarding heat conduction. I have written down a code and using the method that I know I tried to solve it but when I'm making the T0 matrix it gives me error because I have to start at 0 Kelvin and it gives me an error. Attached is an image of the question I'm trying to solve here.

%% Clearing
clc
clear
close all
%% Initialisation
L=1;
t=100;
k=0.01;
nt=500;
dx=0.05;
n=L/dx;
dt=0.5;
x=0:dx:L;
alpha=k*dt/dx^2;
T0=0*ones(1,n);
T1=20*ones(1,n);
T0(1) = 0;
T0(end) = 20;
%% Solving
for j=1:nt
for i=2:n-1
T1(i)=T0(i)+alpha*(T0(i+1)-2*T0(i)+T0(i-1));
end
T0=T1;
end
%% plotting
timeset=[0 1 5 10 100]; % time instants required
for i=1:length(timeset) % 1 to number of elements in timeset
z=timeset(i); % time instant
ntset=z/dt+1; % time instant extracted for the corresponding step
figure, plot(x,T1(:,ntset)) % plotting temperature vs distance
ylabel('Temperature (°C)') % labels y axis
xlabel('Distance (m)') % label x axis
title('Distribution of Temperature') % title of graph
grid minor % detailed view
end
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

