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!