352 lines
7.5 KiB
Plaintext
352 lines
7.5 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Suite et répétition\n",
|
|
"\n",
|
|
"Dans tout ce TP, il est demandé de ne **jamais** utiliser la formule explicite pour répondre aux consignes.\n"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Calculer des termes d'une suite\n",
|
|
"\n",
|
|
"Ci-dessous, un programme python qui permet de calculer des termes d'une suite. \n",
|
|
"\n",
|
|
"1. Reconnaître la nature et les paramètres de cette suite. *Vous pouvez modifier le programme pour afficher les résultats des calculs*."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"u = 2\n",
|
|
"u = u - 1.5\n",
|
|
"u = u - 1.5\n",
|
|
"u = u - 1.5\n",
|
|
"u = u - 1.5\n",
|
|
"u = u - 1.5"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Réponse:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"2. Même question pour la suite suivante"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"t = 5\n",
|
|
"t = 2*t\n",
|
|
"t = 2*t\n",
|
|
"t = 2*t\n",
|
|
"t = 2*t\n",
|
|
"t = 2*t\n",
|
|
"t = 2*t"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Réponse:"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"3. Pour les suites suivantes écrire une programme python qui permet de calculer et afficher les valeurs de $u_1$, $u_5$ et $u_{10}$.\n",
|
|
"\n",
|
|
"a. $(u_n)$ est géométrique de raison 1.2 et de premier terme $u_0 = 23$."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"b. $(u_n)$ est arithmétique de raison -2 et de premier terme $u_0 = 7$"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"c. (\\*) $(u_u)$ a pour premier terme $u_0 = 3$ et pour formule de récurence $u_{n+1} = 2u_n - 1$"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Éviter les répétitions: boucle for\n",
|
|
"\n",
|
|
"Dans les programmes précédents, beaucoup de lignes se répètent. Imaginez que l'on demander $u_{1000}$, cette méthode de programmation ne serait pas satisfaisant.\n",
|
|
"\n",
|
|
"1. Le programme suivant calcule les termes d'une suite et affiche le terme 5. "
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"2.1020201002\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"u = 2\n",
|
|
"for i in range(5):\n",
|
|
" u = u *1.01\n",
|
|
"print(u)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"a. Quelle est la nature de la suite? Quels sont les paramètres?"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"b. Copier puis modifier le programme pour calculer $u_{10}$."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"c. Idem pour calculer la valeur de $u_{1000}$"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"2. Écrire un programme qui calcule $u_{500}$ quand $(u_n)$ est une suite géométrique de raison 0.99 et de premier terme 10 000."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"3. (\\*) $(u_u)$ a pour premier terme $u_0 = 700$ et pour formule de récurence $u_{n+1} = 0.7u_n - 400$. Calculer $u_{50}$."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"## Détecter des seuils: boucle while\n",
|
|
"\n",
|
|
"Ci-dessous, un programme qui répète plusieurs actions **jusqu'à** ce que quelque chose arrive.\n",
|
|
"\n",
|
|
"1. Expliquer ce que fait chaque ligne, en utilisant les commentaires #... comme fait à la première ligne."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"u( 0 ) = 5\n",
|
|
"u( 1 ) = 7\n",
|
|
"u( 2 ) = 9\n",
|
|
"u( 3 ) = 11\n",
|
|
"u( 4 ) = 13\n",
|
|
"u( 5 ) = 15\n",
|
|
"u( 6 ) = 17\n",
|
|
"u( 7 ) = 19\n",
|
|
"u( 8 ) = 21\n",
|
|
"u( 9 ) = 23\n",
|
|
"u( 10 ) = 25\n",
|
|
"u( 11 ) = 27\n",
|
|
"u( 12 ) = 29\n",
|
|
"u( 13 ) = 31\n",
|
|
"u( 14 ) = 33\n",
|
|
"u( 15 ) = 35\n",
|
|
"u( 16 ) = 37\n",
|
|
"u( 17 ) = 39\n",
|
|
"u( 18 ) = 41\n",
|
|
"Ah! u(n) est plus grand que 40 après avoir répété 18 fois le calcul.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"u = 5 # assigne 5 à la variable u\n",
|
|
"n = 0\n",
|
|
"print(\"u(\", n, \") = \", u)\n",
|
|
"\n",
|
|
"while u < 40:\n",
|
|
" u = u + 2\n",
|
|
" n = n + 1\n",
|
|
" print(\"u(\", n, \") = \", u)\n",
|
|
"\n",
|
|
"print(\"Ah! u(n) est plus grand que 40 après avoir répété\", n, \"fois le calcul.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"2. Soit $(u_n)$ une suite géométrique de raison 1.2 et de premier terme 10. Déterminer $n$ pour que $u_n$ soit supérieur à 1000."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"3. Un camion est acheté 40 500€ en 2020. Chaque année, il perd 20% de sa valeur. En quelle année la valeur du camion sera inférieur à 1 000€?"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"4. On souhaite mettre 10 000€ en banque. On propose deux placements.\n",
|
|
"\n",
|
|
" - Placement 1: rendement fixe de 500\\euro par ans\n",
|
|
" - Placement 2: rendement variable de 1% de la valeur initiale.\n",
|
|
"\n",
|
|
"Combien d'année faudra-t-il attendre pour que le placement 2 devienne plus rentable que le premier?"
|
|
]
|
|
},
|
|
{
|
|
"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.8.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 4
|
|
}
|