MATLAB Answers

For inbuilt solvers ODE23/DDE23, how to keep saving/output all solution values intermediately (eg: every 1 hour, save/output the solution instead of only after reaching tf)

조회 수: 1(최근 30일)
kim pearson
kim pearson 2021년 8월 31일
댓글: kim pearson 2021년 9월 1일
For long run simulations, there is a chance the simulations might stop prematurely after running for a week.
tspan = [0 500];
sol = dde23(@ddefun, lags, @history, tspan);
In that case, if the simulation ends prematurely before t = 500, the above code doesn't return anything. Is there an efficient way to keep saving/outputing the sol at every value of eg., tf = [50, 100, 150...500] so that if the simulation stops, still I can use the sol values saved until that point to restart the simulation


Bjorn Gustavsson
Bjorn Gustavsson 2021년 8월 31일
You could request output for a selected set of points in time instead of only setting the time-span:
t_all = [0:1:500];
[t_out,Y] = dde23(@ddefun, lags, @history, t_all);
You'll have to judge how many time-steps to include in t_all. It seems a bit strange to me to not get anything out after dde23 quits prematurely, in my work I typically get the [t_out,Y] output up to the point where the ode-integrating functions give up (that is admittedly the odeNN-functions, dde23 might work differently).
  댓글 수: 1
kim pearson
kim pearson 2021년 8월 31일
So, this will output the state values only at those specific times right, what I also want is the history of states up until these specified times.

댓글을 달려면 로그인하십시오.

Steven Lord
Steven Lord 2021년 8월 31일
Specify an OutputFcn in your dde23 function. Have that OutputFcn log the data to a file.

Community Treasure Hunt

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

Start Hunting!

Translated by