How to delay a state derivative using ode solvers in MATLAB

Hello,
I would like to ask how it is possible to add a delay on the derivatives of the states that are being used inside a set of equations.
A simple random example to clarify what I mean:
function dz = example(t,z)
k = 2;l = 1;Is = 1;
x = z;
A = sin(x_dot)*l;
B = A*k;
x_dot = 1/Is*B;
dz = x_dot;
end
The above example in Simulink is quite simple to implement because we have the memory block to use for the x_dot. How could I implement the same in MATLAB? I thought of using a first order delay such as x_star_dot_dot = 1/tau*(-x_star_dot+x_dot), but I am not sure if this is the appropriate way to do it.
Many thanks
EDITED:
After Steven Lord's comment, here is a simple example of equations in which in order to find side slip angular velocity I need to know it beforehand.

5 commentaires

What context would this be used in? There are ways using persistent variables, but it is common for it to turn out that the calls do not get executed in the order you expect, depending how you use the function.
I want to solve the ode so it would be called by an appropriate solver (e.g. ode23).
Can you show us a sample of the mathematical equations you're trying to solve? It does sound to me (like it did to Walter) that you have a system of delay-differential equations for which the DDE solvers (like dde23 are the right tool.) You can use the LaTeX button (the summation symbol in the Insert section of the Toolstrip for the comment editor) to enter the equations as equations rather than as code.
Enter \frac{dy}{dt} = t \cdot y(t) to get as an example.
Thank you Steven for the recommendation, I have written another more realistic simple example illustrating my question.
I'm curious about these equations. Usually, the equations of motions for an air vehicle do not exhibit an algebraic loop for the sideslip dynamics, at least to my undestanding. Would you mind providing a bit more insight into the source of these equations?

Connectez-vous pour commenter.

 Réponse acceptée

patr chri
patr chri le 1 Juin 2022
For people with similar questions, one way to approach the solution to this loop is to use a dummy first-order-delay ode. For the specific example of the question, I did the following and I am able to get the same results as with Simulink (with a very small tau):

Plus de réponses (1)

Walter Roberson
Walter Roberson le 31 Mai 2022
I just noticed that you intend to use this with the ode solvers.
The answer is that using this with the ode solvers would violate the mathematics used for predictions, and you would get the wrong result or error.
Using persistent cannot help you for this purpose, as your function is evaluated 6 times with different times and boundary conditions for each successful step, and the "previous" call might be for different conditions with different hypothesized derivatives.
What you need to do is use dde23 or similar.

10 commentaires

I found dde23 while I was searching for an answer, but I am not able to see how it fits with my problem. I do not have a delay in the states used in my equations, but a delay used in the derivatives.
Maybe actually the only way to approach this is to use a dummy first order equation on the state derivative with very fast settling time.
I suggest you read the SIMULINK documentation about how such a delay is mathematically modelled.
I am not able to go under the mask for the memory/delay blocks.
Torsten
Torsten le 31 Mai 2022
Modifié(e) : Torsten le 31 Mai 2022
Suppose you need x'(t-2) then make a state that you output the value of x'' to, and the corresponding state as input would be the integral of that, x' . States are not restricted to correspond to distinct physical quantities such as distance: it is valid and common for velocity (derivative of distance) to have its own state, and in some contexts it makes sense for acceleration to have its own state (when acceleration changes over time... rocket for example.)
In order to make a derivative for x'(t-2) I need to know something about it and I do not in the problem I am trying to solve. What I mean is that in order to do that I need to create a dummy first order equation with very fast dynamics (like an analytical derivation) to achieve this. I thought of this but I was not convinced that it is the only way to achieve what I want. So my question was that maybe there is a memory/delay (or a much more convenient way programmatically) to achieve what I want in MATLAB (similar to the very convenient way of Simulink).
@Torsten thank you for the recommendation but I do not think this is useful to this particular problem
The memory/delay is to make the information into a state and use dde23 or equivalent.
If you have incoming information that you cannot characterize through its derivative then that would likely violate the conditions needed for Runge Kutta methods to work. dde23 has support for some cases of singularities that ode*() cannot handle.
To be explicit, there is no available memory/delay mechanism for the ode* routines, and such a mechanism would be incompatible with the way ode*() routines calculate.
RK methods essentially do a polynomial fit at carefully selected locations near the current boundary. Those carefully selected locations do not have a "history" to go back to. They are not points that are expected to be gone to in the future: they are chosen to provide information about the local slope. Sort of like sweeping a flashlight in a regular pattern as you walk in the dark, you do not expect to travel through most of the points you light up, but you use the information to figure out the best route. (And every once in a while there is a tree in the way and you do end up going through the bramble bush as the best of not-great choices.)

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Centre d'aide et File Exchange

Produits

Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by