ode45 with a function that change with time
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Mischa Kim
el 24 de Jun. de 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 comentarios
Torsten
el 24 de Jun. de 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.
Ver también
Categorías
Más información sobre Ordinary Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!