ode45 with a function that change with time
2 次查看(过去 30 天)
显示 更早的评论
I have a body that is subjected to an acceleration for a time duration of "tp". After this time the acceleration go to zero and the velocity is constant. So I have introduced an if on the velocity value. The problem is that the result is not a step: I have a transitory before obtain a constant value for the velocity. In the follow you can read the code:
Main:
v = 0; %m/s initial velocity
x = 0; %m initial position
X0 = [x,v]; %initial status
time = 0:0.0001:10; %integration time
[t,X] = ode45(@int,time,X0);
Function:
v= sqrt(K/m)*d;
j= X(2)
if j<v F = K*d;
else F = 0;
end
dX = zeros(2,1);
dX(1) = X(2);
dX(2) = F/m;
Thank you in advance for any suggestion
0 个评论
回答(1 个)
Mischa Kim
2016-6-24
Nashira, one approach is to use two different ode functions. Use the first one to integrate over the time interval [0,tp] and the second one for the interval [tp,10]. The initial conditions for the second integration are the final conditions of the first.
2 个评论
Torsten
2016-6-24
@Mischa Kim: Although the OP claims that the equations change at time tp, the code indicates that this time instant is unknown in advance. I suggest to use the event facility of ODE45. The ballode example in the documentation is a good starting point.
Best wishes
Torsten.
另请参阅
类别
在 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!