Is it Possible to Solve a Coupled System of ODEs with ODE45 in MatLAB?

  • Context: MATLAB 
  • Thread starter Thread starter Niles
  • Start date Start date
  • Tags Tags
    Matlab Ode45
Click For Summary

Discussion Overview

The discussion revolves around solving a coupled system of ordinary differential equations (ODEs) using the ODE45 function in MATLAB. Participants explore issues related to integration stability, time intervals, and the effects of rapid rates in the equations on the solver's performance.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant describes a coupled system of ODEs and reports that MATLAB's ODE45 does not yield results, possibly due to rapid rates in the equations.
  • Another participant suggests reducing the time interval significantly to avoid instability, indicating that the presence of a large constant (1e9) may lead to exponential functions that require very small time steps.
  • A participant mentions that switching from ODE45 to a solver ending in "s" might allow for larger step sizes without instability.
  • One participant reports that after trying a smaller time interval, the solution still blows up when the Heaviside function changes, but switching to ODE23 yields results quickly.
  • Another suggestion is made to split the integration into two parts to handle the Heaviside step function more accurately, proposing the creation of two versions of the ODEs to manage the transition at the step function's edge.
  • A participant expresses frustration after receiving a warning about integration tolerances when attempting to extend the system of ODEs, questioning the effectiveness of changing solvers.

Areas of Agreement / Disagreement

Participants express differing opinions on the best approach to solve the coupled ODEs, with no consensus reached on a definitive solution. Some suggest modifying the time intervals or switching solvers, while others highlight the challenges posed by the Heaviside function and rapid rates.

Contextual Notes

Participants note limitations related to the stability of the ODE45 solver, particularly in relation to the large constants in the equations and the behavior of the Heaviside function. There are unresolved issues regarding integration tolerances and the effectiveness of different solvers.

Niles
Messages
1,834
Reaction score
0
Hi

I am trying to solve a simple set of coupled ODE's by ODE45. The coupled system is given by:
Code:
function xprime = eoms(t, x)

xprime = [
    1e9 + 5.0e4*x(3) - 50*x(1);
    4.0e1*x(1) - 3.3e3*x(2);
    2.0e3*x(2) - 5e4*x(3) + 3.5e7*heaviside(t-1)*x(4);
    1.0e3*x(2) - heaviside(t-1)*5.0e7*x(4)];

I solve it using the following command:
Code:
x0 = [0 0 0 0];
tspan = [0, 2];
[t, x] = ode45(@eoms, tspan, x0);
However when I compile MatLAB just keeps calculating, it doesn't give me a result. Maybe it is due to the very rapid rates in the equations. Do I have any options here, or am I not able to solve for the transient behavior?

Thanks in advance.


Niles.
 
Physics news on Phys.org
Try mkaing the time interval much smaller, for example 0 to 1e-8, and see what happens. If that works, try increasing the interval (say by factors of 10) till it blows up.

Since you have a constant of 1e9 in your definition of xprime, it's likely the solution contains functions similar to exp(1e9 t) or exp(-1e9 t). A conditionally stable integration method like ODE45 may need need to take time steps of smaller than 1e-9 to avoid going unstable. It may not be able to find a suitable step length, and even if it does, more than 109 steps may take a long time.

You mgiht have more luck changing ODE45 to one of the solver names ending in "s", which should work with a bigger step size without blowing up.
 
AlephZero said:
Try mkaing the time interval much smaller, for example 0 to 1e-8, and see what happens. If that works, try increasing the interval (say by factors of 10) till it blows up.

Since you have a constant of 1e9 in your definition of xprime, it's likely the solution contains functions similar to exp(1e9 t) or exp(-1e9 t). A conditionally stable integration method like ODE45 may need need to take time steps of smaller than 1e-9 to avoid going unstable. It may not be able to find a suitable step length, and even if it does, more than 109 steps may take a long time.

You mgiht have more luck changing ODE45 to one of the solver names ending in "s", which should work with a bigger step size without blowing up.

Thanks for taking the time to reply. I have actually already tried your first suggestion, and it blows up as soon as the Heaviside step-function is different from 0. I also suspected that. I tried changing ODE45 to odes23, and now the solution pops up almost instantly! Wow, that is really good. Thanks!Niles.
 
Niles said:
I have actually already tried your first suggestion, and it blows up as soon as the Heaviside step-function is different from 0.

In that case, you can probably solve it with ODE45 by splitting it into two parts 0 to 1 and 1 to 2, so you force one time point to be exactly on the "edge" of the step function at t = 1.

You might need to make two versions of xprime with and without the step function included, so in effect you have heavisde(0) = 0 at the end of the first half of the solution, and heavisde(0) = 1 at the start of the second half.

That might give you a more accurate solution than odes23, which will "round off" the edge of the step a bit, in order to keep going.
 
Last edited:
Thanks for helping, that is kind of you. I tried extending the system of ODEs, but I get the message:

Warning: Failure at t=1.000000e+000. Unable to meet integration tolerances without reducing the step size below the smallest value allowed (3.552714e-015) at time t.

Something tells me choosing a different solver won't help me here. And I can't even change the time-step. Do I have any alternatives left?


Niles.
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 5 ·
Replies
5
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 2 ·
Replies
2
Views
3K