Can I select the number of points in which ode45 is evaluated?
조회 수: 42(최근 30일)
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.
Star Strider 2019년 12월 17일
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.