Problem in solving differential equation

Click For Summary

Discussion Overview

The discussion revolves around the challenges of solving a differential equation related to a driven damped anharmonic oscillator within chaotic systems. Participants explore the impact of varying timestep sizes on the accuracy and stability of numerical simulations, particularly in the context of chaotic dynamics.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant notes discrepancies in results when using different timesteps (10^5, 10^6, and 10^7), questioning the independence of solution accuracy from timestep size.
  • Another participant explains that long-time integrations of chaotic systems are challenging due to their sensitivity to initial conditions, suggesting that increased timesteps can lead to more round-off errors.
  • A participant suggests that while a timestep of 10^6 may be theoretically optimal, results from a timestep of 10^7 appear more consistent over a range of values, although they express uncertainty about its appropriateness.
  • One participant introduces the concept of "rigid" systems with multiple time constants and recommends exploring different numerical integration methods, such as rk4 or multi-step methods like Adams-Moulton or Adams-Bashforth.

Areas of Agreement / Disagreement

Participants express differing views on the optimal timestep size and its impact on solution accuracy, indicating that multiple competing perspectives remain unresolved.

Contextual Notes

Participants mention the potential for numerical errors with large timestep sizes and the need for careful selection of integration methods, but do not reach a consensus on the best approach or specific timestep recommendations.

Oliver321
Messages
59
Reaction score
5
Hello everyone!
I was studying chaotic systems and therefore made some computer simulations in python. I simulated the driven damped anhatmonic oscillator.

The problem I am facing is with solving the differential equation for t=0s-200s. I used numpy.linspace(0,200,timesteps) for generate a time scale. I did this for three different timesteps: 10^5,10^6 and 10^7. For every timestep i get different results, and they jump between one another. If I increase it further, it changes again (see pictures).

Now I was wondering what was going on here! I thought the accuracy of the solution should be independent of the timesteps? If not, I can conclude: As I increase the timesteps, the result gets more accurate and if I increase it to high, there are going to be numerical errors. But how could I tell which solution is the right one? Shouldn’t 10^6 steps be enough?

Thanks for every answer!
[CODE lang="python" title="Python code"]from scipy.integrate import odeint
import numpy as np
import matplotlib.pyplot as plt
import scipy.signal as sig

F=63
xv0=[4.346,0]


res=10000000
tmax=200
t=np.linspace(0,tmax,res)
t2=np.linspace(0,250,res)
w=2

def ddp(xv,t):
x=xv[0]
v=xv[1]
b=0.3
x2=-x-x**3-b*v+F*np.cos(w*t)
return v,x2
x=odeint(ddp,xv0,np.linspace(0,50*2*np.pi/w,1000))
xv0=[x[-1,0],x[-1,1]]

x=odeint(ddp,xv0,t)
x2=odeint(ddp,xv0,t2)
n=int((res/tmax*2*np.pi/w))
peak,_=sig.find_peaks(-1*x[:,0],4)
x_s=np.take(x[:,0],peak)
v_s=np.take(x[:,1],peak)
t_s=np.take(t,peak)

fig, axs = plt.subplots(ncols=2,figsize=(12,4.8))
axs[0].plot(x2[:,0],x2[:,1],linewidth=0.5)
axs[0].plot(x_s,v_s,'.r',markersize='1')
axs[0].set(xlabel="x",ylabel="v")
axs[1].plot(x[:,0],x[:,1],linewidth=0.5)
axs[1].plot(x_s,v_s,'.r',markersize='3')
axs[1].set_xlim([-6.5,-4])
axs[1].set(xlabel="x",ylabel="v")
plt.ylabel('v')
#plt.savefig('phase_plot',dpi=300)
plt.show()
[/CODE]
 

Attachments

  • 10^6.png
    10^6.png
    47.3 KB · Views: 240
  • 10^5.png
    10^5.png
    44.2 KB · Views: 226
  • 10^7.png
    10^7.png
    52.1 KB · Views: 238
Last edited by a moderator:
Technology news on Phys.org
Oliver321 said:
Now I was wondering what was going on here! I thought the accuracy of the solution should be independent of the timesteps? If not, I can conclude: As I increase the timesteps, the result gets more accurate and if I increase it to high, there are going to be numerical errors. But how could I tell which solution is the right one? Shouldn’t 10^6 steps be enough?

Long time integrations of chaotic systems are very difficult, precisely because they are chaotic: For few time steps (large step size), the algorithm is usually not accurate enough. Increasing the number of time steps leads to more floating point calculations, so more round-off errors, and the effect of these is amplified by the chaotic nature of the system ("sensitive dependence on initial conditions").

For certain systems, you can use specialized integrations, e.g. symplectic integrators for chaotic Hamiltonian systems, but your system is dissipative. You should in any case compare different integrators, vary the step sizes (as you already did), and see if you can discover consistent behavior among integrators, for step sizes that are somewhere between "not too lange" and "not too small".
 
  • Informative
Likes   Reactions: Oliver321
Thank you very much, this is helping me a lot! Unfortunately I am very inexperienced in this topic.
At one hand, the step size 10^6 would be optimal from a theoretical standpoint (the Lorenz section would (if plotted in the right way) represent a u-sequence). On the other hand result of stepsize 10^7 would be more constant over a long range of the stepsizes. But maybe this is to large.
Could you give me a clue what you think would be a optimal range?

Edit: I now tried it with different solvers, and it seems that the plot from stepsize 10^7 is most accurate!
 
Last edited:
  • Like
Likes   Reactions: S.G. Janssens
The optimal time step would be related to the time constant of you system. Systems with multiple time constants that have a large separation are called "rigid", iirc, and don't behave well with numerical integration. You can try rk4, or multi step methods such as adams-moulton or adams-bashforth.
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
4
Views
2K