Given an ode $x'=e^{-x}\sin(x)$, initial condition is $x(0)=-2\pi$. Why the x(t) is not a straight line in the graph x vs t?

76 Views Asked by At

Question:

Given an ode $x'=e^{-x}\sin(x)$, initial condition is $x(0)=-2\pi$. Why the x(t) is not a straight line in the graph x vs t?

Thoughts:

I found out the fixed points, $x=-2\pi$ is one of the unstable fixed points. Which means the velocity is 0 at that point.

Which means if its initially there, it should never move. Then it should be a straight line in the graph. Am I correct?

Situation:

But when I draw it in python its not the case::

import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

# function that returns dx/dt
def dxdt(x, t):
    return np.exp(-x)*np.sin(x)

# time points
t = np.linspace(0,20, 100)

plt.rcParams['figure.figsize'] = [15, 6]
fig, ax = plt.subplots(1)

# initial condition
x0 = -2*np.pi
# solve ODE
x = odeint(dxdt,x0,t)

# plot results
ax.plot(t, x)

ax.set(xlabel='time', ylabel='x(t)')
import matplotlib.ticker as tck
ax.yaxis.set_major_formatter(tck.FuncFormatter(
   lambda val,pos: '{:.0g}$\pi$'.format(val/np.pi) if val !=0 else '0'
))
ax.yaxis.set_major_locator(tck.MultipleLocator(base=np.pi))

x0=-2pi

For more initial conditions, x(t) is actually not in -2pi, -4pi, ... when time is positive :

given more x0

Why is that?

1

There are 1 best solutions below

5
On BEST ANSWER

The issue is with numerical errors:

np.exp(2*np.pi)*np.sin(-2*np.pi)=1.31157628381704e-13

This is not zero. You can do something like:

# function that returns dx/dt
def dxdt(x, t):
    r = np.exp(-x)*np.sin(x)
    if np.abs(r)<1e-10:
       r=0
    return r