Problem in using ddesd for a simple DDE with one dependent variable and two delay terms.

7 visualizaciones (últimos 30 días)
Let's say we have only one independent variable t and one dependent variable x. Then consider the following DDE equation
dx/dt = t*x(t-cos(t)) + t^2 * x(t-2) + t^3 ; t >= 0
and with the history
I guess I have to use ddesd as one of my term delays is not a constant delay, i.e. t-cos(t).
Reading the help page of ddesd (https://uk.mathworks.com/help/matlab/ref/ddesd.html) didn't make it clear for me how to do it. Here is my attempt.
sol = ddesd( @dde_equation, @delay, @history, [ 0, 1 ] );
t = sol.x;
x = sol.y;
plot(t, x);
xlabel('t');
ylabel('x(t)');
title('Solution of Delay Differential Equation');
% local functions
function dxdt = ddefun( t, x, Z )
dxdt = t * Z( 1, 1 ) + ( t ^ 2 ) * Z( 1, 2 ) + t ^ 3;
end
function d = delay( t )
d = [ delay1( t ); delay2( t ) ];
end
function d1 = delay1( t )
d1 = t - cos( t );
end
function d2 = delay2( t )
d2 = t - 2;
end
function v = history( t )
v = sin( t );
end
But I get the following error message
Error using Matlab_20230517_DDE_1>delay
Too many input arguments.
Error in ddesd>lagvals (line 549)
d = delays(tnow,ynow);
Error in ddesd (line 146)
Z0 = lagvals(t0,y0,delays,history,t0,y0,[]);
Error in Matlab_20230517_DDE_1 (line 1)
sol = ddesd( @dde_equation, @delay, @history, [ 0, 1 ] );
I would appreciate if someone let me know what is my mistake and how to solve the above DDE using Matlab. I found help pages and examples of DDE in Matlab help confusing and not really well explained.

Respuesta aceptada

Torsten
Torsten el 17 de Mayo de 2023
sol = ddesd( @ddefun, @delay, @history, [ 0, 1 ] );
t = sol.x;
x = sol.y;
plot(t, x);
xlabel('t');
ylabel('x(t)');
title('Solution of Delay Differential Equation');
% local functions
function dxdt = ddefun( t, x, Z )
dxdt = t * Z( 1, 1 ) + ( t ^ 2 ) * Z( 1, 2 ) + t ^ 3;
end
function d = delay( t, x )
d = [ delay1( t ); delay2( t ) ];
end
function d1 = delay1( t )
d1 = t - cos( t );
end
function d2 = delay2( t )
d2 = t - 2;
end
function v = history( t )
v = sin( t );
end
  2 comentarios
Amirhossein Sadeghi Manesh
Amirhossein Sadeghi Manesh el 17 de Mayo de 2023
@Torsten Thanks. Just to make sure that I understood right. I had one typo (dde_equation --> ddefun) and the other problem is that the delay function MUST have "x" as argument as well for the sake of ddesd. Am I right?
Torsten
Torsten el 17 de Mayo de 2023
Editada: Torsten el 17 de Mayo de 2023
Yes. Or you have to modify the list of input arguments to "delay":
sol = ddesd( @ddefun, @(t,x)delay(t), @history, [ 0, 1 ] );
and leave the function "delay" as in your posted code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Delay Differential Equations en Help Center y File Exchange.

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by