Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Backward integration in time using scipy odeint

Is it possible to integrate any Ordinary Differential Equation backward in time using scipy.integrate.odeint ? If it is possible, could someone tell me what should be the arguement 'time' in 'odeint.

like image 352
ADK Avatar asked Oct 19 '25 15:10

ADK


1 Answers

odeint handles negative values of the t argument. No special treatment is needed.

Here's an example:

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


def mysys(z, t):
    """A slightly damped oscillator."""
    return [z[1] - 0.02*z[0], -z[0]]


if __name__ == "__main__":
    # Note that t starts at 0 and goes "backwards"
    t = np.linspace(0, -50, 501)

    z0 = [1, 1]
    sol = odeint(mysys, z0, t)

    plt.plot(t, sol)
    plt.xlabel('t')
    plt.show()

The plot: Solve an ODE backward in time

like image 173
Warren Weckesser Avatar answered Oct 22 '25 04:10

Warren Weckesser