Vous êtes sur la page 1sur 7

EXAMEN

Semestre : 1 X 2 X
Session : Principale X Rattrapage X
Unité d’enseignement : Méthodes Numériques pour l’Ingénieur
Module(s) : Calcul Scientifique
Classe(s) : 1CINFO
Nombre des questions : 20 Nombre de pages : 7
Calculatrice autorisée : OUI X NON X Documents autorisés : OUI X NON X
Date : 01 Juillet 2020 Heure: 18h30 Durée : 45 minutes

Question 1 :

Soient A et B deux matrices carrées, pour calculer le produit matriciel de A et B sous python on écrit :

A A∗B B dot(A).dot(B) C A.dot(B) D A.product(B)


Question 2 :

Le code suivant retourne :

import numpy a s np
f o r i i n np . a r a n g e ( 2 , 5 ) :
print ( i )

2
3 2
3 2
A B 4 C 3 D
4 5
5 4
5
Question 3 :

Sous python, on peut remplacer la commande x = x + 1 par :

A x++ B x+ = 1 C x−1=x D x++=1


Question 4 :

Quelle est la sortie du code suivant ?

L= [ − 1 , 2 , 3 , ’CINFO ’ ]
p r i n t ( L[ − 1 ] )

A −1 B ’CINFO’ C ’O’ D 1
Question 5 :
Soit M une matrice carrée, inversible, si on veut calculer l’inverse de M sous python on écrit :

A
import numpy
numpy . i n v (M)

B
import numpy
numpy . l i n a l g . i n v e r s e (M)

1
C
import numpy
numpy . l i n a l g . i n v (M)

D
i n v (M)

Question 6 :
Nous disposons de deux listes X et Y. Parmi les propositions suivantes, indiquez celle qui permet, sous python,
de représenter Y en fonction de X avec les caractéristiques suivantes :

• Couleur de la courbe : orange


• Épaisseur de la ligne : 3
• Type de la ligne : discontinu
• Marqueur : étoile
• Taille des marqueurs : 8

A
import m a t p l o t l i b . p y p l o t a s p l t
p l t . p l o t (X, Y, ’ o∗−− ’ , l i n e w i d t h =3 , m a r k e r s i z e = 8 )
B
import m a t p l o t l i b . p y p l o t a s p l t
p l t . p l o t (X, Y, c o l o r = " o r a n g e " , l i n e s t y l e = " d a s h e d " ,
m a r k e r = " ∗ " , l i n e w i d t h =3 , m a r k e r s i z e = 8 )

C
import m a t p l o t l i b . p y p l o t a s p l t
p l t . p l o t (X, Y, c o l o r = " o r a n g e " , l i n e s t y l e = " d o t t e d " ,
m a r k e r = " ∗ " , l i n e w i d t h =3 , m a r k e r s i z e = 8 )
D
import m a t p l o t l i b . p y p l o t a s p l t
p l t . p l o t (X, Y, ’ o ∗ ’ , l i n e s t y l e = " d a s h e d " , l i n e w i d t h =3 , m a r k e r s i z e = 8 )

Question 7 : Z 1
Parmi les propositions suivantes, indiquez celle qui calcule la valeur numérique de cos(x) + sin(x) dx
−1
sous python.

A
import sympy a s s p
x= s p . s y m b o l s ( ’ x ’ )
sp . i n t e g r a t e ( sp . cos ( x )+ sp . s i n ( x ) , x )
B
import sympy a s s p
x= s p . s y m b o l s ( ’ x ’ )
sp . i n t e g r a t e ( sp . cos ( x )+ sp . s i n ( x ) , x ) . e v a l f ( )

C
import sympy a s s p
x= s p . s y m b o l s ( ’ x ’ )
sp . i n t e g r a t e ( sp . cos ( x )+ sp . s i n ( x ) , ( x , −1 ,1))

2
D
import sympy a s s p
x= s p . s y m b o l s ( ’ x ’ )
sp . i n t e g r a t e ( sp . cos ( x )+ sp . s i n ( x ) , ( x , − 1 , 1 ) ) . e v a l f ( )

Question 8 :
Identifiez le seul objet mutable parmi les objets suivants :

A
Obj_A= ’ The exam i s s o e a s y ’
B
Obj_B = ( ’ The exam i s s o e a s y ’ )
C
OBJ_C = [ ’ The ’ , ’ exam ’ , ’ i s ’ , ’ s o ’ , ’ e a s y ’ ]
D
OBJ_D = ( ’ The ’ , ’ exam ’ , ’ i s ’ , ’ s o ’ , ’ e a s y ’ )

Question 9 :
La courbe suivante représente l’erreur d’intégration de la fonction f (x) = exp(x), sur [0, 1], par la méthode
composite des trapèzes, en fonction de n, le nombre de sous intervalles de [0, 1].
Pour quelles valeurs de n l’erreur d’intégration est inférieure à 0.008 ?

A ∀n ≥ 3 B ∀n ≥ 4 C ∀n ≥ 5 D ∀n ≥ 6
Question 10 :

La courbe suivante représente la précision de la méthode de Jacobi, lors de la résolution d’un certain sys-
tème de Cramer AX = b, en fonction du nombre d’itérations. À partir de quel nombre d’itérations la précision
de la méthode de Jacobi atteint 10−9 ? Cochez la bonne réponse.

3
A 20 B 35 C 25 D 40
Question 11 :

On considère, ci-dessous, la représentation graphique de P , le polynôme d’interpolation de 3 points sur l’in-


tervalle [−1, 1].

Identifiez ces 3 points en cochant la bonne réponse.


A (−1, 1), (0, 2) et (1, 2). B (−1, 1), (0, 1) et (1, 2).
C (−1, 1), (0, 1), et (1, 0). D (−1, 0), (0.1) et (1, 2)
Question 12 :
Soit f une fonction continue sur un intervalle [a, b]. Parmi les scripts Python suivants, identifiez celui qui
Z b
approche I(f ) = f (t)dt par la méthode d’intégration simple des trapèzes.
a

A
t r a p e z e = lambda f , a , b : ( b−a ) ∗ f ( b )

B
t r a p e z e = lambda f , a , b : ( b−a ) ∗ f ( ( a+b ) / 2 )

C
t r a p e z e = lambda f , a , b : ( ( b−a ) / 2 ) ∗ ( f ( a ) + f ( b ) )

D
t r a p e z e = lambda f : ( b−a ) ∗ f ( a / 2 )

Question 13 :
les quatre scripts suivants calculent la neme puissance d’un réel a (an = a.a.a.a.a.a..a
| {z }). Indiquez celui qui est
n f ois
correctement écrit sous python :

A
def puissance ( a , n )
P=1
f o r i i n np . a r a n g e ( 0 , n )
P=P∗ a
return P

4
def puissance ( a , n ) :
P=1
f o r i i n np . a r a n g e ( 0 , n ) :
P=P∗ a
return P

C
def puissance ( a , n ) :
P=1
f o r i i n np . a r a n g e ( 0 , n ) :
P=P∗ a
return P

D
def puissance ( a , n ) :
P=1
f o r i i n np . a r a n g e ( 0 , n ) :
P=P∗ a
return P

Question 14 :
Soit la liste Date définie par :
D a t e = [ [ " J a n " , " F e r " , " Mar " , " Avr " , " Mai " , " J u i n " , " J u i l " , " Aout " , " S e p t " ,
" Oct " , " Nov " , " Dec " ] , [ " Lun " , " Mar " , " Mer " , " J e u " , " Vend " , " Sam " , " Dim " ] ]
Parmi les propositions suivantes, indiquez celle qui illustre une liste nomée Choix contenant deux tuples tels
que :
- Tuple1 est composé de : Jour = lun et Mois = Aout
- Tuple2 est composé de : Jour = Ven et Mois = Jan

A
Choix = [ ( D a t e [ 1 ] [ 0 ] , D a t e [ 0 ] [ 7 ] ) , ( D a t e [ 1 ] [ 4 ] , D a t e [ 0 ] [ 0 ] ) ]

B
Choix = [ ( D a t e [ 2 ] [ 1 ] , D a t e [ 1 ] [ 8 ] ) , ( D a t e [ 2 ] [ 5 ] , D a t e [ 1 ] [ 1 ] ) ]

C
Choix = [ [ D a t e [ 1 ] [ 0 ] , D a t e [ 0 ] [ 7 ] ] , [ D a t e [ 1 ] [ 4 ] , D a t e [ 0 ] [ 0 ] ] ]

D
Choix = [ D a t e [ 1 , 7 ] , D a t e [ 4 , 0 ] ]

Question 15 :
Soit le code Python suivant :

d e f m o n _ e n t i e r ( n ,m ) :
w h i l e n ! =m :
i f n>m:
r e t u r n m o n _ e n t i e r ( n−m,m)
else :
r e t u r n m o n _ e n t i e r ( n , m−n )
r e t u r n ( n+m) / 2
Cochez la réponse qui indique la valeur retournée par mon_entier(3,2) :
A 2 B 2.5 C 1 D 3

5
Méthode composite des rectangles à gauche
Z b
Soit f : [a, b] → R une fonction continue. L’approximation de I(f ) = f (t) dt par la méthode composite
a
des rectangles à gauche, notée c (f ),
IRg est donnée par la formule suivante :

n−1
X
c
I(f ) ≈ IRg (f ) =h f (xk ),
k=0

avec xk = a + kh, 0 ≤ k ≤ n les points d’intégrations issus de la subdivision de [a, b] en n sous intervalles
b−a
avec un pas fixe h = .
n
La fonction rectangle_gauche_composite(f,a,b,n), ci-dessous, programme IRgc (f ), où var1, var2 et var3 sont

des variables à déterminer dans les questions 16 et 17.

def rectangle_gauche_composite ( f , a , b , n ) :
h = ( b−a ) / n
s = var1
f o r k i n np . a r a n g e ( v a r 2 , v a r 3 ) :
s += f ( a+k∗h )
return h∗ s
Question 16 :

Pour var2=0 et var3=n, cochez la réponse qui indique la valeur à attribuer à var1, dans la fonction rec-
tangle_gauche_composite(f,a,b,n) :
A a B 1 C b D 0
Question 17 :
Pour var1=f(a), cochez la réponse qui indique les valeurs à attribuer à (var2,var3), dans la fonction
rectangle_gauche_composite(f,a,b,n) :
A (1, n) B (0, n) C (1, n + 1) D (0, n − 1)

Méthode composite des rectangles à droite


Z b
Soit f : [a, b] → R une fonction continue. L’approximation de I(f ) = f (t) dt par la méthode composite
a
c (f ), est donnée par la formule suivante :
des rectangles à droite, notée IRd
n
X
c
I(f ) ≈ IRd (f ) = h f (xk ),
k=1

avec xk = a + kh, 0 ≤ k ≤ n les points d’intégrations issus de la subdivision de [a, b] en n sous intervalles
b−a
avec un pas fixe h = .
n
c (f ), où var1 et var2 sont des va-
La fonction rectangle_droite_composite(f,a,b,n), ci-dessous, programme IRd
riables à déterminer dans les questions 18 et 19.

def r e c t a n g l e _ d r o i t e _ c o m p o s i t e ( f , a , b , n ) :
h = ( b−a ) / n
s = var1
X=np . a r a n g e ( a , v a r 2 , h )
f o r x in X:
s += f ( x )
return h∗ s

6
Question 18 :
Pour var2 = b+h, cochez la réponse qui indique la valeur à attribuer à var1, dans la fonction
rectangle_droite_composite(f,a,b,n) :
A f (a) B f (a + h) C −f (a) D f (a − h)
Question 19 :
Pour var1 = f(b)-f(a), cochez la réponse qui indique la valeur à attribuer à var2, dans la fonction
rectangle_droite_composite(f,a,b,n) :
A b+h B b−h C b D b+a
Question 20 :
Nous rappelons l’expression du polynôme d’interpolation de Lagrange P , interpolant n + 1 points de coor-
données (xi , yi )0≤i≤n tels que xi 6= xj , pour 0 ≤ i, j ≤ n et i 6= j :
n
X
P (t) = yi Li (t), t∈R
i=0

n
Y t − xj
où Li (t) = .
xi − xj
j=0
j6=i
La fonction interpolation_lagrange(t,x,y) donnée ci-dessous, programme P avec x= (xi )0≤i≤n et y= (yi )0≤i≤n .
Indiquez le nombre de fautes à corriger pour que la fonction interpolation_lagrange(t,x,y) s’exécute correcte-
ment.
def i n t e r p o l a t i o n _ l a g r a n g e ( t , x , y ) :
n= l e n ( x )
f o r i i n np . a r a n g e ( 0 , n ) :
P=0
L=1
f o r j i n np . a r a n g e ( 0 , n ) :
if j=i :
L∗ = ( t −x [ j ] ) / ( x [ i ]−x [ j ] )
P+=y [ i ]
return P

A 0 B 1 C 2 D 3

Vous aimerez peut-être aussi