diff --git "a/Chapitre 9 - Produits scalaires et espaces euclidens/9.6-9.7 Comment trouver une base orthogonale au orthonormale - Le proc\303\251d\303\251 de Gram-Schmidt.ipynb" "b/Chapitre 9 - Produits scalaires et espaces euclidens/9.6-9.7 Comment trouver une base orthogonale au orthonormale - Le proc\303\251d\303\251 de Gram-Schmidt.ipynb" index 94f0776..816cdd2 100644 --- "a/Chapitre 9 - Produits scalaires et espaces euclidens/9.6-9.7 Comment trouver une base orthogonale au orthonormale - Le proc\303\251d\303\251 de Gram-Schmidt.ipynb" +++ "b/Chapitre 9 - Produits scalaires et espaces euclidens/9.6-9.7 Comment trouver une base orthogonale au orthonormale - Le proc\303\251d\303\251 de Gram-Schmidt.ipynb" @@ -1,304 +1,356 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# **Concept(s)-clé(s) et théorie**\n", "\n", "## Proposition 1\n", "Soient $V$ un $\\mathbb{R}$-espace vectoriel muni d'un produit scalaire $\\langle \\cdot,\\cdot\\rangle$ et $S = \\{v_1, \\dots, v_k\\} \\subset V$ une famille orthogonale de vecteurs non-nuls. Alors $S$ est une famille libre.\n", "\n", "## Définition 1\n", "Soit $V$ un $\\mathbb{R}$-espace vectoriel muni d'un produit scalaire $\\langle \\cdot,\\cdot\\rangle$. Pour $u,v \\in V$, on définit la **projection orthogonale de $u$ sur $v$** par $$ proj_v u = \\dfrac{\\langle u,v \\rangle}{\\langle v,v \\rangle} v = \\dfrac{\\langle u,v \\rangle}{||v||^2}v$$\n", "\n", "## Proposition 2\n", "Soit $V$ un $\\mathbb{R}$-espace vectoriel muni d'un produit scalaire $\\langle \\cdot,\\cdot\\rangle$. Alors les affirmations suivantes sont vérifiée:\n", "\n", "1. Pour tous $u,v \\in V$ le vecteur $proj_v u \\in V$ appartient à $Vect(\\{v\\})$\n", "2. Pour tous $u,v \\in V$, on a $\\langle u - proj_v u, v \\rangle = 0$\n", "\n", "## Théorème 1: Procédé de Gram-Schmidt\n", "Soient $V$ un $\\mathbb{R}$-espace vectoriel muni d'un produit scalaire $\\langle \\cdot,\\cdot \\rangle$ et $S = \\{x_1, \\dots, x_k\\}$ une famille de vecteurs dans $V$. Alors en posant successivement\n", "\\begin{equation}\n", "\\begin{aligned}\n", "v_1 &= x_1 \\\\\n", "v_2 &= x_2 - proj_{v_1}x_2 \\\\\n", "v_3 &= x_3 - proj_{v_1}x_3 - proj_{v_2}x_3 \\\\\n", "\\vdots & \\qquad \\\\\n", "v_k &= x_k - proj_{v_1}x_k - proj_{v_2}x_k - \\cdots - proj_{v_{k-1}}x_k\n", "\\end{aligned}\n", "\\end{equation}\n", "la famille $\\{v_1, \\dots, v_k\\}$ ainsi obtenue est une famille orthogonale.\n", "\n", "## Théorème 2: Proprietes du procédé de Gram-Schmidt\n", "Soient $V$ un $\\mathbb{R}$-espace vectoriel muni d'un produit scalaire $\\langle \\cdot,\\cdot \\rangle$ et $S = \\{x_1, \\dots, x_k\\}$ une famille de vecteurs *linéarment indépentants* dans $V$. La procédé de Gram-Schmidt applique à la famille $S$ définit une suite de vecteurs $v_1, \\dots v_k$ telle que $\\{v_1, \\dots, v_k\\}$ est une famille de vecteurs deux-à-deux ortogonaux, non-nuls et donc linéarment indédendants. De plus, on a $$ Vect(S) = Vect(v_1, \\dots, v_k)$$\n", "\n", "## Remarque 1\n", "1. Si $\\{x_1, \\dots, x_k\\}$ est une base de $V$, le procédé de Gram-Schmidt donne une base orthogonale $\\{v_1,\\dots, v_k\\}$ de $V$.\n", "2. Si l'on souhaite avoir une base orthonormale de $V$, il suffit de normaliser la base obtenue." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Exercises et Exemples" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import Librairie.AL_Fct as al\n", "import Corrections.corrections as corrections\n", "import numpy as np\n", "import sympy as sp" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 1\n", "\n", "Considérez les $\\mathbb{R}$-espaces vectoriels suivants, équipés avec le produit scalaire donnè. Considérez les éléments donnés $u$ et $v$ de ces espaces. Calculez la projection orthogonale de $u$ sur $v$.\n", "\n", "1. $\\quad$ $V = \\mathbb{R}^2$; $\\qquad \\qquad$ $\\langle u,v \\rangle_V = u^Tv$; $\\qquad \\qquad \\qquad \\qquad \\qquad \\qquad \\quad$ $u = \\begin{pmatrix} -1 \\\\ 2 \\end{pmatrix}$ $\\qquad \\ \\ $ $v = \\begin{pmatrix} 1 \\\\ 1 \\end{pmatrix}$\n", "\n", "2. $\\quad$ $V = \\mathbb{R}^3$; $\\qquad \\qquad$ $\\langle u,v \\rangle_V = u^TAv \\quad avec \\ \\ A=\\begin{bmatrix} 2 & 0 & -1\\\\ 0 & 1 & 0\\\\ -1 & 0 & 2 \\end{bmatrix}$ $\\qquad$ $u = \\begin{pmatrix} 1 \\\\ 2 \\\\ 1 \\end{pmatrix}$ $\\qquad \\quad \\ \\ $ $v = \\begin{pmatrix} 0 \\\\ 1 \\\\ -1 \\end{pmatrix}$\n", "\n", "3. $\\quad$ $V = \\mathbb{R}^5$; $\\qquad \\qquad$ $\\langle u,v \\rangle_V = u^Tv$; $\\qquad \\qquad \\qquad \\qquad \\qquad \\qquad \\quad \\ $ $u = \\begin{pmatrix} -1 \\\\ 0 \\\\ 1 \\\\ 0 \\\\ 1 \\end{pmatrix}$ $\\qquad \\quad $ $v = \\begin{pmatrix} 0 \\\\ 1 \\\\ -1 \\\\ 1 \\\\ 0 \\end{pmatrix}$\n", "\n", "4. $\\quad$ $V = \\mathbb{P}^2(\\mathbb{R})$; $\\qquad \\quad$ $\\langle f,g \\rangle_V = \\int_0^1 f(x)g(x) \\ dx$; $\\qquad \\qquad \\qquad \\qquad \\ \\ \\ $ $f(x) = x^2 - 1$ $\\qquad$ $g(x) = x$\n", "\n", "5. $\\quad$ $V = \\mathbb{P}^3(\\mathbb{R})$; $\\qquad \\quad$ $\\langle f,g \\rangle_V = \\int_{-1}^1 (1-x^2)f(x)g(x) \\ dx$; $\\qquad \\qquad \\quad \\ \\ \\ $ $f(x) = x^2 -x$ $\\qquad$ $g(x)=x+1$" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# CAS 1\n", "ans = [1/2,1/2] # inserez ici votre réponse\n", "corrections.Ex1Chapitre9_6_7(ans, case_nb=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# CAS 2\n", "ans = [0, 1/3, -1/3] # inserez ici votre réponse\n", "corrections.Ex1Chapitre9_6_7(ans, case_nb=2)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# CAS 3\n", "ans = [0, 0, 0, 0, 0] # inserez ici votre réponse\n", "corrections.Ex1Chapitre9_6_7(ans, case_nb=3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# CAS 4\n", "x = sp.Symbol('x')\n", "ans = x**1 # inserez ici votre réponse\n", "corrections.Ex1Chapitre9_6_7(ans, case_nb=4)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# CAS 5\n", "x = sp.Symbol('x')\n", "ans = x**1 # inserez ici votre réponse\n", "corrections.Ex1Chapitre9_6_7(ans, case_nb=5)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercice 2\n", "\n", - "Consider the following sets of vectors in $\\mathbb{R}^n, \\ n \\in \\{2,3,4\\}$. Take advantage of the interactive method that follows to apply the Gram-Schmidt method and derive an orthonormal set of vectors.\n", - "Assume the inner product to be the standard one $\\langle u,v \\rangle = u^Tv$ in all cases.\n", + "Considérez les ensembles de vecteurs suivants dans $\\mathbb{R}^n, \\ n \\in \\{2,3,4\\}$. Tirez parti de la méthode interactive qui suit pour appliquer la méthode de Gram-Schmidt et dériver un ensemble orthonormé de vecteurs.\n", + "Supposez que le produit scalair soit le produit standard $\\langle u,v \\rangle = u^Tv$ dans tous les cas.\n", "\n", - "**Remark**: in order to properly execute the algorithm, keep the given order of the vectors! \n", + "**Remarque**: pour exécuter correctement l'algorithme, gardez l'ordre donné des vecteurs!\n", "\n", "1. $\\mathcal{S}_1 = \\left\\{ \\begin{bmatrix} 2 \\\\ 1 \\end{bmatrix}, \\begin{bmatrix} -1 \\\\ -1 \\end{bmatrix} \\right\\}$\n", "\n", "2. $\\mathcal{S}_2 = \\left\\{ \\begin{bmatrix} 2 \\\\ 0 \\\\ 1 \\end{bmatrix}, \\begin{bmatrix} 1 \\\\ 1 \\\\ 0 \\end{bmatrix}, \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix} \\right\\}$\n", "\n", "3. $\\mathcal{S}_3 = \\left\\{ \\begin{bmatrix} 1 \\\\ 0 \\\\ -1 \\end{bmatrix}, \\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\end{bmatrix}, \\begin{bmatrix} 0 \\\\ 0 \\\\ 1 \\end{bmatrix}, \\begin{bmatrix} 1 \\\\ 1 \\\\ 1 \\end{bmatrix} \\right\\}$\n", "\n", "4. $\\mathcal{S}_4 = \\left\\{ \\begin{bmatrix} 1 \\\\ 0 \\\\ 0 \\\\ 1 \\end{bmatrix}, \\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\\\ -1\\end{bmatrix}, \\begin{bmatrix} 0 \\\\ 1 \\\\ 0 \\\\ 1 \\end{bmatrix}, \\begin{bmatrix} 0 \\\\ 1 \\\\ 1 \\\\ 0\\end{bmatrix} \\right\\}$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Instructions\n", "\n", - "To use the interactive Gram-Schmidt method, follow these steps:\n", + "Pour utiliser la méthode interactive de Gram-Schmidt, procédez comme suit:\n", "\n", - "1. Insert the desired case number in the following cell\n", - "2. Run the cell called \"PARAMETERS SELECTION\" to select the type of operation and the necessary coefficients\n", - "3. Run the cell called \"EXECUTE GS STEP\" to execute the step of the Gram-Schmidt algorithm with the previously selected parameters\n", + "1. Insérez le numéro de dossier souhaité dans la cellule suivante\n", + "2. Exécutez la cellule appelée \"SÉLECTION DES PARAMÈTRES\" pour sélectionner le type d'opération et les coefficients nécessaires\n", + "3. Exécutez la cellule appelée \"EXÉCUTER L'ÉTAPE DE L'ALGORITHME GRAM-SCHMIDT\" pour exécuter l'étape de l'algorithme de Gram-Schmidt avec les paramètres précédemment sélectionnés\n", "\n", - "Furthermore:\n", + "En outre:\n", "\n", - "1. You can revert an operation by selecting the \"Revert\" button. \n", + "1. Vous pouvez annuler une opération en sélectionnant le bouton \"Revert\".\n", "\n", - "2. If the inserted coefficients are wrong, you can try with new values without doing a \"Revert\" operation. \n", + "2. Si les coefficients insérés sont incorrects, vous pouvez essayer avec de nouvelles valeurs sans effectuer une opération \"Revert\".\n", "\n", - "3. Coefficients that are not linked to the selected operation can be set to whichever value, as they are not used in the code." + "3. Les coefficients qui ne sont pas liés à l'opération sélectionnée peuvent être définis sur n'importe quelle valeur, car ils ne sont pas utilisés dans le code." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "case_number = 3" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if case_number == 1:\n", " vectors = [[2,1], [-1,-1]]\n", " dim=2\n", "elif case_number == 2:\n", " vectors = [[2,0,1], [1,1,0], [0,0,1]]\n", " dim=3\n", "elif case_number == 3:\n", " vectors = [[1,0,-1], [0,1,1], [0,0,1], [1,1,1]]\n", " dim=4\n", "elif case_number == 4:\n", " vectors = [[1,0,0,1], [0,1,1,-1], [0,1,0,1],[0,1,1,0]]\n", " dim=4\n", "else:\n", - " print(f\"{case_number} is not a valid case number!\" \n", - " f\"Available case numbers: [1,2,3,4]\")\n", + " print(f\"{case_number} n'est pas un numéro de cas valide!\" \n", + " f\"Numéros de cas disponibles: [1,2,3,4]\")\n", "step = 0\n", "VectorsList = [vectors]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ + "# SÉLECTION DES PARAMÈTRES\n", "norm_coeff, proj_coeffs, operation, step_number = al.manual_GS(dim=dim)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ + "# EXÉCUTER L'ÉTAPE DE L'ALGORITHME GRAM-SCHMIDT\n", "vectors = al.interactive_gram_schmidt(norm_coeff, proj_coeffs,\n", " operation, step_number, \n", " vectors.copy(), VectorsList)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Exercise 3\n", "\n", - "Interactive Gram-Schmidt in $\\mathbb{P}^3(\\mathbb{R})$. It works as in $\\mathbb{R}^3$, but at each step a plot of the functions is returned. We can do it in $[-1;1]$ so that the Legendre basis is derived." + "Considérez les ensembles de fonctions suivants, dans les intervalles donnés et avec le produit scalir donné. Tirez parti de la méthode interactive qui suit pour appliquer la méthode de Gram-Schmidt et dériver un ensemble orthonormé de vecteurs. Vous pouvez vous aider à calculer les intégrales en exécutant la cellule appelée \"Cellule d'aide pour calculer les intégrales\"\n", + "\n", + "\n", + "**Remarque**: pour exécuter correctement l'algorithme, gardez l'ordre donné des fonctions!\n", + "\n", + "1. $\\mathcal{F}_1 = \\left\\{1, x, x^2\\right\\}; \\qquad \\quad \\ \\ [a;b] = [-1;1] \\qquad \\langle f,g \\rangle = \\int_a^b f(x) g(x) \\ dx$\n", + "2. $\\mathcal{F}_2 = \\left\\{1, x, x^2, x^3 \\right\\}; \\qquad \\ [a;b] = [0;1] \\qquad \\ \\ \\langle f,g \\rangle = \\int_a^b f(x) g(x) \\ dx$\n", + "3. $\\mathcal{F}_3 = \\left\\{1, x^2, x^4 \\right\\}; \\qquad \\quad [a;b] = [-1;1] \\qquad \\langle f,g \\rangle = \\int_a^b (1-|x|) f(x) g(x) \\ dx$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "case_number = 2" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "x = sp.Symbol('x')\n", - "functions = [1 + 0*x, x, x**2]\n", + "\n", + "if case_number == 1:\n", + " functions = [1 + 0*x, x, x**2]\n", + " int_limits = [-1, 1]\n", + " weight_function = 1.0 + 0*x\n", + " dim=3\n", + "elif case_number == 2:\n", + " functions = [1.0 + 0*x, x, x**2, x**3]\n", + " int_limits = [0, 1]\n", + " weight_function = 1.0 + 0*x\n", + " dim=4\n", + "elif case_number == 3:\n", + " functions = [1.0 + 0*x, x**2, x**4]\n", + " int_limits = [-1, 1]\n", + " weight_function = (1 - sp.abs(x))\n", + " dim=3\n", + "else:\n", + " print(f\"{case_number} n'est pas un numéro de cas valide!\" \n", + " f\"Numéros de cas disponibles: [1,2,3,4]\")\n", + " \n", "step = 0\n", - "dim=3\n", "FunctionsList = [functions]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ + "# SÉLECTION DES PARAMÈTRES\n", "norm_coeff, proj_coeffs, operation, step_number = al.manual_GS(dim=dim)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ + "# EXÉCUTER L'ÉTAPE DE L'ALGORITHME GRAM-SCHMIDT\n", "functions = al.interactive_gram_schmidt_func(norm_coeff, proj_coeffs,\n", " operation, step_number, \n", " functions.copy(), \n", - " FunctionsList)" + " FunctionsList,\n", + " int_limits=int_limits,\n", + " weight_function=weight_function)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# Cellule d'aide pour calculer les intégrales\n", + "x = sp.Symbol('x')\n", + "func = weight_function * x # insert here the expression of your function, using 'x' as variable\n", + "I = al.integrate_sp_function(func, x, int_limits)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "[Passez au notebook du chapitre 9.8-9.9: La projection orthgonale sur un sous-espace vectoriel - La projection orthogonale: examples et remarques supplémentaires](./)" + ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.4" } }, "nbformat": 4, "nbformat_minor": 4 }