The entries in tspan must strictly increase or decrease. ode45 Issues
21 views (last 30 days)
Show older comments
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.
0 Comments
Answers (2)
Walter Roberson
on 1 Dec 2018
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.
0 Comments
See Also
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!