# -*- coding: utf-8 -*-
"""
Illustrate the shooting method for the equation
w'' = 3/2*w**2
It plots the error for picking different initial values in the range
[-100, 0]. There are two (approximated) roots -36 and 8.
"""
from __future__ import division
import numpy as np
import matplotlib.pyplot as plt
from scipy.integrate import odeint
import seaborn as sns
sns.set_style("white")
def func(y, t):
return [y[1], 1.5*y[0]**2]
t = np.linspace(0, 1, 50)
diff_ini = np.linspace(-100, 0, 200)
err = np.zeros_like(diff_ini)
plt.figure(figsize=(6, 4))
for cont, dy in enumerate(diff_ini):
y0 = [4, dy]
y = odeint(func, y0, t)
err[cont] = y[-1, 0]
plt.hlines(0, -100, 0, linestyles="dashed", color="#3c3c3c",
linewidth=1)
plt.plot(diff_ini, err)
plt.xlabel(r"$w'(0)=s$")
plt.ylabel(r"$w(t; s) - 1$")
plt.savefig("Shooting_method_error.svg", bbox_inches="tight")
plt.show()