Borrar filtros
Borrar filtros

Efficiently evaluating ODE event that depends on only some variables

2 visualizaciones (últimos 30 días)
Roy Goodman
Roy Goodman el 4 de Dic. de 2023
Comentada: Roy Goodman el 4 de Dic. de 2023
I'm simulating an N-body problem in the plane.
I want to know when the three particles that are closest to each other are collinear. (Supposing I have a MATLAB function that identifies the "three closest particles.")
Suppose that I have a function f(z1,z2,z3) that vanishes when the particles z1, z2, z3 are collinear.
Right now my simulation evaluates a vector containing all triples of particles and records all the times any triple is collinear.
Then at the end of the run, I sort through all the events and throw away all the ones where the particles are not "the three closest."
I would rather compute this during the ODE simulation and not afterward. I'd like to construct a new event g that gets triggered whenever f(z1,z2,z3)=0 and z1, z2, and z3. are the closest.
The events construct doesn't seem well-suited to this situation, since it detects zero crossings and the second half of my event is just a boolean. Is there a workaround?

Respuestas (1)

Torsten
Torsten el 4 de Dic. de 2023
Editada: Torsten el 4 de Dic. de 2023
Use OutputFcn to check your condition after each successful time step.
But I think it will be difficult to check for complanarity for a time-dependent system. It's like checking if a variable equals 0 - floating point arithmetic and the discrete time stepping will hinder to correctly detect such events.
  1 comentario
Roy Goodman
Roy Goodman el 4 de Dic. de 2023
At first, I thought this answer made sense, but after thinking it through, I'm not sure.
The particles are evolving in the plane, so I'm not trying to test for complanarity, only for triplet wise collinearity. That's easy, because three particles with positiions are collinear whenever where . That's the definition of my function f above.
So, I can define events easily. The problem is that I find too many of them because I only care about the collinearity of the threenearest particles.
outputFcn works after successful steps but I'm looking for something that works better with events.
Perhaps I'm missing something.

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by