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

1 visualizzazione (ultimi 30 giorni)
Modificato: Torsten il 17 Mag 2023
Let's say we have only one independent variable t and one dependent variable x. Then consider the following DDE equation
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.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Torsten il 17 Mag 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 CommentiMostra NessunoNascondi Nessuno
@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 il 17 Mag 2023
Modificato: Torsten il 17 Mag 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.

Accedi per commentare.

### Categorie

Scopri di più su Delay Differential Equations in Help Center e File Exchange

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by