필터 지우기
필터 지우기

1D Heat equation using an implicit method

조회 수: 16 (최근 30일)
krayem youssef
krayem youssef 2019년 4월 14일
댓글: Youssef Benmoussa 2020년 4월 12일
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
  댓글 수: 1
Youssef Benmoussa
Youssef Benmoussa 2020년 4월 12일
bonjour est ce que tu peut m'envoyer le code pour l'implicite ?

댓글을 달려면 로그인하십시오.

답변 (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