summaryrefslogtreecommitdiff
path: root/PVCM/cama
diff options
context:
space:
mode:
authormarcellus <msimon_fr@hotmail.com>2025-05-11 20:31:18 +0200
committermarcellus <msimon_fr@hotmail.com>2025-05-11 20:31:18 +0200
commitced984cebd1d3f613aa764e14c3cb59300a6aabb (patch)
tree756e692ecb78f2bb895ef407943c5ea3e31c6ebb /PVCM/cama
parent8bef0a919683f4296a93fb7082a28044ab0ebf1f (diff)
update: exo PCVM
Diffstat (limited to 'PVCM/cama')
-rw-r--r--PVCM/cama/fr/ma26 Vecteurs propres -- Exercices.ipynb146
1 files changed, 104 insertions, 42 deletions
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
+}