ode45 and rungekutta yield different result
Show older comments
I am using ode45 and rungekutta script to solve some piecewise differential equations. But the result is a bit different.
Can anyone help me to solve the problem? I am hoping to get a similar result as ode45.
Thanks,
5 Comments
Sam Chak
on 10 Jul 2022
Didn't check your dynamical equations due to code clutter issue.
Is it a piecewise smooth dynamical system, or a piecewise discontinuous system?
If your rungekutta code is 100% correct and is expected to return output similar to the ode45 solver, then I guess something is missing in the dynamical system.
haohaoxuexi1
on 10 Jul 2022
haohaoxuexi1
on 10 Jul 2022
First change your Runge-Kutta code such that both ODE45 and your code can use the same function "SDOFFriction" to compute the derivatives.
Then someone might invest the effort to compare the codes.
haohaoxuexi1
on 10 Jul 2022
Accepted Answer
More Answers (1)
Jan
on 10 Jul 2022
The function to be integrated contains:
if abs(vrel)/v_band<0.001
...
if abs(faply)<uS*Fn
This looks like this function is not smooth. Matlab's ODE integrators are designed to handle smooth functions only. Otherwise the step size controller drives mad and the final value is not a "result" anymore but can be dominated by accumulated rounding errors.
A fixed step solver runs brutally over the discontuinuities. It depends on the function and stepsize, if the calculated trajectory is "better" or "worse" than the trajectory calculated with a step size controller. From a scientific point of view, both methods, fixed step RK and ODE45 without detection of discontinuities are expensive random number generators with a weak entropy.
Don't do this for scientific work. Use a stepsize controlled integrator and stop/restart the integration at each discontinuitiy to recondition the controller.
4 Comments
haohaoxuexi1
on 10 Jul 2022
haohaoxuexi1
on 29 Jul 2022
Edited: haohaoxuexi1
on 29 Jul 2022
Torsten
on 29 Jul 2022
All deterministic ODE integrators assume that the function to be integrated is at least differentiable. They can't cope with stochastic inputs.
Look up "Stochastic Differential Equations" if you want to define some inputs as random variables.
haohaoxuexi1
on 30 Jul 2022
Categories
Find more on Programming in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
