{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# importing libraries used in this book\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"from NonLinearEquationsLib import plotPhi, FixedPoint, plotPhiIterations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## 1.3.1 Méthode de point fixe\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## 1.3.2 Méthode de point fixe, limite\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"On considère les méthodes de point fixe $x^{(n+1)} = g_i(x^{(n)})\n",
"\\quad (i=1,2,3)$ avec:\n",
"\n",
"$$g_1(x^{(n)}) = \\dfrac{1}{2} e^{x^{(n)}/2} , \\qquad g_2(x^{(n)}) = -\\dfrac{1}{2}\n",
" e^{x^{(n)}/2}, \\qquad g_3(x^{(n)}) = 2 \\ln(2x^{(n)}),$$\n",
"dont les fonctions d'itération $g_i(x)$ sont visualisées sur la figure plus bas"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"plt.rcParams['figure.figsize'] = [20, 5]\n",
"\n",
"plt.subplot(1,3,1)\n",
"[a,b] = [-2,5]\n",
"phi1 = lambda x : np.exp(x/2)/2\n",
"plotPhi(a,b,phi1,'$g_1$')\n",
"\n",
"plt.subplot(1,3,2)\n",
"[a,b] = [-2,5]\n",
"phi2 = lambda x : - np.exp(x/2)/2\n",
"plotPhi(a,b,phi2,'$g_2$')\n",
"\n",
"plt.subplot(1,3,3)\n",
"[a,b] = [1e-1,5]\n",
"phi3 = lambda x : 2*np.log(2*x)\n",
"plotPhi(a,b,phi3,'$g_3$')\n",
"\n",
"plt.show()\n",
"\n",
"# Graph of the fonction $f(x)=e^x-4x^2$\n",
"N = 100\n",
"z = np.linspace(a,b,N)\n",
"f = lambda x : np.exp(x) - 4*x*x\n",
"\n",
"plt.subplot(1,3,1)\n",
"plt.plot(z,f(z),'k-')\n",
"\n",
"plt.xlabel('x'); plt.ylabel('f(x)');\n",
"# Plot the x,y-axis \n",
"plt.plot([a,b], [0,0], 'k-',linewidth=0.1)\n",
"plt.plot([0,0], [np.min(f(z)),np.max(f(z))], 'k-',linewidth=0.1)\n",
"plt.legend(['f(x)'])\n",
"plt.title('Graph of $f(x)=e^x-4x^2$')\n",
"\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Partie 1**\n",
"*Pour chaque point fixe $\\bar{x}$ de la fonction d'itération $g_i$ ($i=1,2,3$), on suppose choisir une valeur \n",
"initiale $x^{(0)}$ proche de $\\bar{x}$. Etudiez si la méthode converge vers $\\bar{x}$.*\n",
"\n",
"On va utiliser la fonction `FixedPoint` qui se trouve dans `NonLinearEquationsLib.py`\n",
"```python\n",
"def FixedPoint( phi, x0, a, b tol, nmax ) :\n",
" '''\n",
" FixedPoint Find the fixed point of a function by iterative iterations\n",
" FixedPoint( PHI,X0,a,b, TOL,NMAX) tries to find the fixedpoint X of the a\n",
" continuous function PHI nearest to X0 using \n",
" the fixed point iterations method. \n",
" [a,b] : if the iterations exit the interval, the method stops\n",
" If the search fails an error message is displayed.\n",
" \n",
" Outputs : [x, r, n, inc, x_sequence]\n",
" x : the approximated fixed point of the function\n",
" r : the absolute value of the residual in X : |phi(x) - x|\n",
" n : the number of iterations N required for computing X and\n",
" x_sequence : the sequence computed by Newton\n",
" \n",
" ...\n",
" return xk1, rk1, n, np.array(x) \n",
" '''\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tol = 1e-2\n",
"nmax = 10\n",
"\n",
"# Choose fonction phi\n",
"[a,b] = [-2,5]\n",
"phi = phi1\n",
"label = '$phi_1$'\n",
"\n",
"# Initial Point\n",
"x0 = 3\n",
"zero, residual, niter, x = FixedPoint(phi, x0, a,b, tol, nmax)\n",
"\n",
"plt.subplot(131)\n",
"plotPhi (a,b,phi,label)\n",
"plt.plot(x,phi(x), 'rx')\n",
"\n",
"# plot the graphical interpretation of the Fixed Point method\n",
"plotPhiIterations(x)\n",
"\n",
"plt.show()\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Avec $\\phi_1$, la méthode de point fixe converge. Que se passe-t-il avec $\\phi_2$ et $\\phi_3$ ?\n",
"Esssayez avec Python :\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Réutilisez le code plus haut et observez se qu'il se passe pour \n",
"# phi = phi1 et phi2\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## 1.3.3 Méthode de point fixe, convergence globale\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## 1.3.4 Méthode de point fixe, preuve\n",
"\n",
""
]
},
{
"cell_type": "markdown",
"metadata": {
"tags": []
},
"source": [
"## 1.3.5 Méthode de point fixe, convergence globale bis\n",
"\n",
""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.16"
}
},
"nbformat": 4,
"nbformat_minor": 4
}