Can I select the number of points in which ode45 is evaluated?

조회 수: 84 (최근 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];
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

채택된 답변

Star Strider
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.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by