The entries in tspan must strictly increase or decrease. ode45 Issues

21 次查看(过去 30 天)
Hello all,
I am writing a script for a missile simulation, where a missile flies from a given altitude and strikes the ground. Initial conditions are X0=[x; y; z; xdot; ydot; zdot]. XYZ are coordinates and the dots are the velocities.
I have to make a function for the derivative of X0, which is then integrated by ode45 to make a new X, which is put back through the script over and over until the missile strikes the ground.
function xDot = dxdt(t,X)
xDot = [X(4,1);X(5,1);X(6,1);A(1,1);A(2,1);A(3,1)]
end
For the first iteration of the above function, X is the initial condition X0. xDot is equal to the velocity components in the X, and accelerations denoted by A.
The ode45 function must follow this form.
[time,X]=ode45(@dxdt,[t t+dt],X0);
The time interval for this simulation is only 5 seconds, with increments of 0.01 seconds.
How can I make this function continually iterate, making a new vector X, finding the xDot of that X, then putting it through the ode45, and so on, for possibly 20 iterations?
t=[0 10]
dt = 0.01
tspan= [t t+dt]
[t,X]=ode45(@dxdt,tspan,X0)
This gives the error
Error using odearguments (line 87)
The entries in tspan must strictly increase or decrease.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in V2_0 (line 20)
[t,X]=ode45(@xDot,tspan,X0)
Please help.

回答(2 个)

madhan ravi
madhan ravi 2018-12-1
编辑:madhan ravi 2018-12-1
tspan= t(1):dt:t(end);

Walter Roberson
Walter Roberson 2018-12-1
tspan= t + [0, dt];
Note: instead of looping, you should consider using an ode event function to detect when the ground is hit and terminate then.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by