Update ODE45 in realtime
2 次查看(过去 30 天)
显示 更早的评论
Hello,
I am using the ODE45 solver to simulate the dynamic behaviour of a valve. I am facing a problem, I wish to alter some of the values within the script passed to ODE45 after a certain condition. When the valve opens to a certain value I would like to close off the force that holding it open. The opening height is part of the output vector of the ODE script, it is a value in the script id like to change. This would be easily done with a IF loop however as the script refreshes every cycle the loop is not really effective in this sense.
My question is, the value of the ODE script output (in this case the valve opening) is stored as part of a array, is there anyway to access this in real time so I can update my script once a certain threshold value has been reached in the output array?
I'm not sure if that is well enough explained but any help would be much appreciated!
Kind regards
Steven.
1 个评论
Jan
2017-8-27
Note: There are no "IF loops" in any programming language I know. In consequence I cannot imagine, how this could be applied "easily".
回答(1 个)
Walter Roberson
2017-8-27
No, you cannot do that. But it would not be a good idea if you could do it.
The ode*() routines will miscalculate if your function is not continuously differentiable twice more than you code. If your function is not continuously differentiable once more than what you code, then usually the function will detect that and spend a lot of time trying to find the exact boundary under the hypothesis that it is differentiable but that the algorithm is just having numeric problems. If your function is once continuously differentiable but not twice continuously differentiable then it might not notice the discontinuity but you will typically just get wrong answer.
When you turn off a force abruptly then your function is not continuously differentiable there, and the ode*() routines will often notice and fail at that point.
So, what you need to do is to create an event function that detects that condition under which the force is to be turned off and signals that the ode*() is to be terminated. Then you examine the outputs to get the boundary conditions and time values, and you call ode*() again to start from that point, this time with the force turned off.
另请参阅
类别
在 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!