Solving second order ODE using odeint in Python
<p>I want to solve this equation:</p>

<p>y'' + A<em>y' - B</em>y = 0</p>

<p>where y, A and B are functions of the same variable "a"</p>

<p>I tried the following code:</p>

<pre><code>import numpy as np
import matplotlib.pyplot as pyplot
from scipy.integrate import odeint


x0 = 0.,0.1 # initial conditions 
oe = 0.0 # cosmological constant density parameter
om = 1. # matter density parameter
h = 2.3E-18 # Hubble constant
w = -1. 

a = np.linspace(0.1,1,10) # scale factor


def H(a): # Hubble rate equation 
    return h*np.sqrt((om/(a**3.))+(oe/(a**(3.*(1.+w)))))

def A(a): # differential equation term 
    return (-3./(2.*a))

def B(a): # differential equation term
    return (3.*om*(h**2.))/((2.*(a**5.))*(H(a)**2.))



def system(X,a): # differential equation system
    X0 = X[0]
    X1 = X[1]
    X2 = -A(a)*X1 + B(a)*X0

    return X1,X2



x = odeint(system,x0,a)



pyplot.semilogx(a,x, linestyle='-', c="k", linewidth="2")
</code></pre>

<p>It returns a plot that doesn't make sense. I should get just one plot, with the maximum value of "x" being 1 at a=1. But I get the following plot:</p>

<p>Plot that I get:</p>

<p><img src="http://i.stack.imgur.com/bxW08.png" alt="Plot that I get"></p>

<p>And the expected result is like the continuous line of the following graph:</p>

<p><img src="http://i.stack.imgur.com/4slPW.png" alt="enter image description here"></p>

<p>Any suggestions? </p>

<p>Please try to change sign before B(a)*X0 in the function system(X, a). It should be negative according to your initial equation.</p>

python ode