How can I turn this Explicit method code to Implicit method code ?

조회 수: 26 (최근 30일)
Md Badrul Hasan
Md Badrul Hasan 2018년 10월 17일
댓글: Torsten 2018년 10월 17일
I want to turn my matlab code for 1D heat equation by explicit method to implicit method. How can I do this easily?
% A program to plot the temperature distribution in a insulated rod using the explicit Finite Central Difference Method and 1D Heat equation.
The rod is heated on one end at 400K and exposed to ambient temperature on the right end at 300K. I am using a time of 10s, 20 grid points
and a .2s time step.
L=1; % Length of modeled domain [m]
t=10; % time [s]
k=.001;
n=20; % Number of gridpoints
nt=500;
dx=L/n; % Spacing of grid
dt=.2; % Timestep [s]
alpha=k*dt/dx^2;
T0=400*ones(1,n);
T1=300*ones(1,n);
T0(1) = 300;
T0(end) = 300;
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
dlmwrite('Trial_1.csv',T1,'Delimiter','\n') % Saves data into a csv file
Please help.

답변 (1개)

Torsten
Torsten 2018년 10월 17일
L = 1; % Length of modeled domain [m]
nx = 200; % Number of gridpoints
t = 500; % time [s]
nt = 15;
k = .001;
dx = L/(nx-1); % Spacing of grid
dt = t/nt; % Timestep [s]
alpha = k*dt/dx^2;
T0 = 400*ones(nx,1);
T1 = 300*ones(nx,1);
T0(1)= 300;
T0(end) = 300;
A = full(gallery('tridiag',nx-2,-alpha,1+2*alpha,-alpha));
for j = 1:nt
b = [T0(2)+alpha*T0(1);T0(3:nx-2);T0(end-1)+alpha*T0(end)];
T1(2:end-1) = A\b;
T0 = T1;
end
  댓글 수: 2
Md Badrul Hasan
Md Badrul Hasan 2018년 10월 17일
A = full(gallery('tridiag',nx-2,-alpha,1+2*alpha,-alpha));
for j = 1:nt
b = [T0(2)+alpha*T0(1);T0(3:nx-2);T0(end-1)+alpha*T0(end)];
T1(2:end-1) = A\b;
I could not understand the operation here. Can you please elaborate ? Thanks for your reply.
Torsten
Torsten 2018년 10월 17일
Read and learn:
https://en.wikipedia.org/wiki/Finite_difference_method#Implicit_method
Best wishes
Torsten.

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

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by