ode45 taking long time to solve
89 ビュー (過去 30 日間)
古いコメントを表示
Hi, I'm trying to solve a system of ode's with 11 equations using the ode45 solver with time interval 0 to 200 and timestep of 0.1. I am also simulating drug treatments by giving doses as heaviside functions:
J=0;
a=29;
while a<200
J=J+85.62*(heaviside(t-a)-heaviside(t-(a+1)));
a=a+3.5;
end
Without the heaviside functions, the run takes approximately 10 minutes, but with the heaviside functions, it takes many hours to do a single run. Why is it taking so long? Is there a way to reduce the run time?
Thanks!
0 件のコメント
回答 (2 件)
Walter Roberson
2017 年 2 月 17 日
Every use of heaviside corresponds to a discontinuity in your function. The ode*() routines respond to discontinuities by trying to find their exact boundary numerically in order to try to meet integration tolerances. Then when it decides that Yes, there is a discontinuity, it will quit the integration.
If your formula calls for heaviside or piecewise in time, then you need call ode45() once for each individual time range, passing in the objective function specific to that time range and using the output of one as the boundary conditions of the next. If your formula calls for heaviside or piecewise in x (or y) then you need to use event functions to detect transitions between segments and terminate the integration, and then restart inside the next segment.
0 件のコメント
Peter O
2017 年 2 月 16 日
Is ode45 a requirement? I'd guess that your equations are becoming stiff when you add in the heavisides. As a result, ode45 is taking really small timesteps to satisfy your tolderance requirements.
Two options:
1. Decrease the tolerance on ode45. Obviously accuracy will suffer if you decrease it too far.
opts = odeset('RelTol',1e-3);
[t,Y] = ode45(@(t,y) myfunc(t,y,....), tspan, ic, opts);
2. Try a stiff solver like ode15s or ode23tb. I'd recommend trying this first.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!