필터 지우기
필터 지우기

Finite explicit method for heat differential equation

조회 수: 25 (최근 30일)
Ewona CZ
Ewona CZ 2019년 12월 15일
답변: Shahidul 2023년 6월 4일
I'm get struggles with solving this problem: Using finite difference explicit and implicit finite difference method solve problem with initial condition: u(0,x)=sin(x) and boundary conditions: ,
So, I tried but get struggles and really need advises. Even I'm not sure how to describe this differential equation or choose number of time steps/space steps in Matlab. Here is what I have tried:
L = 1.; % Length of the wire
T =1; % Final time
% Parameters needed to solve the equation within the explicit method
maxk = 50; % Number of time steps
dt = T/maxk;
n = 10; % Number of space steps
dx = L/n;
a = 1;
b = 2.*a*dt/(dx*dx);
% Initial temperature of the wire: a sinus.
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(x(i));
end
% Temperature at the boundary
for t=1:maxk+1
u(1,t) = exp(t);
u(n+1,t) = sin(1)*exp(t);
time(t) = (t-1)*dt;
end
% Implementation of the explicit method
for t=1:maxk % Time Loop
for i=2:n; % Space Loop
u(i,t+1) =u(i,t) + b*(u(i-1,t)+u(i+1,t)-2.*u(i,t));
end
end
% Graphical representation of the temperature at different selected times
figure(1)
plot(x,u(:,1),'-',x,u(:,10),'-',x,u(:,45),'-',x,u(:,30),'-',x,u(:,60),'-')
title('Temperature within the explicit method')
xlabel('X')
ylabel('T')
figure(2)
mesh(x,time,u')
title('Temperature within the explicit method')
xlabel('X')
ylabel('Temperature')
  댓글 수: 1
Furqan Ahmad
Furqan Ahmad 2022년 9월 9일
Dear Respected sir, i appreciate your work .Dear sir, I'm student of BS(Hons)Mathematics in GC University,Lahore.Sir,I'm last year student and my research topic is "Numerical solution of 1D Wave equation using by Finite Difference approximation" (Explicit and implicit Schemes).Sir,I need your help .Sir can you make me a big favour? Sir ,i want you to make 3 codes for me. 1:Matlab code for Analytic soltuion of 1D Wave equation 2: Matlab codes for Explicit and Implicit methods. Sir, i can send you the details of my topic. Please be kind with me I will be gratefull to you

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

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2019년 12월 15일
You were actually pretty close, the main problem was that in the boundary condition you was exponentiating your index, not your actually time. Besides this you missed the x and t terms in the equation and the time step needed to be smaller for stability. This code produces reasonable results
L = 1.; % Length of the wire
T =1; % Final time
% Parameters needed to solve the equation within the explicit method
maxk = 210; % Number of time steps
dt = T/maxk;
n = 10; % Number of space steps
dx = L/n;
a = 1;
b = a*dt/(dx*dx); % b should be less than 0.5
% Initial temperature of the wire: a sinus.
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(x(i));
end
% Temperature at the boundary
for t=1:maxk+1
time(t) = (t-1)*dt;
u(1,t) = exp(time(t));
u(n+1,t) = sin(1)*exp(time(t));
end
% Implementation of the explicit method
for t=1:maxk % Time Loop
for i=2:n; % Space Loop
u(i,t+1) =u(i,t) + b*(u(i-1,t)+u(i+1,t)-2.*u(i,t)) + dt*(x(i)-time(t));
end
end
% Graphical representation of the temperature at different selected times
figure(1)
plot(x,u(:,1),'-',x,u(:,10),'-',x,u(:,45),'-',x,u(:,30),'-',x,u(:,60),'-')
title('Temperature within the explicit method')
xlabel('X')
ylabel('T')
figure(2)
mesh(x,time,u')
title('Temperature within the explicit method')
xlabel('X')
ylabel('Temperature')
Untitled.png
  댓글 수: 2
Ewona CZ
Ewona CZ 2019년 12월 15일
Thank you, it's really helpful, but why you using dt* here before (x(i)-time(t)?
for i=2:n;
u(i,t+1) =u(i,t) + b*(u(i-1,t)+u(i+1,t)-2.*u(i,t)) + dt*(x(i)-time(t));
end
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2019년 12월 15일
if you discretize the equation you end up with a dt term multiplying the right side. You had this term in your b, but the (x-t) term didn't, therefore to reproduce the equation you wrote it this dt is needed

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

추가 답변 (1개)

Shahidul
Shahidul 2023년 6월 4일
L = 1.; % Length of the wire
T =1; % Final time
% Parameters needed to solve the equation within the explicit method
maxk = 210; % Number of time steps
dt = T/maxk;
n = 10; % Number of space steps
dx = L/n;
a = 1;
b = a*dt/(dx*dx); % b should be less than 0.5
% Initial temperature of the wire: a sinus.
for i = 1:n+1
x(i) =(i-1)*dx;
u(i,1) =sin(x(i));
end
% Temperature at the boundary
for t=1:maxk+1
time(t) = (t-1)*dt;
u(1,t) = exp(time(t));
u(n+1,t) = sin(1)*exp(time(t));
end
% Implementation of the explicit method
for t=1:maxk % Time Loop
for i=2:n; % Space Loop
u(i,t+1) =u(i,t) + b*(u(i-1,t)+u(i+1,t)-2.*u(i,t)) + dt*(x(i)-time(t));
end
end
% Graphical representation of the temperature at different selected times
figure(1)
plot(x,u(:,1),'-',x,u(:,10),'-',x,u(:,45),'-',x,u(:,30),'-',x,u(:,60),'-')
title('Temperature within the explicit method')
xlabel('X')
ylabel('T')
figure(2)
mesh(x,time,u')
title('Temperature within the explicit method')
xlabel('X')
ylabel('Temperature')

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by