introduction à la programmation pythonimagine.inrialpes.fr/people/damien.rohmer/documents/... ·...
TRANSCRIPT
![Page 1: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/1.jpg)
Introduction à la programmation
Python
2013
Damien Rohmer
000
![Page 2: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/2.jpg)
Premier "programme"
001
![Page 3: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/3.jpg)
Premier "programme"
002
![Page 4: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/4.jpg)
Commandes
Notion de variables:
a est une variable (qui vaut 7)b est une variable (qui vaut 2)
003
![Page 5: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/5.jpg)
Commandes
Notion de variables:
> 7
004
![Page 6: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/6.jpg)
Commandes
Affichage à l'écran:
> le resultat de 2+2 vaut 4
005
![Page 7: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/7.jpg)
Commandes
Types de variables:
a est un nombre (entier)
b est un nombre (à virgule)
c est un texte
a+b OK
a+cunsupported operand type(s) for +: 'int' and 'str'
006
![Page 8: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/8.jpg)
Commandes
Types de variables:
007
![Page 9: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/9.jpg)
Commandes
Variable nombre/texte:
ceci est du texte
ceci est un nombre
> 4+72+2> 15 008
![Page 10: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/10.jpg)
Commandes
Variable nombre/texte:
transforme un nombre en texte(str=string)
> 1278
009
![Page 11: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/11.jpg)
L'aide
Pour obtenir de l'aide sur une fonction:
help(nom_fonction)
ex. help(pow)
http://docs.python.org/2/index.html
http://docs.python.org/3/index.html
Site web:
010
![Page 12: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/12.jpg)
Ecriture dans un fichier
Ecrire ligne à ligne est fastidieux ...
On écrit d'abord dans un fichier texte
On lance Python sur le fichier
(.py = fichier texte lisible par Python)
011
![Page 13: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/13.jpg)
Editeur Python
Editeur de texte (attention à l'indentation)
- Linux: Kate- Window: par defaut, pyscripter
Editeur type Matlab: Spyder
012
![Page 14: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/14.jpg)
Python: le langage
Création en 1990 (C ~ 1973)
Scripts, manipulation texte, pas de scientifique
Module Numpy en 2005
Developpement du calcul scientifique
Python 2.0 en 2000Python 3.0 en 2009
Python devient un acteur majeur du monde du calculscientifique- beaucoup de modules (scientifique, visualisation, etc)- lisible- simple à écrire- language haut niveau- potentiellement optimisable 013
![Page 15: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/15.jpg)
Python: positionnementTout usage
Spécialisé
N'est pas prévupour du scientifique
Peut faire du scientifique
C++C
Python
Fortran
Java
Ada
JavaScript
PHP
Lua
Maple
Mathematica
MatlabPerl
Tcl
Basic
C#
014
![Page 16: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/16.jpg)
Python: positionnementSimple, Lisible
Complexe
C++
C
Python
Ada
Java
015
![Page 17: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/17.jpg)
Python: Les + / -
+ Langage très lisible
Lisibilité d'un code = Le + Important
Un code est beaucoup plus lue qu'écritLe code est sa propre documentationErreur facilement détectable = gain de temps
016
![Page 18: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/18.jpg)
+ Langage très lisible
Java
Python
Ce qui est simple s'écrit simplement
017
![Page 19: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/19.jpg)
+ Langage très lisible
C++ : occurence dans un conteneur
Python
Commentaires indispensables!!
Est-ce utile de commenter?
La généricités'écrit "naturellement"
018
![Page 20: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/20.jpg)
+ Langage très lisible
C
Python
Commentaires + qu'indispensables!!
...+ danger mémoire "run-time"
019
![Page 21: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/21.jpg)
Python: Les + / -
+ Langage très lisible
+ Algorithme proche du langage
+ Utilisé en industrie script
calcul
(apprentissage)
- Pas d'apprentissage "hardware"/OS
- Délicat pour code très volumineuxtypage dynamique
020
![Page 22: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/22.jpg)
Python VS
C + Aisance codage, clareté- Pas de contrôle bas niveau (embarqué, OS)- Lent
C++ + Clareté- Lent
Java + Simple, moins verbeux+ Applicable science (operateurs)- Moins répendu
Matlab + Vraie informatique, structures données+ Rapide- Moins "sucre syntaxique"
021
![Page 23: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/23.jpg)
Plan
1: Bases du language
2: Librairie mathématique et affichage graphique
3: Entrées/sorties, utilisation de fichiers
022
![Page 24: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/24.jpg)
Plan
1: Bases du language
2: Librairie mathématique et affichage graphique
3: Entrées/sorties, utilisation de fichiers
Conditions: if/elseListesCreation de listes, iterations "for"Fonctions
Manipulation de fonctions réellesCalcul intégral
Boucles forBoucles while
Recherche de zéros par dichotomie
023
![Page 25: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/25.jpg)
Plan
Numpy: arrayCalculs géométriques
Matplotlib: affichage de courbes
Dérivée discrète et équations différentiellesPendule oscillant
MatricesRésolution système linéaires
DiagonalisationRacines de polynomes
Affichage de matrices et d'imagesAffichage de fonctions 2DFractales
Champ de vecteursMécanique des fluides
1: Bases du language2: Librairie mathématique et affichage graphique
3: Entrées/sorties, utilisation de fichiers 024
![Page 26: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/26.jpg)
Plan
Chaine de caractères
Lecture et écriture de fichiersVisualisation de données scientifiquesFormattage de fichiers de notes
Communication avec programmes externes
1: Bases du language2: Librairie mathématique et affichage graphique3: Entrées/sorties, utilisation de fichiers
025
![Page 27: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/27.jpg)
Conditions: si, sinon
026
![Page 28: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/28.jpg)
Condition if"si"
(si a fois b est plus grand que 22)
027
![Page 29: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/29.jpg)
Condition if"si"
: début d'un bloc de traitement
espace => bloc d'instructions
028
![Page 30: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/30.jpg)
Condition if"si"
029
![Page 31: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/31.jpg)
Condition if / else"si / sinon"
si a fois b est supérieur à 22 alors "j'affiche ce message"sinon j'affiche "ceci est un autre message"
:
030
![Page 32: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/32.jpg)
Condition if / else"si / sinon"
si a est égale à 6 alors affiche "a vaut 6"sinon affiche "a ne vaut pas 6"
Cas particulier du test d'égalité
symbole ==test d'égalité
a=b
a==b
Math Code
affectation
test d'égalité(vaut vrai ou faux)
031
![Page 33: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/33.jpg)
Condition if / else"si / sinon"
Conditions if/elif/elseelif = else, if (/ sinon, si ...)
:[4,5[
032
![Page 34: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/34.jpg)
Condition if imbriqués
Quelle courbe dessine y si x varie ?
:
:
>
2x
-2(x+1)
033
![Page 35: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/35.jpg)
Condition if imbriqués
Application:
Soit 2 points A=(x1,y1) et B=(x2,y2)
Indiquer si A est au dessus/dessous de B gauche/droite
A
B dessusdroite
dessousdroite
dessusgauche
dessousgauche
034
![Page 36: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/36.jpg)
L'indentation
Débatphilosophique ... religieux
!=
y y
L'indentation fait partie du code!!!
Ne s'execute pas!IndentationError: unexpected indent
035
![Page 37: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/37.jpg)
L'indentation
!=
y y
+ Force à la lisibilité du codeBon pour l'apprentissage
+/- Copié-coller difficileMais: copié-coller est à éviter
- Portabilité: compatibilité Tab, espaces, ... (éditeur obligatoire)
036
![Page 38: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/38.jpg)
Les listes d'éléments
037
![Page 39: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/39.jpg)
Ensemble éléments: Listes
1 7 5 9 -4 3[0] [1] [2] [3] [4] [5]
crochets [ ... ] indiquent une liste
indices:
contenu:
038
![Page 40: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/40.jpg)
Ensemble éléments: Listes
1 7 5 9 -4 3[0] [1] [2] [3] [4] [5]indices:
contenu: ??[6]
IndexError: list index out of range
039
![Page 41: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/41.jpg)
Ensemble éléments: Listes
Une liste peut contenir des mots
"pomme" "poire" "banane" "peche"
[0] [1] [2] [3]
040
![Page 42: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/42.jpg)
Ensemble éléments: Listes
Une liste peut contenir différents types
1.45 "un torchon" "une serviette"
[0] [1] [4]
-7
[2] [3]
1
041
![Page 43: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/43.jpg)
Ensemble éléments: ListesAjouter des éléments dans une liste
042
![Page 44: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/44.jpg)
Ensemble éléments: ListesSupprimer des éléments dans une liste
043
![Page 45: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/45.jpg)
Ensemble éléments: ListesCréer une "liste" particulière
4 5 6 7 8
8 5 2 -1
a
b
range(debut,fin,[increment])
stop 1 élémentavant fin
044
![Page 46: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/46.jpg)
Ensemble éléments: ListesNombre d'éléments d'une liste
045
![Page 47: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/47.jpg)
Ensemble éléments: ListesIndexation inverse
046
![Page 48: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/48.jpg)
Sous partie d'une liste
-4 5 -7 4 1 2 -2.20 1 2 3 4 5 6
ma_sous_liste_2
ma_sous_liste_1
047
![Page 49: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/49.jpg)
Trier une liste
unorderable typesstr()<int()
048
![Page 50: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/50.jpg)
Compter nombre d'occurences
049
![Page 51: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/51.jpg)
Insérer un élément dans une liste
4 7 4 8 65 1 7 9 -4 5 80 1 2 3 4 5 6 7 8 9 10
-3.12
4
050
![Page 52: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/52.jpg)
Supprimer par valeur
Ne supprime qu'une valeur (la première trouvée)
Différent de: del(ma_liste[k])!
supprime le kème élément (indice)
Recherche valeur et supprime l'élément
051
![Page 53: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/53.jpg)
Liste de listes
052
![Page 54: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/54.jpg)
Application sur les listes
Soit
Supprimer le deuxième élément de la liste
Afficher le troisième élément de la nouvelle liste
Insérer un 2 en quatrième position de la nouvelle liste
Soustraire 3 à l'avant dernier élément
Afficher la nouvelle liste
Trier la nouvelle liste puis l'afficher
053
![Page 55: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/55.jpg)
Ensemble éléments: ListesExercice:
Combien y a t'il de nombres entre -525 et 640 (inclus)en comptant de 5 en 5 ?
055
![Page 56: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/56.jpg)
3
Egalité de liste
1 2 4 5 6liste_1
liste_2
0 1 2 3 4 5
-1
L'affectation de liste référence la même entité
056
![Page 57: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/57.jpg)
3
Copie de liste
1 2 4 5 6liste_1
liste_2
0 1 2 3 4 5
Si l'on souhaite dupliquer une liste, on appelle explicitementlist(nom_liste)
création d'une copie de la liste
31 2 -1 5 60 1 2 3 4 5
057
![Page 58: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/58.jpg)
Copie de liste
liste_1:
sous_liste:
1 4 7 8 5 1 4 7
7 8 15 10 1 2 3
0 1 2 3 4 5 6 7
Copie "automatique"par sous liste
058
![Page 59: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/59.jpg)
Itération sur les listes
le mot clé "for"
059
![Page 60: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/60.jpg)
Créer des listes
Exemple pour
En francais: L = (k-2)^2 pour k variant dans [0,N[
En code
(** :puissance)
060
![Page 61: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/61.jpg)
La boucle "pour"
[ f(x) for x in nom_liste ]
Symbole d'une liste
Fonction à appliquer
nom de la variablequi est itérée
on itère
"dans" quoi
la liste que l'on parcourt
061
![Page 62: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/62.jpg)
Application
Calculer:
(|x| : abs(x))
062
![Page 63: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/63.jpg)
Application
Calculer:
(|x| : abs(x))
063
![Page 64: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/64.jpg)
Application
affichage (plot=dessine, show=montre à l'écran)
064
![Page 65: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/65.jpg)
Application
Avec les bonnes abscisses + echantillons
en rougedessinerdes
065
![Page 66: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/66.jpg)
Les fonctions
066
![Page 67: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/67.jpg)
Les fonctions
Remarque:
compliqué ... peu lisible!
On souhaiterait écrire:
avec f(k)= ... 067
![Page 68: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/68.jpg)
Les fonctions
068
![Page 69: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/69.jpg)
Les fonctions
def nom_fonction(argument) :
return valeur
Faire quelque chose ...
069
![Page 70: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/70.jpg)
Les fonctions
Les fonctions peuvent être compliquées
070
![Page 71: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/71.jpg)
Les fonctions : retour d'arguments
retour "liste"
récupère chaque argument(unpack)
ErreurValueError: too many values to unpack
071
![Page 72: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/72.jpg)
Multi fichiers
ma_lib.py
namespace automatique(pas de collisions de noms)
072
![Page 73: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/73.jpg)
Multi fichiers
ma_lib.py
plus de namespace
non accessible
073
![Page 74: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/74.jpg)
Multi fichiers
ma_lib.py
! A éviter
Tout est accessible
074
![Page 75: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/75.jpg)
Les fonctions
Les fonctions peuvent prendre des paramètres
075
![Page 76: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/76.jpg)
Les fonctions
Les fonctions peuvent etre vectorielles
076
![Page 77: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/77.jpg)
Manipulation de fonctions réelles
077
![Page 78: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/78.jpg)
Echantillonner dans
Calculer et stocker N valeurs également réparties sur [0,1[
0.0 0.2 0.4 0.6 0.8
0 1
x
078
![Page 79: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/79.jpg)
Echantillonner dans
Calculer et stocker les N échantillons de f(x)
0.0 0.2 0.4 0.6 0.8
0 1
y[0] y[1] y[2] y[3] y[4]y
x
079
![Page 80: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/80.jpg)
Echantillonner dans
Calculer N échantillons de f pour
080
![Page 81: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/81.jpg)
Application
La diode possède une caractéristique s'exprimant sous cette forme
I0=100 nAq=1.6 10-19 Ck=1.38 10-23 J/K
Tracer la caractéristique pour T=25° et T=65°(298K) (338K)
Rem: Pour exponentielle from math import exp
exp(x) 081
![Page 82: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/82.jpg)
Fonctions disponibles
083
![Page 83: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/83.jpg)
Somme des éléments
Application:
084
![Page 84: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/84.jpg)
Min/Max des éléments
085
![Page 85: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/85.jpg)
Il existe un élément ...
Question:
En francais: Il existe au moins un élément tel que ak égale 4pour k variant entre [0,N[
En code: True
False
(type booléen)
086
![Page 86: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/86.jpg)
Il existe un élément ...
Exemple:
087
![Page 87: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/87.jpg)
Tous les éléments ...
Question:
En francais: Tous les ak sont inférieurs à 12 pour k variant entre [0,N[
En code: True
False
(type booléen)
088
![Page 88: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/88.jpg)
Application
Vérifiez que les vecteurs sont tous unitaires
(On évitera la notation vk==a pour des nombres à virgule)
089
![Page 89: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/89.jpg)
Cas d'application
Calcul intégral
091
![Page 90: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/90.jpg)
Soit
Calculer cette intégrale pour a=3, b=2, c=1 (prendre N=100)
Calcul intégral
092
![Page 91: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/91.jpg)
Calcul intégral
Tracer le log de l'erreur en fonction de N
Quelle est l'erreur E par rapport à la vraie valeur?
094
![Page 92: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/92.jpg)
Calcul intégral
Meilleure approximation
096
![Page 93: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/93.jpg)
Calcul intégral
Evaluer la longueur de la courbe de f sur [0,1]
099
![Page 94: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/94.jpg)
Boucle for "avancée"
100
![Page 95: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/95.jpg)
Boucle sur des mots
j'aime manger des pommesj'aime manger des poiresj'aime manger des champignonsj'aime manger des poivrons
101
![Page 96: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/96.jpg)
Boucle sur plusieurs vecteurs
met les éléments ensemble
math : 12.1physique : 8.4chimie : 12.3informatique : 7.8
102
![Page 97: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/97.jpg)
Boucle "classique"
[ f(x) for x in nom_liste]
Remarque: Parfois/souvent f est - complexe - ne retourne rien / modifie x (la liste) - n'est écrite qu'une seule fois
for x in nom_liste:
f(x)
103
![Page 98: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/98.jpg)
Boucle "classique"
Exemple
a%breste de la division euclidienne
104
![Page 99: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/99.jpg)
Boucle "classique"
Soit:
Afficher "attention + nom_matiere" si note<10Afficher "ATTENTION + nom_matiere" si note<8Afficher "TB + nom_matiere" si note>15
105
![Page 100: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/100.jpg)
Boucle "classique"
Modification d'éléments:
Ajouter 2 à toutes les notes si elles sont inférieures à 8
107
![Page 101: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/101.jpg)
Récupérer valeur et indice
0 9.11 8.42 16.33 7.8
Similaire à :
108
![Page 102: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/102.jpg)
Récupérer valeur et indice
Application: Rendre une suite croissante
Soit la suite
Si , alors
109
![Page 103: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/103.jpg)
Application
Ajouter 2 points à chaque note si m est inférieur à 10Ajouter seulement 1 point pour les mathsSi m inférieur à 8, rajouter 3 points à la chimie
Soit:
Soit m la moyenne des notes
111
![Page 104: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/104.jpg)
Application
Soit f(x)=E(x)%2 E: partie entière (int(x))
x appartenant à [0,10]
Calculer N=200 échantillons (yk) de f sur [0,10[
Calculer zk, tel que
pour k dans [1,N-1[, sinon zk=yk pour k=0 et k=N
Itérer le processus sur z ... 15 fois
113
![Page 105: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/105.jpg)
Boucle while / "tant que"
115
![Page 106: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/106.jpg)
Boucle while / "tant que"
while condition_vraie :
Faire quelque chose
On ne connait pas forcémentle nombre d'itérations
116
![Page 107: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/107.jpg)
Application: encadrement
Soit f une fonction continue de
Soit Trouver
ab
aa
encadrement de f(xi)=0
117
![Page 108: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/108.jpg)
Application: encadrement
ab
aa
encadrement de f(xi)=0
118
![Page 109: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/109.jpg)
Dichotomie
a
bc=(a+b)/2
f(c)
f(a)>0
f(b)>0[a,b]
120
![Page 110: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/110.jpg)
Dichotomie
a
bc
f(c)>0
f(a)>0
f(b)>0[a,b]
[c,b]
121
![Page 111: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/111.jpg)
Dichotomie
a
bc
f(c)>0
f(a)>0
f(b)>0[a,b]
[c,b]
d
f(d)
122
![Page 112: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/112.jpg)
f(d)<0
Dichotomie
a
bc
f(c)>0
f(a)>0
f(b)>0[a,b]
[c,b]
d
[c,d]
123
![Page 113: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/113.jpg)
f(d)<0
Dichotomie
a
bc
f(c)>0
f(a)>0
f(b)>0[a,b]
[c,b]
d
[c,d]
e
[e,d] 124
![Page 114: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/114.jpg)
f(d)<0
Dichotomie
a
bc
f(c)>0
f(a)>0
f(b)>0[a,b]
[c,b]
d
[c,d]
e
[e,d]
f
[f,d] 125
![Page 115: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/115.jpg)
Dichotomie
Soit [a,b], f(a)>0 et f(b)<0
Tant que |b-a|>erreur_max
Calculer f(c), avec c=(a+b)/2
Si f(c)>0 [a,b] <- [c,b] Sinon [a,b] <- [a,c]
Algorithme
a b
a
b
b
a
f
f>0
f<0
126
![Page 116: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/116.jpg)
Dichotomie
Application: calculer le zéro de f pour un intervalle d'encadrement de 10-6
127
![Page 117: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/117.jpg)
Passage arguments
Passage par copie? Passage par référence?
5 [5,7]
129
![Page 118: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/118.jpg)
Passage arguments
Passage par copie? Passage par référence?
5 [5,7]
=> Passage par "partage" Call by Sharing
130
![Page 119: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/119.jpg)
Passage par "partage"
- Variables => table de correspondance (table globale, table locale)
- Passage d'argument = création d'entrée dans la table
- Les variables "mutables" sont modifiées
Jamais de "copie" de variable => + rapide
ex. liste: a[1]=4
- Les variables "immutables" ne peuvent être modifiés (nouvelle affectation = nouvelle valeur)
ex. entiers, string: b="maison"
Rem. Donne l'impression que Les variables de bases sont copiées Les variables listes, classes, sont passés par ref/ptr
131
![Page 120: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/120.jpg)
Typage fort
Python est un langage "fortement" typé(contrairement au C !)
<class 'str'><class 'int'><class 'float'><class 'bool'><class 'list'><class 'list'>
Le type est connuà tout instant
132
![Page 121: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/121.jpg)
Type
isinstance : comparaison du type
rem.Retour variable
133
![Page 122: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/122.jpg)
ID
id ~ adresse=> Mais on n'accède pas à l'objet à partir de l'id!
134
![Page 123: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/123.jpg)
Fonctions arguments
Les fonctions peuvent être passées en tant qu'argument
variable
ex. Optimisation/Intégrationnumérique
135
![Page 124: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/124.jpg)
Librairie mathématiqueet affichage
136
![Page 125: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/125.jpg)
Numpy: Array
array ressemble aux listes spécialisé pour les nombres
137
![Page 126: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/126.jpg)
Numpy: Array
additionsoustractionmultiplication par un scalaireproduit scalaire...
Rem. On ne mélange pas "mot" et nombre dans un array
138
![Page 127: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/127.jpg)
Linspace
Vecteur uniformément réparti entre [a,b] avec N échantillons
139
![Page 128: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/128.jpg)
AffichageCombinaison array + affichage
élève au carré élément à élément
140
![Page 129: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/129.jpg)
Array-range
arange: similaire à range
1 3 5 7
141
![Page 130: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/130.jpg)
Slicing
142
![Page 131: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/131.jpg)
Vecteurs particuliers
0 0 0 0 0
1 1 1 1 1 1
va
vb
143
![Page 132: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/132.jpg)
Applications
Soit la droite D passant par x0 et de vecteur directeur u
x0=(1,2)u=(1,4)
Calculer un, le vecteur directeur unitaire de même direction que u
(norme: from numpy.linalg import norm)
Soit a=x0-2un, b=x0+2un
Afficher la droite ab Afficher un point en x0
144
![Page 133: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/133.jpg)
Applications
Soit p=(3,3)
Calculer L=<ap,un>
Calculer la projection orthogonale p_proj de p sur la droite Dp_proj=a+L un
Afficher p et p_proj
Notez que les axes ne sont pas orthogonaux
Ajouter: plt.axis("square")
Afficher le segment [p,p_proj]
Calculer la distance entre p et la droite D
145
![Page 134: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/134.jpg)
Applications
Soit C le cercle de centre x0=(1,2) et de rayon 4
Stocker dans les vecteurs cx, et cy les coordonneesde N échantillons du cercle C
Construire le vecteur theta contenant N échantillonségalement répartis sur [0,2 pi]
(pi=np.pi)
Tracer le cercle C
Soit C' un cercle tangent à C de centre x0'=(7,5)
Calculer le rayon de C'
Tracer C', les points x0 et x1 et le point d'intersection entre C et C'
146
![Page 135: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/135.jpg)
Vecteurs multi-dimensionnels
p0
p1
p2
148
![Page 136: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/136.jpg)
Vecteurs multi-dimentionnels
149
![Page 137: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/137.jpg)
Embellissement graphique
150
![Page 138: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/138.jpg)
Application, afficher:
151
![Page 139: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/139.jpg)
Courbe et points 3D
153
![Page 140: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/140.jpg)
Courbe et points 3D
154
![Page 141: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/141.jpg)
Cas d'application:Equations différentielles
155
![Page 142: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/142.jpg)
Dérivée discrète
Soit une fonction réelle dérivable f
La dérivée discrète de f au point x estcalculable par la relation
Application:
Coder la fonction: f(x)=sin(x)
Calculer la dérivée numérique en 0
Comparer à la vraie valeur (pour différentes valeurs de ) 156
![Page 143: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/143.jpg)
Dérivée discrèteApplication:
Afficher f et f' sur [-30,30]
159
![Page 144: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/144.jpg)
Pendule oscillant
Equation de la dynamique:
Pas de solution analytique simple pour grand
On discrétise la dérivée (on intègre numériquement suivant t)
Si frottements, ou pendule couplé, pas de solution analytiquedu tout
160
![Page 145: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/145.jpg)
Pendule oscillant
Equation de la dynamique:
Equation discrétisée:
Afficher en fonction de t
Considérer
conservation d'energie
161
![Page 146: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/146.jpg)
Pendule oscillant
Algorithme:
0
Pour tous k
Afficher( )
162
![Page 147: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/147.jpg)
Matrices
164
![Page 148: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/148.jpg)
Matrices
165
![Page 149: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/149.jpg)
Matrices
Produit matriciel
166
![Page 150: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/150.jpg)
Matrices
Matrices carrées
167
![Page 151: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/151.jpg)
Matrices
Bloc/slicing
168
![Page 152: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/152.jpg)
Operateurs matriciels
linalg = linear algebra
169
![Page 153: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/153.jpg)
Algèbre linéaire
170
![Page 154: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/154.jpg)
Application, systeme lineaire
E1
E2
R
R
R
i2
i3
i1
Calculer i1, i2, i3 171
![Page 155: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/155.jpg)
Diagonalisation
173
![Page 156: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/156.jpg)
Application, diagonalisation
La matrice compagnon du polynome
est
Les valeurs propres de A sont les racines du polynome p
174
![Page 157: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/157.jpg)
Application, diagonalisation
Construire la matrice compagnon des polynomes suivants, et en déduire leurs racines:
175
![Page 158: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/158.jpg)
Application, diagonalisation
Afficher p3, ainsi que l'ensemble de ses racines réelles
177
![Page 159: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/159.jpg)
Application, diagonalisation
Construire un polynome dont les coefficients sont des reels aléatoires
Observez la distribution des racines dans le plan complexe
179
![Page 160: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/160.jpg)
Affichage matrices/images
181
![Page 161: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/161.jpg)
Affichage matrices/images
182
![Page 162: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/162.jpg)
Affichage matrices/images
183
![Page 163: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/163.jpg)
Affichage fonctions 2D
184
![Page 164: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/164.jpg)
Affichage fonctions 2D
Soit:
Afficher f (utiliser la colormap "hot")
185
![Page 165: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/165.jpg)
Application: Fractale
La fractale de Mandelbrot est obtenue enitérant la formule suivante:
Afficher |z| après N iterations pour
187
![Page 166: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/166.jpg)
Champs de vecteurs
189
![Page 167: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/167.jpg)
Champs de vecteurs : quiver
190
![Page 168: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/168.jpg)
Changement de coordonnées
r
Afficher et pour
191
![Page 169: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/169.jpg)
Changement de coordonnées
r
Afficher
192
![Page 170: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/170.jpg)
Application: mécanique des fluides
La vitesse d'un fluide (incompressible, non visqueux) autour d'unesphere de rayon R est donnée par
R
r
Afficher le champ de vecteur correspondant
194
![Page 171: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/171.jpg)
Lignes de champs
196
![Page 172: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/172.jpg)
Entrées/sortiesFichiers
197
![Page 173: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/173.jpg)
Chaine caracteres
Les chaines de caracteres sont des listes
m a m a i s o n0 1 2 3 4 5 6 7 8
198
![Page 174: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/174.jpg)
Chaine caracteresOn ne modifie pas une chaine de caractere
(immutable)
'str' object does not support item assignment
199
![Page 175: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/175.jpg)
Concatenation
+ concatène une chaine avec une autre
bonjoura toi!!
bonjour a toi !!
bonjour toi!!
200
![Page 176: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/176.jpg)
Majuscule, minuscule
201
![Page 177: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/177.jpg)
Séparation
Split sépare en plusieurs entités une chaine à l'aide d'undélimiteur
125+784-52.2+845=?
125
784-52.2845=?
resultat[0]
[1]
[2]
202
![Page 178: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/178.jpg)
Utilisation typique: espace
mot 0 : Maitremot 1 : Corbeau,mot 2 : surmot 3 : unmot 4 : arbremot 5 : perche
203
![Page 179: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/179.jpg)
Application: nom/prenom
Dumont , Jean
204
![Page 180: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/180.jpg)
Liste de mots
205
![Page 181: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/181.jpg)
Application
Construire et afficher une liste de nom/prénoms telle que
Soit transformée en:
DumontGontrandReneSeverin
JeanAntoineFabriceRomain
- liste ordonnée dans l'ordre alphabétique du nom- le nom et le prenom sont séparés- la première lettre du nom et prénom sont en majuscule (le reste en minuscule)
la liste:
206
![Page 182: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/182.jpg)
Conversion nombre/mot
Conversion en texte
Conversion texte en nombre
Concaténation detexte
Addition de nombre
208
![Page 183: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/183.jpg)
Application:
Extraire les notes de ce texteAfficher la moyenne correspondante
210
![Page 184: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/184.jpg)
Expression Régulière
['Dupont' , 'Ran']
http://docs.python.org/3/library/re.html
Voir doc complète:
211
![Page 185: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/185.jpg)
Fichiers
212
![Page 186: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/186.jpg)
Lecture d'un fichier
Lecture ligne à ligne
213
![Page 187: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/187.jpg)
Traitement d'un texte
Maître Pelican, sur un arbre perché,Tenait en son bec un fromage.Maître Renard, par l'odeur alléché,Lui tint à peu près ce langage :"Hé ! bonjour, Monsieur du Pelican....
214
![Page 188: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/188.jpg)
Ecriture fichier
write/ecrit(supprime/créé un fichier vierge)
215
![Page 189: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/189.jpg)
Application: Analyse données
Afficher et comparer les courbes de températures
Les fichiers disponibles fournissent les températures moyennes deLyon en fevrier et avril 2011, 2012, et 2013.
Algorithme:
Pour chacun des fichiers Pour chaque ligne à l'exception de la premiere Separer les données suivant le symbol "//" Lire la 4ème donnee en tant que nombre Stocker cette valeur dans un vecteur de temperature Afficher le vecteur de temperature
http://www.meteorologic.net/metar-climato_LFLY.html
216
![Page 190: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/190.jpg)
Application: Formatage
Soit le fichier suivant:
Ecrire le traitement qui viendra écrire le fichier suivant:
218
![Page 191: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/191.jpg)
Programmes externes
220
![Page 192: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/192.jpg)
Programmes externes
Le module "os" permet de communiquer avec le système d'exploitation
os.system(...) appel un programme externe
221
![Page 193: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/193.jpg)
Répertoires
Tous les fichiersdu répertoiredans une liste
222
![Page 194: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/194.jpg)
Traitement de fichiers
Convertir tous les fichiers .png ou .tiff d'un repertoireen .jpg
Utilisez l'outil "convert" en ligne de commande$ convert a.png b.jpg
<str>.endswith(".png")
os.path.splitext(filename)
chaine fini par ".png" ?
sépare nom et extension
223
![Page 195: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/195.jpg)
Parcours repertoires
fichier/répertoire
225
![Page 196: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/196.jpg)
Application: répertoire
Afficher les chemins de tous les fichiers contenantla chaine "int main()"
226
![Page 197: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/197.jpg)
Récupérer ligne commande
Affiche nombre de lignes / motsAffiche pourcentage de commentaires
228
![Page 198: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/198.jpg)
Structures de données
229
![Page 199: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/199.jpg)
Tuples
'tuple' object does not support item assignmenttuples are immutables
230
![Page 200: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/200.jpg)
Set
{1, 2, 4, 5, 7, 8, -5}{'cochon', 'cheval', 'ikea', 'boeuf', 'findus', 'lasagne'}
Supporte "list comprehension"
<set>.add et <set>.remove
231
![Page 201: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/201.jpg)
Set : union/intersection
232
![Page 202: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/202.jpg)
Dict
Ordonnancement: Table de hashage
clé valeur
Accès par clé
233
![Page 203: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/203.jpg)
Dict : initialisation
Egalitéclé/valeur
234
![Page 204: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/204.jpg)
Dict : Utilisation
{'Paris': ['soupe oignon', 'Vin'], 'Lyon': ['andouilette', 'Pieds de porc', 'Vin'], 'Marseille': ['Bouillabaisse', 'Ricard'], 'Strasbourg': ['Choucroute', 'Vin', 'Knack', 'Vin'], 'Dijon': ['Moutarde', 'Vin'], 'Toulouse': ['Cassoulet']}
2x
supprimeclé+valeur
valeur = liste
235
![Page 205: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/205.jpg)
Dict : Utilisation{'Paris': ['soupe oignon', 'Vin'], 'Lyon': ['andouilette', 'Pieds de porc', 'Vin'], 'Marseille': ['Bouillabaisse', 'Ricard'], 'Strasbourg': ['Choucroute', 'Vin', 'Knack', 'Vin'], 'Dijon': ['Moutarde', 'Vin'], 'Toulouse': ['Cassoulet']}
"Inverser" la structure => Pour chaque plat, quelle est la ville ?(ville n'apparait qu'une fois pour chaque plat)
236
![Page 206: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/206.jpg)
Dict : Utilisation
Dénombrez chaque mot contenu dans un fichier
238
![Page 207: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/207.jpg)
Objets
self -> objet courant(pointeur this)
240
![Page 208: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/208.jpg)
Objets, attributsappel création objet__XX__ : reservé
attribut de la classe
En Python: attributs publiques(type dynamique)
241
![Page 209: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/209.jpg)
Initialisation attributs
ordre
nom
242
![Page 210: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/210.jpg)
Conversion str
Appel à print()ou str()
243
![Page 211: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/211.jpg)
Héritage
parent
héritage
244
![Page 212: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/212.jpg)
Duck Typing
Duck Typing="Philosophie Python"
Si j'agit comme un canard, alors je "suis" un canard
=> Puissance du polymorphismeSans nécessiter relation héritage
245
![Page 213: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/213.jpg)
Opérateurs
lt:< , le:<=, gt:>, ge:>=, ...
http://docs.python.org/3/library/operator.html 246
![Page 214: Introduction à la programmation Pythonimagine.inrialpes.fr/people/Damien.Rohmer/documents/... · 2013-11-11 · Matplotlib: affichage de courbes Dérivée discrète et équations](https://reader035.vdocuments.pub/reader035/viewer/2022070912/5fb3c9c5c5066224c00dd97c/html5/thumbnails/214.jpg)
Application
Créez une classe de polynome creux qui
- Ne sauvegarde que les valeurs des coefficients indiqués (les autres sont à 0)=> Méthode append() permet d'ajouter un coefficient
- Est évalué en un point x avec la méthode eval(x)
- Permet l'addition de polynomes creux- Permet la multiplication entre polynomes creux
247