Projet ...
Nom étudiant1, nom étudiant2
14 avril 2023
Table des matières
1 Introduction 2
2 Matériel et Méthodes 2
2.1 La recherche de zéros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Les outils python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.3 Les codes python (voir annexe) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
3 Résultats 4
3.1 Partie une . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.2 Partie deux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 Discussion des résultats 4
5 Conclusion 4
6 Annexe 7
6.1 Codes python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
Question 1.2.1.9 -- Methode Newton-Raphson -- cas 2
Fonction sin x
1.0 1ère étape de l'algorithme
résultat de la méthode de Newton-Raphson
y=0
0.8
0.6
y
0.4
0.2
0.0
0.1 0.0 0.1 0.2 0.3 0.4 0.5
x
Figure 1 – Première figure, 70% de « column width »
1 Introduction
Le texte de l’intro. Voir lyxIntro1.lyx sur moodle pour démarrer avec LyX.
Une fauote d’orthographe devrait être souligné automatiquement dans LyX, mais aussi dans
des éditeurs de LaTeX comme TexMaker (en local) ou overleaf (en ligne).
La physique numérique est un outil de recherche en physique important [1].
2 Matériel et Méthodes
2.1 La recherche de zéros
On voit dans la figure 1 une application de la méthode de Newton.
Dans la figure 2 on voit le principe de la méthode de dichotomie (figure 2a) et de la méthode
de Newton (figure 2b).
2.2 Les outils python
Nous avons utilisé numba [2] et même sur GPU [3].
2.3 Les codes python (voir annexe)
Le premier code python (annexe, listing 1) trace une fonction.
Le deuxième code python (annexe, listing 2) implémente la méthode de dichotomie.
2
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
Question 1.2.1.5 -- Methode Newton-Raphson
1.5 Fonction x - cos x
Dichotomie: fonction test 1ère étape de l'algorithme
1 2ème étape de l'algorithme
1.0 y=0
0
a0, a1 0.5
1
cos(x) - x
b0
y
2 b1, b2 0.0
a2
3 0.5
4
0.0 0.5 1.0 1.5 2.0 2.5 3.0 1.0
x [radians] 0.0 0.2 0.4 0.6
x
0.8 1.0 1.2 1.4
(a) dichotomie, 50% de « column width » (b) Newton, 50% de « column width »
Figure 2 – Figure avec deux sous-figures
3
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
x[m2 ] y[m/s] z[ ms ] R[kg sm2 ] d[A]
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
Table 1 – Un tableau de valeurs
3 Résultats
Les résultats...
3.1 Partie une
Les résultats sont reportés dans le tableau 1.
3.2 Partie deux
Les résultats sont affichés dans la figure 3
4 Discussion des résultats
La discussion....
5 Conclusion
Et pour finir la conclusion...
4
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
Question 1.2.1.5 -- Methode Newton-Raphson
1.5 Fonction x - cos x
Dichotomie: fonction test 1ère étape de l'algorithme
1 2ème étape de l'algorithme
1.0 y=0
0
a0, a1 0.5
1
cos(x) - x
b0
y
2 b1, b2 0.0
a2
3 0.5
4
0.0 0.5 1.0 1.5 2.0 2.5 3.0 1.0
x [radians] 0.0 0.2 0.4 0.6
x
0.8 1.0 1.2 1.4
(a) dichotomie (b) Newton
Question 1.2.1.5 -- Methode Newton-Raphson
1.5 Fonction x - cos x
Dichotomie: fonction test 1ère étape de l'algorithme
1 2ème étape de l'algorithme
1.0 y=0
0
a0, a1 0.5
1
cos(x) - x
b0
y
2 b1, b2 0.0
a2
3 0.5
4
0.0 0.5 1.0 1.5 2.0 2.5 3.0 1.0
x [radians] 0.0 0.2 0.4 0.6
x
0.8 1.0 1.2 1.4
(c) dichotomie (d) Newton
Figure 3 – Figure avec quatre sous-figures, deux colonnes, deux lignes. Sous LyX il suffit
simplement de fermer les cadres « float » et de les placer comme souhaité :
1) l’un à côté de l’autre => placer les rectangles fermés « float » sur une même ligne.
2) l’un en-dessous de l’autre => en mettant les rectangles fermés « float » sur la ligne suivante.
5
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
Pour la biblio, il suffit d’ajouter des références au fichier biblio.bib ou encore en ajoutant
d’autres fichiers *.bib en cliquant sur le cadre gris « BibTeX ... » ci-dessous. Pour avoir les
citations en format BibTeX, il suffit de les exporter depuis les sites des journaux scientifiques
directement (chercher « Citer » ou « Cite ») ou alors depuis google scholar le button « Citer »
sous chaque référence : scholar.google.com
Pour assembler une grande biblio, l’outil zotero est une grande aide : www.zotero.org
Il y a une fonction pour exporter la collection sous format BibTeX (clique droit sur la
collection, puis « Export Collection » et choisir le format « BibTeX »). Zotero permet aussi
d’importer des pages web pour les citer (ex : wikipedia).
Puis pour éditer un fichier *.bib, il y a un simple éditeur de text (spyder ou notepad) ou
encore l’outil JabRef : www.jabref.org
Parfois c’est nécessaire, quand une référence contient des caractères spéciaux que LaTeX ne
digère pas bien.
Références
[1] Amy Lisa Graves and Adam D. Light. Hitting the ground running : Computational physics
education to prepare students for computational physics research. Computing in Science &
Engineering, 22(4) :50–60, jul 2020.
[2] Siu Kwan Lam, Antoine Pitrou, and Stanley Seibert. Numba : A llvm-based python jit
compiler. In Proceedings of the Second Workshop on the LLVM Compiler Infrastructure in
HPC, LLVM ’15, New York, NY, USA, 2015. Association for Computing Machinery.
[3] Lena Oden. Lessons learned from comparing c-cuda and python-numba for gpu-computing.
In 2020 28th Euromicro International Conference on Parallel, Distributed and Network-
Based Processing (PDP), pages 216–223, 2020.
6
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
6 Annexe
Si besoin, pour mettre des figures supplémentaires, mais moins importantes. Ou encore les
codes python.
6.1 Codes python
Sous LyX on peut importer un code via le menu « Insert->File->Child Document », comme
c’est fait ici :
Listing 1 – q01.py
1 # -* - coding : utf -8 -* -
2 """
3 Created on Fri Jan 7 12:18:56 2022
4
5 @author : chiche
6 """
7 import numpy as np
8 import matplotlib . pyplot as plt
9 import configMatplotlib # pour un affichage en noir et blanc pour l ’
impression
10
11 #
=============================================================================
12 # Question 1
13 #
=============================================================================
14
15 # On d é finit la fonction test : f ( x ) = cos ( x ) - x
16
17 def test_function ( x ) :
18
19 # x : angle en radians
20
21 return np . cos ( x ) - x
22
23 # On plot cette fonction test avec matplotlib sur l ’ intervalle [0 , pi ]
24
25 # on cr é e un tableau de points r é guli è rement espac é s sur l ’ intervalle [0 , pi
]
26 x = np . arange (0 , np . pi , 0.1)
27
28 # On calcule les valeurs de f ( x ) correspondantes que l ’ on met dans une
29 # variable f
30 f = test_function ( x )
31
32 plt . plot (x , f ) # on plot f ( x )
33 plt . xlabel ( " x [ radians ] " ) # label sur l ’ axe des x
34 plt . ylabel ( " cos ( x ) - x " ) # label sur l ’ axe des y
35 plt . axhline ( y =0 , color = ’k ’)
36 plt . axvline ( x =0.1 , linestyle = ’ - ’ , label = ’ $a_ {0} , a_ {1} $ ’)
37 plt . axvline ( x =1.7 , linestyle = ’: ’ , label = ’ $b_ {0} $ ’)
38 plt . axvline ( x =0.9 , linestyle = ’ -- ’ , label = ’ $b_ {1} , b_ {2} $ ’)
39 plt . axvline ( x =0.5 , linestyle = ’ -. ’ , label = ’ $a_ {2} $ ’)
40 plt . title ( " Dichotomie : fonction test " , fontsize = 12) # titre
41 plt . legend ()
42 plt . tight_layout ()
7
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
43 plt . savefig ( " graph01 . pdf " )
44 plt . show () # pour afficher la figure
LyX utilise le paquet LaTeX « listings » pour cela, avec la commande « \lstinputlisting ».
On peut changer le style d’affichage dans le menu « Document->Settings->LaTeX Preamble »
où on peut mettre du code LaTeX pour configurer les « listings ». Le style est adapté de cette
source :
https://www.overleaf.com/learn/latex/Code_listing
Listing 2 – q02.py
1 # prog02 . py
2 # R é ponse à la question 1.1.1.2
3
4 from prog01 import test_function
5
6
7 #
=============================================================================
8 # Question 1
9 #
=============================================================================
10
11 # Fonction dichotomie
12
13 def dichotomie (a , b , x0 , epsilon ) :
14 # La dichotomie s ’ applique sur un intervalle [a , b ] sur lequel la
fonction
15 # f s ’ annule . Cela est v é rifi é par la condition f ( a ) * f ( b ) <0
16 if test_function ( a ) * test_function ( b ) < 0:
17
18 # On d é finit un crit è re de convergence
19 while abs ( test_function ( x0 ) ) > epsilon :
20 # Si la conditon de convergence n ’ est pas respect é e on affecte à
21 # x0 une valeur correspondant au milieu de l ’ intevalle [a , b ]
22 x0 = ( a + b ) / 2.0
23
24 # On v é rifie ensuite si la racine se trouve dans l ’ intervalle
25 # [a , x0 ] ou [ x0 , b ]
26 if test_function ( a ) * test_function ( x0 ) < 0:
27 # si la racine est dans l ’ intervalle [a , x0 ] on affecte a b
28 # la valeur de x0
29 b = x0
30
31 elif test_function ( b ) * test_function ( x0 ) < 0:
32 # si la racine est dans l ’ intervalle [ x0 , b ] on affecte a b
33 # la valeur de x0
34 a = x0
35
36 else :
37 a = x0
38 b = x0
39 epsilon = 0
40
41 print ( " f ( x ) vaut 0 pour x valant %.3 f , avec une precison de %.8 f " \
42 % ( x0 , epsilon ) )
43
44 return x0
45
8
Sorbonne Université, UE LU3PY126 FOAD, 2023 Nom1, Nom2
46 else :
47 print ( " Pas de racine de la fonction f ( x ) pour x compris entre a et b
")
48
49
50 # On teste le r é sultat obtenu
51
52 x0 = dichotomie (0 , 1 , 0.5 , 1e -8)
53 print ( test_function ( x0 ) )
54
55 # pour epsilon = 1e -8 on trouve x0 = 0.738 et f ( x0 ) ~ -7e -9 < epsilon