Borrar filtros
Borrar filtros

Update ODE45 in realtime

1 visualización (últimos 30 días)
Steven Taggart
Steven Taggart el 27 de Ag. de 2017
Comentada: Walter Roberson el 27 de Ag. de 2017
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 comentario
Jan
Jan el 27 de Ag. de 2017
Note: There are no "IF loops" in any programming language I know. In consequence I cannot imagine, how this could be applied "easily".

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 27 de Ag. de 2017
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.
  2 comentarios
Steven Taggart
Steven Taggart el 27 de Ag. de 2017
Hi Walter,
I usually turn off the force after a certain time and the function continues until the end of the problem with no issues. It is a spring-mass-damper system and the force is pressing against the mass to compress the spring. After a certain amount of time the force is turned off and the spring would over come the flow force and close the valve. What I would like to do is turn off this force after the spring is compressed to a certain value instead of doing it like I am currently doing by stopping the force after a certain amount of time.
Kind regards
Steven
Walter Roberson
Walter Roberson el 27 de Ag. de 2017
You need an event function.

Iniciar sesión para comentar.

Categorías

Más información sobre Ordinary Differential Equations en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by