Map of $x_{k+1} = x_k^2$
import numpy as np;
import matplotlib.pyplot as plt;
plt.rcParams.update({"text.usetex":True});
%config InlineBackend.figure_format = "svg"
from ipywidgets import interactive
def f(x):
return x**2;
def g(x):
return x;
x = np.linspace(-2, 2);
plt.plot(x, f(x), x, g(x));
x0 = -0.5;
for i in np.arange(0, 4):
if i == 0:
plt.plot([x0,x0], [0, f(x0)], '-r');
else:
plt.plot([x0, x0], [x0, f(x0)], '-r');
plt.plot([x0,f(x0)], [f(x0),f(x0)], '-r');
xi = x0**2; print("Iter: %d, x:%f\n"%(i, xi))
x0 = xi;
plt.xlim([-1, 1]);
plt.ylim([-1, 1]);
Iter: 0, x:0.250000 Iter: 1, x:0.062500 Iter: 2, x:0.003906 Iter: 3, x:0.000015
def f(x):
return np.cos(x);
def g(x):
return x;
x = np.linspace(-2, 2);
plt.plot(x, f(x), x, g(x));
x0 = 0.1;
for i in np.arange(0, 10):
if i == 0:
plt.plot([x0,x0], [0, f(x0)], '-r');
else:
plt.plot([x0, x0], [x0, f(x0)], '-r');
plt.plot([x0,f(x0)], [f(x0),f(x0)], '-r');
xi = f(x0); print("Iter: %d, x:%f\n"%(i, xi))
x0 = xi;
plt.xlim([0.5, 1.2]);
plt.ylim([0, 1.2]);
Iter: 0, x:0.995004 Iter: 1, x:0.544499 Iter: 2, x:0.855387 Iter: 3, x:0.655927 Iter: 4, x:0.792483 Iter: 5, x:0.702079 Iter: 6, x:0.763501 Iter: 7, x:0.722420 Iter: 8, x:0.750208 Iter: 9, x:0.731547
def f(x, r):
return r*x*(1-x);
def g(x):
return x;
r = 3.9;
x = np.linspace(0, 1);
plt.plot(x, f(x, r), x, g(x)); plt.xlim([0, 1]); plt.ylim([0, r/4+0.1])
plt.plot(1-1/r, 1-1/r, 'ok')
x0 = 0.8;
for i in np.arange(0, 100):
if i == 0:
plt.plot([x0,x0], [0, f(x0, r)], '-r');
else:
plt.plot([x0, x0], [x0, f(x0, r)], '-r');
plt.plot([x0,f(x0, r)], [f(x0, r),f(x0, r)], '-r');
xi = f(x0, r); #print("Iter: %d, x:%f\n"%(i, xi))
x0 = xi;
def f(x, r):
return r*x*(1-x);
def g(x):
return x;
r = 3.5;
x0 = 0.8;
n = np.arange(0, 50);
xi = np.zeros(np.shape(n));
xi[0] = x0;
for i in n:
if i !=0:
xi[i] = f(xi[i-1], r);
#print("Iter: %d, x:%f\n"%(i, xi[i]))
plt.plot(n, xi)
plt.axhline(1-1/r)
<matplotlib.lines.Line2D at 0x1e1a94f9c70>
def f(x, r):
return r*x*(1-x);
def g(x):
return x;
r = 3.4;
x = np.linspace(0, 1,200);
plt.plot(x, f(f(f(f(x, r),r),r),r), x, g(x), x, f(x,r)); plt.xlim([0, 1]); plt.ylim([0, r/4+0.1])
plt.plot(1-1/r, 1-1/r, 'ok')
[<matplotlib.lines.Line2D at 0x1e1a9813970>]
def f1(x, r):
return r*x*(1-x);
def f(x,r):
return f1(f1(x,r),r)
def g(x):
return x;
r = 3.1;
x = np.linspace(0, 1);
plt.plot(x, f(x, r), x, g(x)); plt.xlim([0, 1]); plt.ylim([0, r/4+0.1])
plt.plot(1-1/r, 1-1/r, 'ok')
x0 = 0.8;
for i in np.arange(0, 100):
if i == 0:
plt.plot([x0,x0], [0, f(x0, r)], '-r');
else:
plt.plot([x0, x0], [x0, f(x0, r)], '-r');
plt.plot([x0,f(x0, r)], [f(x0, r),f(x0, r)], '-r');
xi = f(x0, r); #print("Iter: %d, x:%f\n"%(i, xi))
x0 = xi;
def f(x, r):
return r*x*(1-x);
def g(x):
return x;
x0 = 0.8;
n = np.arange(0, 400);
for r in np.linspace(3.4, 4, 200):
xi = np.zeros(np.shape(n));
xi[0] = x0;
for i in n:
if i !=0:
xi[i] = f(xi[i-1], r);
#print("Iter: %d, x:%f\n"%(i, xi[i]))
y = xi[200:400];
plt.plot(r*np.ones(np.shape(y)), y, '.k', markersize=1)
def f(x, r):
return r*x*(1-x);
def g(x):
return x;
x0 = 0.8;
n = np.arange(0, 400);
for r in np.linspace(3.847, 3.857, 200):
xi = np.zeros(np.shape(n));
xi[0] = x0;
for i in n:
if i !=0:
xi[i] = f(xi[i-1], r);
#print("Iter: %d, x:%f\n"%(i, xi[i]))
y = xi[200:400];
plt.plot(r*np.ones(np.shape(y)), y, '.k', markersize=1)
plt.ylim([0.13, 0.18])
(0.13, 0.18)