From Explicit to Implicit Euler

조회 수: 71 (최근 30일)
Bas Haar
Bas Haar 2019년 5월 4일
답변: suketu vaidya 2020년 11월 9일
Hello everyone, for an assignment, I have to make an implicit Euler descritization of the ODE: dc/dt = -0.15c^2 and compare computing times.
For this, an explicit Euler scheme is already provided:
f = @(t,c) -0.15*c^2; % function f, from dc/dt=f(c)
c_e(1) = 5; % initial concentration
t_e(1) = 0; % initial time
dt = 0.2; % time stepsize
i = 1;
tic % start computing timer
while (t_e(i) <= 5)
c_e(i+1) = c_e(i) + dt*f(t_e(i),c_e(i)); % time marching explicitly
t_e(i+1) = t_e(i) + dt; % forward time counter
i = i + 1;
end
toc
Now, how can I get to the equation : c_e(i+1) = c_e(i) + dt*f(t_e(i+1),c_e(i+1))?
I have tried predicting c_e(i+1) using the forward scheme and then plugging it in the backward scheme, but this feels very wrong.
I am allowed to use other solvers (a tip is provided that in the while loop, a solver like vpasolve is used).
Can anybody help me with this?
  댓글 수: 1
Jim Riggs
Jim Riggs 2019년 5월 5일
I can give some general comments.
The explicit method is very straight-forwardand and easy to implement. That's it's main appeal. An implicit method, by definition, contains the future value (i+1 term) on both sides of the equation. Consequently, more work is required to solve this equation. Since the c_e(i+1) shows up on both sides, you might try an itterative solution, such as make an initial guess, then use Newton-Raphson to refine the guess until it converges. Clearly a lot more computation is involved.
The point of this exercise is probably to realize that explicit methods are easier. But you will learn that they have stability issues, and are not well suited for "stiff" systems. For stiff systems, an implicit method performs better.

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

답변 (1개)

suketu vaidya
suketu vaidya 2020년 11월 9일
function taska
h = 0.0001;
x = -pi:h:pi;
y1 = [0];
for i = 1:length(x)-1
y1(i+1)=y1(i) + h * f1(x(i), y1(i));
y1(i+1)=y1(i)+h*f1(x(i+1), y1(i+1));
end
plot(x,y1)
end
function dy = f1(x,y1)
y0 = -1;
dx=0.01;
d = 50;
c1=(y0-(d^2/(d^2+1)));
dy=c1*exp(-dx)+d*(sin(x)/(d^2+1))+d^2*(cos(x)/d^2+1);
end
i cant able to run both explicit Euler, implicit Euler in one file

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by