ode45 with a function that change with time

조회 수: 8 (최근 30일)
Nashira
Nashira 2016년 6월 23일
댓글: Nashira 2016년 6월 24일
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

답변 (1개)

Mischa Kim
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
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.
Nashira
Nashira 2016년 6월 24일
So, it is not possible to change the integrated function in ode45, I have to use 2 ode45 and merge the final graph... ok! thank you for your answers and suggestions!

댓글을 달려면 로그인하십시오.

카테고리

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