1D Heat equation using an implicit method

16 次查看(过去 30 天)
hi guys,
so i made this program to solve the 1D heat equation with an implicit method.
i have a bar of length l=1
the boundaries conditions are T(0)=0 and T(l)=0
and the initial conditions are 1 if l/4<x<3*l/4 and 0 else.
i plot my solution but the the limits on the graph bother me because with an explicit method i have a better shape for the same problem.
if someone can help me solve the problem
clear, clc, close all
%% parametres
Nx = 40;
Nt = 1000;
dx = 1/(Nx-1);
c = 5;
l=1;
cfl = (2*c)/(2*c+1);
dt = cfl*(dx^2)/(2*c);
alpha = c*dt/dx^2;
beta = (1+2*alpha);
x = 0:dx:l;
%% construction de la matrice A
A = full(spdiags(ones(Nx,1)*[-alpha,beta,-alpha],[-1,0,1],Nx,Nx));
%% construction de la matrice b
b = ones(Nx,1);
b(1:Nx/4,1)=0; % initial conditions
b(3*Nx/4:Nx,1)=0; % initial conditions
%% %% %% %%t
time = 0;
for t = 0:dt:Nt
T = linsolve(A,b);
T(1) = 0; % boundary conditions
T(Nx) = 1; % boundary conditions
b = T;
time = time+dt;
figure(1), clf % Solution plot
plot(x,T);
xlabel('x [m]')
ylabel('Temperature [^oC]')
ylim([0 3])
drawnow
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by