ode45 with a function that change with time
1 回表示 (過去 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!