matlabpositionodeacceleration

Solving 2nd order ODE, Matlab- the acceleration in the equation needs its own value in order to include another different term


I have this 2nd order ODE to solve in Matlab:

(a + f(t))·(dx/dt)·(d²x/dt²)  +  g(t)  +  ((h(t) + i(t)·(d²x/dt² > b·(c-x)))·(dx/dt)  +  j(t))·(dx/dt)²  +  k(t)·(t > d)  = 0

where

and notice the two conditions that

So, the problem could be solved with a similar structure in Matlab as this example:

[T,Y] = ode45(@(t,y) [y(2); 'the expression of the acceleration'], tspan, [x0 v0]);

where

Some issues that could help:

Thank you in advanced !


Solution

  • First of all, you should reduce your problem to a first-order differential equation, by substituting dx/dt with a dynamical variable for the velocity. This is something you have to do anyway for solving the ODE and this way you do not need to access the previous values of the velocity.

    As for realising your conditions, just modify the function you pass to ode45 to account for this. For this purpose you can use that d²x/dt² is in the right-hand side of your ODE. Keep in mind though that ODE solvers do not like discontinuities, so you may want to smoothen the step or just restart the solver with a different function, once the condition is met (credit to Steve).