From Explicit to Implicit Euler

63 views (last 30 days)
Bas Haar
Bas Haar on 4 May 2019
Answered: suketu vaidya on 9 Nov 2020
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 Comment
Jim Riggs
Jim Riggs on 5 May 2019
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.

Sign in to comment.

Answers (1)

suketu vaidya
suketu vaidya on 9 Nov 2020
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

Community Treasure Hunt

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

Start Hunting!