I understand you are trying to solve system of differential equation using ‘dde23’. To do this you need to do following steps.
Define constant delays.
In this system of equation there are two lags i.e. (t-1) and (t-0.2).
lags = [1 0.2];
2. Define Solution History.
It Defines the first solution from which the solver starts iterations.
function s = history(t)
s = ones(3,1);
end
3. Form the equation.
function dydt = ddex1de(t,y,Z)
ylag1 = Z(:,1);
ylag2 = Z(:,2);
dydt = [ylag1(1);
ylag1(1)+ylag2(2);
y(2)];
end
Here In the call to ddex1de,
‘t’ is a scalar indicates the current ‘t’ in the equation
‘y’ is a column vector approximates y(t)
‘Z’ is a column vector approximates y(t – αj) for delay αj= lags(J).
In the following example Solution history is [1;1;1]. So Approximate values of lag ie ‘Z’ will be a matrix of size 3x2.In ‘Z’ Row defines the number of equations and column defines Number of lags.
Then you write your ODE-function (preferably in an m-file):
function Dy = harmonic_ode(t,z)
Dz = [0;0];
Dz(1) = z(2);
Dz(2) = -a*z(1);
To solve your ODE you should preferably use one of the built-in ODE-solvers, for example ode23 z0 = [y0;y1]; [sol] = ode23(@(t,z) harmonic_ode(t,z),t_span,z0);
Best Answer