From Explicit to Implicit Euler
63 views (last 30 days)
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;
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?
suketu vaidya on 9 Nov 2020
h = 0.0001;
x = -pi:h:pi;
y1 = ;
for i = 1:length(x)-1
y1(i+1)=y1(i) + h * f1(x(i), y1(i));
function dy = f1(x,y1)
y0 = -1;
d = 50;
i cant able to run both explicit Euler, implicit Euler in one file