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 0ccad96..94f0776 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,365 +1,304 @@
{
"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": 1,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/html": [
- " \n",
- " "
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
+ "outputs": [],
"source": [
"import Librairie.AL_Fct as al\n",
"import Corrections.corrections as corrections\n",
- "import numpy as np"
+ "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",
- "ans = lambda x: x # inserez ici votre réponse\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",
- "ans = lambda x: x # inserez ici votre réponse\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",
- "Interactive Gram-Schmidt process in $\\mathbb{R}^3$. Give a family of vectors. Ask the user to insert the coefficients of the projections (step by step). If the value is right, display the \"status\" in a plot and go on; if the value is wrong, display again the \"status\" to show that something is wrong and ask the user to insert the value again.\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",
+ "\n",
+ "**Remark**: in order to properly execute the algorithm, keep the given order of the vectors! \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",
+ "\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",
"\n",
- "Show that the order in which the vectors are chosen is not important! Show that, if the vectors are linearly dependent, then the result of GS will contain at least one null element."
+ "Furthermore:\n",
+ "\n",
+ "1. You can revert an operation by selecting the \"Revert\" button. \n",
+ "\n",
+ "2. If the inserted coefficients are wrong, you can try with new values without doing a \"Revert\" operation. \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."
]
},
{
"cell_type": "code",
- "execution_count": 2,
+ "execution_count": null,
"metadata": {},
"outputs": [],
"source": [
- "vectors = [[2,0,1], [1,1,0], [0,0,1]]\n",
+ "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",
"step = 0\n",
"VectorsList = [vectors]"
]
},
{
"cell_type": "code",
- "execution_count": 3,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/latex": [
- "Régler les paramètres et évaluer la cellule suivante"
- ],
- "text/plain": [
- ""
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/vnd.jupyter.widget-view+json": {
- "model_id": "ef1872f91dd2436ca9ee445d30405dda",
- "version_major": 2,
- "version_minor": 0
- },
- "text/plain": [
- "BoundedIntText(value=1, description='Numéro du vecteur courant', max=3, min=1, style=DescriptionStyle(descript…"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/vnd.jupyter.widget-view+json": {
- "model_id": "0db78a1b4fd2483d976023d04d671829",
- "version_major": 2,
- "version_minor": 0
- },
- "text/plain": [
- "RadioButtons(description='Opération:', options=('Normalization', 'Projection', 'Revert'), style=DescriptionSty…"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/vnd.jupyter.widget-view+json": {
- "model_id": "6c164dd2b39c4c2a975ca06a9e1756ce",
- "version_major": 2,
- "version_minor": 0
- },
- "text/plain": [
- "BoundedFloatText(value=1.0, description='Coefficient de Normalisation', max=10000000000.0, step=0.1, style=Des…"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/vnd.jupyter.widget-view+json": {
- "model_id": "8048f8ae2f7842f69199080f39c90f48",
- "version_major": 2,
- "version_minor": 0
- },
- "text/plain": [
- "FloatText(value=0.0, description='Coefficient de Projection 1', step=0.1, style=DescriptionStyle(description_w…"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "application/vnd.jupyter.widget-view+json": {
- "model_id": "d36676238a854a27b39a74465805850c",
- "version_major": 2,
- "version_minor": 0
- },
- "text/plain": [
- "FloatText(value=0.0, description='Coefficient de Projection 2', step=0.1, style=DescriptionStyle(description_w…"
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- }
- ],
+ "outputs": [],
"source": [
- "norm_coeff, proj_coeffs, operation, step_number = al.manual_GS(dim=3)"
+ "norm_coeff, proj_coeffs, operation, step_number = al.manual_GS(dim=dim)"
]
},
{
"cell_type": "code",
- "execution_count": 6,
+ "execution_count": null,
"metadata": {},
- "outputs": [
- {
- "data": {
- "text/latex": [
- "Construction du vecteur numéro 3"
- ],
- "text/plain": [
- ""
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/latex": [
- "Current Vectors: [array([2., 0., 1.]), array([ 0.2, 1. , -0.4]), array([0., 0., 1.])]"
- ],
- "text/plain": [
- ""
- ]
- },
- "metadata": {},
- "output_type": "display_data"
- },
- {
- "data": {
- "text/plain": [
- "[[array([2., 0., 1.], dtype=float32),\n",
- " array([1., 1., 0.], dtype=float32),\n",
- " array([0., 0., 1.], dtype=float32)],\n",
- " [array([2., 0., 1.], dtype=float32),\n",
- " array([ 0.19999999, 1. , -0.4 ], dtype=float32),\n",
- " array([0., 0., 1.], dtype=float32)]]"
- ]
- },
- "execution_count": 6,
- "metadata": {},
- "output_type": "execute_result"
- }
- ],
+ "outputs": [],
"source": [
"vectors = al.interactive_gram_schmidt(norm_coeff, proj_coeffs,\n",
" operation, step_number, \n",
- " vectors.copy(), VectorsList)\n",
- "VectorsList"
+ " 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."
]
},
{
- "cell_type": "markdown",
+ "cell_type": "code",
+ "execution_count": null,
"metadata": {},
+ "outputs": [],
"source": [
- "## Exercise 4\n",
- "\n",
- "Same as on the MOOC. Give an underdetermined system / rank deficient matrix; compute a basis for its kernel; from it, apply GS to derive an orthogonal/orthonormal basis; finally compute the coordinates of an \"extra\" element with respect to such basis."
+ "x = sp.Symbol('x')\n",
+ "functions = [1 + 0*x, x, x**2]\n",
+ "step = 0\n",
+ "dim=3\n",
+ "FunctionsList = [functions]"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "norm_coeff, proj_coeffs, operation, step_number = al.manual_GS(dim=dim)"
]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "functions = al.interactive_gram_schmidt_func(norm_coeff, proj_coeffs,\n",
+ " operation, step_number, \n",
+ " functions.copy(), \n",
+ " FunctionsList)"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": []
}
],
"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
}