{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Unstable iterations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Consider the iterations \n",
"$$\n",
"x_0 = 1, \\qquad x_1 = \\frac{1}{3}, \\qquad x_i = \\frac{13}{3}x_{i-1} - \\frac{4}{3} x_{i-2}, \\qquad i=2,3,\\ldots\n",
"$$\n",
"The exact solution is\n",
"$$\n",
"x_i = \\frac{1}{3^i}\n",
"$$"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"%config InlineBackend.figure_format = 'svg'\n",
"from numpy import zeros, float32, float64, abs\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We first try with single precision. By default, Numpy uses double precision, so to use single precision, we have to explicitly specify this in Numpy functions."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 2 1.1111115664e-01 1.1111111194e-01\n",
" 3 3.7037219852e-02 3.7037037313e-02\n",
" 4 1.2346410193e-02 1.2345679104e-02\n",
" 5 4.1181510314e-03 4.1152262129e-03\n",
" 6 1.3834409183e-03 1.3717421098e-03\n",
" 7 5.0404260401e-04 4.5724736992e-04\n",
" 8 3.3959673601e-04 1.5241578512e-04\n",
" 9 7.9952902161e-04 5.0805261708e-05\n",
" 10 3.0118301511e-03 1.6935087842e-05\n",
" 11 1.1985225603e-02 5.6450294323e-06\n",
" 12 4.7920204699e-02 1.8816764396e-06\n",
" 13 1.9167391956e-01 6.2722546090e-07\n",
" 14 7.6669335365e-01 2.0907515363e-07\n",
" 15 3.0667726994e+00 6.9691715510e-08\n",
" 16 1.2267090797e+01 2.3230571244e-08\n",
" 17 4.9068363190e+01 7.7435240442e-09\n",
" 18 1.9627345276e+02 2.5811746074e-09\n",
" 19 7.8509381104e+02 8.6039153580e-10\n"
]
},
{
"data": {
"image/svg+xml": [
"\n",
"\n",
"\n",
"\n"
],
"text/plain": [
"