How to delay a state derivative using ode solvers in MATLAB
Afficher commentaires plus anciens
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
Walter Roberson
le 31 Mai 2022
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.
patr chri
le 31 Mai 2022
Steven Lord
le 31 Mai 2022
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.
patr chri
le 1 Juin 2022
Paul
le 1 Juin 2022
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?
Réponse acceptée
Plus de réponses (1)
Walter Roberson
le 31 Mai 2022
0 votes
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
patr chri
le 31 Mai 2022
patr chri
le 31 Mai 2022
Torsten
le 31 Mai 2022
I suggest you read the SIMULINK documentation about how such a delay is mathematically modelled.
patr chri
le 31 Mai 2022
Does this help ?
Walter Roberson
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.)
patr chri
le 1 Juin 2022
patr chri
le 1 Juin 2022
Walter Roberson
le 1 Juin 2022
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.
Walter Roberson
le 1 Juin 2022
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.)
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!