solution to 2nd order ode having time varying coefficients using RK4 steps in Matlab
4 views (last 30 days)
Show older comments
Hello everybody, I am trying to solve a 2nd order ODE using RK4. The coefficients are time dependent and assume new values after a fixed time interval and needs to be updated from the solution to previous steps. I think I have to use a loop. Can I connect this to any standard suite like ode45? Or do I need to write down the RK4 algorithm in steps and then use a loop counter?
Note: The fixed time interval can be same as the stepped time interval we use while solving the ode suite.
Generally any IVP evolves with time for a given set of coefficients. In this case if the coefficients themselves were to change every second will I be able to capture the transient dynamics or I need to go for a time step one order lower with the ode suite to capture the dynamics? Then how do I run a loop along with the suite like ode45?
Thank you.
2 Comments
James Tursa
on 16 Apr 2020
Please tell us more about the time varying nature of the coefficients. Are they step functions? Do they happen based on some event? Are they functions of the state vector? Etc.
Can you provide an example of how they change?
Answers (1)
Ameer Hamza
on 15 Apr 2020
Edited: Ameer Hamza
on 15 Apr 2020
ode45 is capable of handling time-varying parameters. See this example for details: https://www.mathworks.com/help/matlab/ref/ode45.html#bu3l43b
You don't need to write a loop yourself. Just modify the parameter inside the ODE function according to your requirement.
3 Comments
Ameer Hamza
on 16 Apr 2020
Can you clarify what do you mean by "time varying coefficients updated based on previous solution steps"? Can you give an example of the ODE system?
See Also
Categories
Find more on Ordinary Differential Equations 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!