How to force dde23 function to generate output after fixed time step

546 views Asked by At

I am solving a delay differential equation using MATLAB dde23 function. I want to use the output generated by the first dde23 function in the second dde23 function. Here is the code

tspan=[0:1:1440]';
x0=1.7;

%1st function 
% options = ddeset('OutputFcn',@odeplot,'OutputSel',1);
sol = dde23(@dd,70,x0,tspan,options);
y_obs=sol.y; 
tspan_new=sol.x;

%{2nd function 
x1=[x0 ; 0.1; 0.01; 0.01];
final_sol = dde23(@ddc,70,x1,tspan,[],y_obs);
y_fit=final_sol.y;
tdata=final_sol.x;
%}

The time series I generated as an input to the first function is of size 1441 but the size of tspan_new and y_obs is 212 (generated from the dde23 output). I am unable to understand why the size is changing. Is it possible to output y_obs at each time point provided in the input i.e. is it possible to obtain y_obs of length 1441 in this case ? Since the size of output is different I am unable to use y_obs vector in my second function. The size of y_fit and tdata is again entirely different from y_obs and tspan.

1

There are 1 answers

2
TroyHaskin On

Unlike the ODE Suite that implements a dense output routine as part of its time march, dde23 requires an explicit post-deval to accomplish what you're after:

tspan=[0:1:1440]';
x0=1.7;

%1st function 
sol   = dde23(@dd,70,x0,tspan([1,end]),options);
y_obs = deval(sol,tspan);

This function uses local Hermite cubic interpolation on the mesh generated by its dynamic time-stepping routine to approximate the y value at the requested t values.