Is it possible to access the value of the variable step size (of the independent variable) used by ODE45 within the ode function?
조회 수: 3 (최근 30일)
이전 댓글 표시
If I am solving for y, which is a function of t, using ODE45, will it be possible for me to access and print the value of the variable step size dt used by ODE45? If yes, can anyone tell me how to do it? I would like to know the value of dt used during each time step, and print it as the solution progreses.
댓글 수: 2
Torsten
2021년 6월 1일
편집: Torsten
2021년 6월 1일
If you choose tspan = [tstart tend] in the call to ODE45, you will get the solution at the times the solver has chosen. The difference between T(i+1) and T(i) will be the dt variable you are looking for.
If you need the dt values during the calculation, you will have to use the OutputFcn function.
채택된 답변
Steven Lord
2021년 6월 1일
No, ode45 does not provide this information to the ODE function you pass into it.
Why are you interested in the steps ode45 uses internally (which may not be the same as the steps between values returned by the solver and which in fact may not be positive if a proposed step needs to be rejected because the solution does not satisfy the error tolerances?)
If you want this information to display the progress of the ODE solver use an OutputFcn. See the ballode and orbitode examples included with MATLAB for a demonstration of this technique.
If your ODE function includes delays meaning that your equation is not y' = f(t, y) but y' = f(t, y, y(t-delay1), etc.) then use a delay differential equation solver like dde23 instead.
추가 답변 (1개)
Sulaymon Eshkabilov
2021년 6월 1일
Hi,
As if I undertood your question correctly, you'd like to save and display simulation iteration process, correct?
If this is the case, you can employ this syntax:
[t, Sol]=ode45(@(t,u)????, [0, ????], ICs, OPTs)
Or an alternative way:
Sol = ode45(@(t,u)????, [0, ????], ICs, OPTs) % Sol is a structure contains lots of data
댓글 수: 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!