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.
0 个评论
回答(2 个)
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.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!