ode45 with a function that change with time

7 visualizzazioni (ultimi 30 giorni)
Nashira
Nashira il 23 Giu 2016
Commentato: Nashira il 24 Giu 2016
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

Risposte (1)

Mischa Kim
Mischa Kim il 24 Giu 2016
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 Commenti
Torsten
Torsten il 24 Giu 2016
@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 il 24 Giu 2016
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!

Accedi per commentare.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by