I donβt think you can solve your problem as indicated: your initial conditions, with x = 0 and x' > 0 imply that the solution will be positive for some values ββvery close to the starting point. So there is no b for which the solution is never positive ...
Leaving this aside, in order to solve the second-order differential equation, we first need to rewrite it as a system of two first-order differential equations. By defining y = x' , we can rewrite your only equation as follows:
x' = y y' = -b/m*y - k/m*x - a/m*x**3 - g x[0] = 0, y[0] = 5
So your function should look something like this:
def fun(z, t, m, k, g, a, b): x, y = z return np.array([y, -(b*y + (k + a*x*x)*x) / m - g])
And you can solve and build your equations:
m, k, g, a = 1220, 35600, 17.5, 450000 tmax, dt = 10, 0.01 t = np.linspace(0, tmax, num=np.round(tmax/dt)+1) for b in xrange(1000, 10500, 500): print 'Solving for b = {}'.format(b) sol = odeint(fun, [0, 5], t, args=(m, k, g, a, b))[..., 0] plt.plot(t, sol, label='b = {}'.format(b)) plt.legend()
