# using ODE45 with condition

1 visualización (últimos 30 días)
February el 3 de Mzo. de 2015
Respondida: Andrew Newell el 3 de Mzo. de 2015
The problem I am dealing with is a circuit with diode. so I have two different differential equations to solve based on a variable value measured at each time step. what I want to achieve is to run first ode45 and calculate a variable value (different from output) and if that value < threshold, continue running first ode45. Otherwise, run 2nd ode45. same with 2nd ode45.
so I guess what I want to do is having two different "states" (1st ode45 and 2nd ode45) and which to run is determined by the current variable value. how can I achieve this? how can I make ode45 evaluate a value at each time step other than output?
thank you.
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

Iniciar sesión para comentar.

### Respuestas (1)

Andrew Newell el 3 de Mzo. de 2015
You can use event location to run ode45 on one equation until you reach the threshold, at which point the solver stops. Then you'd call ode45 again to solve the other equation, starting where you left off (see the link for examples).
##### 0 comentariosMostrar -2 comentarios más antiguosOcultar -2 comentarios más antiguos

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