Approximating sharp changing time dependent term for use with ODE solver

1 view (last 30 days)
Hello,
I have time dependent terms in my problem, an example being temperature, that are given as being linearly interpolated between N points. I have tried to model in a few ways, including polyfit, smoothingspline and even a feedforward neural network. The polynomial (been using polyfit(x,y,5) is by far the fastest and never cause the solver to struggle, but it is not an accurate representation. The spline is sufficiently accurate, but the solver can struggle at certain points, even when adjusting the smoothness parameter. It is not consistant enough. The neural network is a perfect fit, but the ode solver barely progress where the time dependant terms changes sharply. PIecewise interpolation obviously does not work.
So my question, are there other alternatives to these, which would be as fast and more importantly consistant as the polynomial, but more accurate, like the spline fit. Any suggestions that I could try out are helpful. The two solutions I can think of are:
1. Increase the degree of polynomial fit, n, as I know the start and end times, so a bad fit outside the range does not matter.
2. Split the problem up and solve between the all points from all time dependent variables. The resulting linearly increasing and decreasing terms should not cause any problems to the solver.

Answers (1)

Star Strider
Star Strider on 25 Oct 2021
The documentation secion on ODE with Time-Dependent Terms uses interp1 that also has a number of different methods to do the interpolation. It was not previously mentioned in the original post, so I include it here for reference.
With respect to the regions ‘where the time dependant terms changes sharply’ it would likely be best to stop the solver, save the last rows of the output time vector and result matrices as the new starting time and initial conditions, and re-start it on the ‘other side’ of the discontinuity.
.
  2 Comments
RaFa
RaFa on 25 Oct 2021
Edited: RaFa on 25 Oct 2021
Thank you, you put my thoughts into words. My 2nd solution was to indeed split up the time span into smaller intervals between the discontinuities and iteratively run the solver until the end.

Sign in to comment.

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!