Python odeint clearly returning wrong solution
<p>Using python 2.7.8.<br>
The differential equation I'm working with is x'=2-3*x. Not that difficult. The correct solution is a decaying exponential with a y-intercept of 2/3. Exercise has three initial conditions. Also have to have a slope field with solution on the same plot. I have the slope field, but the solution provided is wrong. A test case of x'=x worked fine but only when t>0. But the solution odeint provided is wrong. Instead of a decaying exponential I'm given what looks like a trig function. Here is the code.
</p>

<pre><code>#Solutions function
def m_diff_sol(input_domain,input_initial_conditions_set):
    f_set=[]
    for n in input_initial_conditions_set:
        m_sol=odeint(m_fst_diff_eq,n,input_domain)
        f=[b for [a,b] in m_sol]
        f_set.append(f)
    return f_set

#Vector field function
def m_fst_diff_eq(x,t):
    m,mdot=x
    return [mdot,2-3*m]
</code></pre>

<p><a href="http://i.stack.imgur.com/AAJd6.png" rel="nofollow"><img src="http://i.stack.imgur.com/AAJd6.png" alt="enter image description here"></a></p>

<p>You want your ODE function to return 1 output, namely</p>

<pre><code>def my_ode_func(x,t):
    return 2.0 - 3.0*x
</code></pre>

<p>Then <code>odeint</code> gives the expected exponential decay from the initial condition to <code>x=2/3</code>.</p>

<pre><code>import numpy as np
from scipy.integrate import odeint
t = np.arange(0,10.0,0.01)
x0 = 1
out1 = odeint(my_ode_func,x0,t)
</code></pre>

<p><a href="http://i.stack.imgur.com/i1jlI.png" rel="nofollow"><img src="http://i.stack.imgur.com/i1jlI.png" alt="Numerical solution to linear ODE"></a></p>

<p>It looks like you're instead modelling something like the second order ODE <code>x''(t) = 2 - 3*x(t)</code>. This would be written as a system of first order ODEs
<code>Y(t) = [x(t),x'(t)]</code>, then</p>

<pre><code>Y'(t) = [Y[2](t), 2 - 3*Y[1](t)]
</code></pre>

<p>The code would look something like this:</p>

<pre><code>def my_ode_func2(Y,t):
    return [Y[1],2.0 - 3.0*Y[0]]

Y0 = [1,1]
out2 = odeint(my_ode_func2,Y0,t)
</code></pre>

<p><a href="http://i.stack.imgur.com/Acy9Y.png" rel="nofollow"><img src="http://i.stack.imgur.com/Acy9Y.png" alt="Numerical solution to second order ODE"></a></p>

python ode