File:Shooting method error.svg
Summary
Description |
English: Graph showing error of the shooting method as a function of the initial value of w'(0).
Español: Gráfico mostrando el error del método de disparo como una función del valor inicial para w'(0). |
Date | |
Source | Own work |
Author | Nicoguaro |
SVG development | |
Source code | Python code# -*- 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()
|
Licensing
I, the copyright holder of this work, hereby publish it under the following license:
This file is licensed under the Creative Commons Attribution 4.0 International license.
- You are free:
- to share – to copy, distribute and transmit the work
- to remix – to adapt the work
- Under the following conditions:
- attribution – You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.