283 lines
5.9 KiB
Plaintext
283 lines
5.9 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",
|
|
"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": [
|
|
"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": [
|
|
"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",
|
|
"1. $(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": [
|
|
"2. $(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": [
|
|
"3. (\\*) $(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",
|
|
"- 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": [
|
|
"1. Quelle est la nature de la suite? Quels sont les paramètres?"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"2. Copier puis modifier le programme pour calculer $u_{10}$."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"3. Idem pour calculer la valeur de $u_{1000}$"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"- É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": [
|
|
"- (\\*) $(u_u)$ a pour premier terme $u_0 = 700$ et pour formule de récurence $u_{n+1} = 0.7u_n - 400$"
|
|
]
|
|
},
|
|
{
|
|
"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",
|
|
"Expliquer ce que fait chaque ligne."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 12,
|
|
"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\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": "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
|
|
}
|