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];
[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
and so on. Then, the matrix of control is constructed as
and so on.
Then, the different state variables are propagated as
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.