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

7 vues (au cours des 30 derniers jours)
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.

Réponse acceptée

Torsten
Torsten le 17 Mai 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 commentaires
Amirhossein Sadeghi Manesh
@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 le 17 Mai 2023
Modifié(e) : Torsten le 17 Mai 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by