How to use changing logical states in a MATLAB intregrator
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Ícar
el 2 de Jul. de 2021
Comentada: Ícar
el 2 de Jul. de 2021
Hello, I would appreciate any help on the following problem:
In a nutshell:
- I need to make an integrator like ode45() to access a variable during integration whose value is changed during integration
More in detail:
I'm trying to integrate a vector field such as with an integrator like ode45(). During the integration, at each step t(i) I need to edit a vector that contains boolean values, for example:
vec is declared in the main as vec = logical([0 0 0]');
- Step t(1): perform computations inside and assign vec(2) = true
- Step t(2): perform computations inside and assign vec(2) = false
- Step t(2): perform computations inside and assign vec(1) = false
- ...
The issue is that I need to keep the information on what are the components of vec between steps (e.g. from step t(2) to step t(3) I'd need to know the values of vec([1,2,3]). MATLAB can access a variable declared in the main during the ODE integration but it cannot modify it.
I've tried to introduce the components of vec as states in x, but that is a problem because their derivative can't be specified as .
How would you recommend me to approach this problem?
Thank you very much.
2 comentarios
Steven Lord
el 2 de Jul. de 2021
What is the mathematical form of the differential equations that you're trying to solve? How is this vec vector used in those equations?
How do you want to handle changes to your vec vector when the ODE solver tries to take a step, realizes that step does not satisfy the tolerances, rejects the step, and takes a smaller step?
Respuesta aceptada
Steven Lord
el 2 de Jul. de 2021
It sounds from your description that the solution to your system of differential equations at a given time depends on the solution of the system at an earlier time. If that's the case you have a delay differential equation rather than an ordinary differential equation and you should use dde23, ddesd, or ddensd instead of an ODE solver like ode45. See this category in the documentation for more information about these functions and several examples
Más respuestas (0)
Ver también
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!