## Welcome to the World of Modelling and Simulation

### What is Modelling?

This blog is all about system dynamics modelling and simulation applied in the engineering field, especially mechanical, electrical, and ... ### Implicit Euler Method by MATLAB to Solve an ODE

In this example, an implementation of the Implicit Euler approach by MATLAB program to solve an ordinary differential equation (ODE) is presented. Let's consider a differential equation, which is defined as,

dv/dt = p(t) v + q(t)

Where,

p(t) = 5(1+t)

and,

q(t) = (1+t)e-t

The initial value is, v(0) = 1; and the time period is 0 < t < 10.

Implicit Euler approach is unconditionally stable. The implementation of Implicit Euler scheme may be represented as,

v_n+1 = (v_n + hq_n+1) / (1 + hp_n+1)

The following MATLAB program implements this scheme:

MATLAB program:

close all;
clc;
y1(1) = 0; % Initial condition
h = 0.1; % Time step
t1(1) = 0;
i = 1;

% Implementation of the Implicit Euler approach
while (t1(i) <= 30)
q=(1+t1(i))*exp(-t1(i));
p= 5*(1+t1(i));

y1(i+1) = (y1(i)+(h*q))/(1+h*p);
t1(i+1) = t1(i) + h;
i = i + 1;
end
plot(t1,y1,'-o')
hold on

Program Output:
The following plot shows the progression of the solution as the time increases.