Clear Filters
Clear Filters

Euller method to solve mackey glass system

6 views (last 30 days)
In my understanding , dt needs to be very small so that the Euller method works.
I am solving the mackey glass equation
dx(t)/dt = 0.2x(t-tau)/(1+x(t-tau)^10) - 0.1x(t)
If I use dt = 1, the graph is very "mackey-glassy", but for any value different than 1, the system converges to a step function.
What am I doing wrong?
Thanks,
x = make_mg_euller(0.3,17);
Warning: Function Warning: Name is nonexistent or not a directory: /users/mss.system.452ATJ/./mackeyglass > In path (line 109) In addpath (line 86) In addpath (line 47) In LiveEditorEvaluationHelperEeditorId>make_mg_euller (line 8) In LiveEditorEvaluationHelperEeditorId (line 1) In connector.internal.fevalMatlab In connector.internal.fevalJSON
figure;
plot(x)
function [x] = make_mg_euller(x0,tau)
addpath ./mackeyglass/
% Euler's Method
% Initial conditions and setup
dt = 0.01; % step size
n = 400000; % simulation steps
x = double(zeros(n,1)); % allocate
x(1) = x0; % initial condition
% The loop to solve the DE
for i = 1:tau-1
x(i+1) = x(i) + double (dt * ( - 0.1 * x(i) ) );
end
for i = tau:n-1
x(i+1) = x(i) + double(dt* ( ( 0.2 * x(i-tau+1) ) / ( 1 + x(i-tau+1)^10 ) - ( 0.1 * x(i) ) )) ;
end
end
  2 Comments
Torsten
Torsten on 29 Apr 2023
Edited: Torsten on 2 May 2023
You try to solve a delay differential equation. Use dde23.
If you want to solve it with your own code, note that tau has to be a multiple of dt, and you must access x(i-j) to get x(t-tau) if tau = j*dt. For t <= tau, x must explicitly be prescribed as a "history" function or by an ordinary differential equation without delay terms and an initial condition at t=0.

Sign in to comment.

Accepted Answer

LeoAiE
LeoAiE on 28 Apr 2023
The main issue with your implementation is that you're using the parameter tau as an integer representing the time delay in terms of steps instead of a continuous time value. With this, when you use a different dt, the delay in the equation isn't adjusted properly.
To fix the issue, you need to calculate the number of steps that correspond to the time delay tau based on the dt value. Here's an updated version of your code with the necessary changes:
x = make_mg_euller(0.3,17);
figure;
plot(x)
function [x] = make_mg_euller(x0, tau)
% Euler's Method
% Initial conditions and setup
dt = 0.01; % step size
n = 400000; % simulation steps
x = double(zeros(n, 1)); % allocate
x(1) = x0; % initial condition
% Calculate the number of steps corresponding to the time delay tau
tau_steps = round(tau / dt);
% The loop to solve the DE
for i = 1:tau_steps - 1
x(i + 1) = x(i) + double(dt * (-0.1 * x(i)));
end
for i = tau_steps:n - 1
x(i + 1) = x(i) + double(dt * ((0.2 * x(i - tau_steps + 1)) / (1 + x(i - tau_steps + 1)^10) - (0.1 * x(i))));
end
end

More Answers (0)

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!