matlabtimeconditional-statementsodeacceleration

Solving an 2nd order ODE with internal conditions - Matlab


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

  • Since you mention

    ode45 is the ODE solver, but another one could be used.

    And your concern (it seems to me) is having access to the history such that you can evaluate d^2x/dt^2 yourself, to introduce the new conditions, have you considered looking into dde23 (delayed diffeq)?

    From the documentation, you specify a vector of lag times yourself, and have the option to specify history as "...the previous solution from an integration, if this call continues that integration" https://www.mathworks.com/help/matlab/ref/dde23.html.

    Hopefully this is helpful since, at the very least you should be able to make a workaround by wrapping your own function that returns the values from the dde23 solutions and check the point you should introduce the new conditions yourself, and then specify the new function, compiling your results as necessary, essentially reducing the problem into more steps.