Can I select the number of points in which ode45 is evaluated?
20 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jaime De La Mota Sanchis
le 17 Déc 2019
Commenté : Star Strider
le 17 Déc 2019
Hello everyone. I am currently trying to propagate an optimization problem by using the control and the initial conditions of the state variables as inputs and the derivatives of the state variables as differential equations using ode45. However, my results are not as good as I would like them to be. I have checked my whole code exhaustingly but I have not found the source of the problem. Now I want to test if this error arises from the fact that the number of nodes in the model is smaller than the number of points in which the ODE is evaluated. For that, I need to evaluate the diferential equation in exactly the nodes of the optimization problem. I however don't know how to do that, since I am following an example. I have searched the documentation but I haven't found how to do it.
My code is as follows:
x0=[x1initial; x2initial; x3initial; x4initial];
tspan=[tinitial tfinal];
[t, x]=ode45(@(t,x) model_evolution(t,x),tspan, x0);
In the prevoius lines the initial conditions and time span are defined and the differential equation solved in the points defined by t, which does not equal the points in which the optimization model has been evaluated. Inside of model_evolution the different control variables and time evolution are read as
u1d1= textread('thrustModelOutput.txt');
and so on. Then, the matrix of control is constructed as
u(1)=interp1(time,u1d,t,'linear');
and so on.
Then, the different state variables are propagated as
xdot(1)=((x(1)*(sqrt(2*x(3)*g0/(constant1*constant2)))*sin(x(4)) )/cos(x(2)));
and so on.
So, if someone can give me some advice on how to evaluate my xdot variables not at the points defined by t but instead in the same points in which I have values I would be extremely thankfull.
Regards.
Jaime
0 commentaires
Réponse acceptée
Star Strider
le 17 Déc 2019
See the documentation section on ‘tspan’. Use the multiple-element ‘tspan’ argument, with the elements correspoinding to the nodes of interest. The differential equations are evaluated at many more values than those points, however they are only returned for the points that correspond to the ‘tspan’ vector in that situation.
2 commentaires
Plus de réponses (0)
Voir également
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!