From ced984cebd1d3f613aa764e14c3cb59300a6aabb Mon Sep 17 00:00:00 2001 From: marcellus Date: Sun, 11 May 2025 20:31:18 +0200 Subject: update: exo PCVM --- PVCM/cama.md | 3 +- .../fr/ma26 Vecteurs propres -- Exercices.ipynb | 146 +++++++++++++++------ 2 files changed, 105 insertions(+), 44 deletions(-) (limited to 'PVCM') diff --git a/PVCM/cama.md b/PVCM/cama.md index 21e49cf..ce46dac 100755 --- a/PVCM/cama.md +++ b/PVCM/cama.md @@ -288,8 +288,7 @@ Une autre vidéo, avec un peu plus d'exemple est qui est tout aussi bien: https://www.youtube.com/watch?v=pkVwUVEHmfI&t=785s La man page de help est aussi très complète. -La manière de faire la plus simple reste d'écrire un pseudo code avec des boucles for, -puis de re-écrire avec la notation Einstein. +La manière de faire la plus simple reste d'écrire un pseudo code avec des boucles for, puis de re-écrire avec la notation Einstein. #### Formule essentiels + exemple diff --git a/PVCM/cama/fr/ma26 Vecteurs propres -- Exercices.ipynb b/PVCM/cama/fr/ma26 Vecteurs propres -- Exercices.ipynb index 88d82df..c62c0b1 100644 --- a/PVCM/cama/fr/ma26 Vecteurs propres -- Exercices.ipynb +++ b/PVCM/cama/fr/ma26 Vecteurs propres -- Exercices.ipynb @@ -1,25 +1,4 @@ { - "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.10.12" - } - }, - "nbformat": 4, - "nbformat_minor": 4, "cells": [ { "cell_type": "markdown", @@ -65,14 +44,14 @@ "source": [ "Comme on a 2 termes à droite du signe égal, écrivons Fibonnacci sous forme d'un système matriciel $2\\times 2$ :\n", "\n", - "$\n", + "$$\n", "\\begin{align}\n", "x_{n-1} &= x_{n-1} \\\\\n", "x_n &= x_{n-2} + x_{n-1} \\\\\n", "\\end{align}\n", - "$\n", + "$$\n", "ce qui donne\n", - "$\n", + "$$\n", "\\begin{bmatrix}\n", "x_{n-1}\\\\\n", "x_n \\\\\n", @@ -86,7 +65,7 @@ "x_{n-2}\\\\\n", "x_{n-1} \\\\\n", "\\end{bmatrix}\n", - "$\n", + "$$\n", "\n", "Écrire la matrice F ci-dessous et vérifier que le 6e élément de la suite de Fibonacci est 8 en n'utilisant que \n", "la matrice F et les valeurs initiales de la suite. La fonction `numpy.linalg.matrix_power` pourra vous être utile." @@ -94,17 +73,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "array([[0, 1],\n", + " [1, 1]])" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "F = np.array([[0,1],[1,1]])\n", + "F" + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "array([[ 5, 8],\n", + " [ 8, 13]])" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "F6 = lin.matrix_power(F,6)\n", + "F6" + ] }, { "cell_type": "markdown", @@ -125,7 +134,9 @@ { "cell_type": "markdown", "metadata": {}, - "source": [] + "source": [ + "$F^n = F \\times F^{n-1} = P\\times D^n \\times P^{-1}$" + ] }, { "cell_type": "markdown", @@ -136,17 +147,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def fibo(n):\n", + " F = np.array([[0,1],[1,1]], dtype=int)\n", + " D, P = lin.eig(F)\n", + " return (P @ lin.matrix_power(np.diag(D),n) @ lin.inv(P))[0]" + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "data": { + "text/plain": [ + "array([5., 8.])" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "fibo(6)" + ] }, { "cell_type": "markdown", @@ -158,10 +187,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "84.8 μs ± 7.75 μs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n", + "109 μs ± 6.71 μs per loop (mean ± std. dev. of 7 runs, 10,000 loops each)\n" + ] + } + ], + "source": [ + "%timeit fibo(5)\n", + "%timeit fibo(1000)" + ] }, { "cell_type": "code", @@ -301,5 +342,26 @@ "outputs": [], "source": [] } - ] -} \ No newline at end of file + ], + "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.13.2" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} -- cgit v1.2.3