Voici des propositions pour les exercices de préparation à cette mystérieuse épreuve de Maths II de Centrale...
Python
# Exo 1 import math import numpy as np import scipy as sp import scipy.integrate as integ import scipy.optimize as resol def approche(a,n): f = lambda x: integ.quad(lambda t: t**n*np.exp(-t)/math.factorial(n), 0, x)[0] - a borne = 0 while f(borne) < 0: borne += 1 gauche, droite = borne - 1, borne while (droite - gauche) > 0.01: milieu = gauche + (droite - gauche)*0.5 (gauche, droite) = (gauche, milieu) if f(milieu) > 0 else (milieu, droite) return (gauche, droite) # ou bien en utilisant fsolve : def approche2(a,n): f = lambda x: integ.quad(lambda t: t**n*np.exp(-t)/math.factorial(n), 0, x)[0] - a return resol.fsolve(f,0) #Exo 2 import scipy.integrate as integ def p(x,n): poly_tmp = 1 for k in range(n): poly_tmp *= (x - k) / (k + 1) return poly_tmp def a(i): return integ.quad(lambda x: p(x,i), 0, 1)[0] #Exo 3 import numpy as np import numpy.linalg as nl from math import sqrt S = np.matrix([[-1,0],[0,1]]) T = np.matrix([[-1,1],[1,1]]) / sqrt(2) R = S*T L = [R**(k % 8)*S**(k // 8) for k in range(16)] def indice(N): i = 0 M = S*N for i in range(16): if (abs(M - L[i]) < 1e-15).all(): return i def signature(G): P = 1 for i in range(16): p = 1 Gi = indice(G[i]) for j in range(i+1,16): p *= (indice(G[j]) - Gi) / (j - i) P *= p return P #Exo 4 import matplotlib.pyplot as plt import numpy as np import math def pu(n): p = 1 X, Y = [],[] for k in range(1,n+1): p *= 1 + 1j/k**2 X.append(p.real) Y.append(p.imag) plt.plot(X,Y) def u(n): p = 1 for k in range(1,n+1): p *= 1 + 1j/k**2 return abs(p), math.atan(p.imag / p.real) def pv(n): p = 1 X, Y = [],[] for k in range(1,n+1): p *= 1 + 2*1j/k X.append(p.real) Y.append(p.imag) plt.plot(X,Y) def v(n): p = 1 for k in range(1,n+1): p *= 1 + 2*1j/k return abs(p), math.atan(p.imag / p.real) #Exo 5 import numpy.random as rnd from collections import Counter def tirage(): return rnd.randint(1,15) def lancers(): return sum([0 if tirage() <= 9 else 1 for k in range(5)]) def tableau(n): return Counter([lancers() for k in range(n)]) #Exo 6 import numpy.random as rnd from collections import Counter def course(): lancer = rnd.randint(1,7) nb_lancers = 1 while (lancer < 6) and (nb_lancers < 5): lancer = rnd.randint(1,7) nb_lancers += 1 return 1 if (lancer < 6) and (nb_lancers == 5) else 0 def simulTortue(n): return Counter([course() for k in range(n)]) #Exo 8 import matplotlib.pyplot as plt import numpy as np def escargot(f,u0,xi,xf,n): X = np.linspace(xi,xf) plt.plot(X,X) plt.plot(X,f(X)) Ordo = [] u = u0 for k in range(n): Ordo += [u,f(u)] u = f(u) plt.plot([u0] + Ordo, Ordo + [u]) #Exo 9 import numpy as np import numpy.linalg as nl from math import sqrt A = np.matrix(np.array([20,12,-4,12,-4,-3,9,-5,-4,1,5,-5,-8,-10,6,-2]).reshape(4,4)) B = np.matrix(np.array([-12,-16,-8,-4,4,13,1,-1,4,5,9,-1,8,10,2,6]).reshape(4,4)) val_A, vec_A = nl.eig(A) val_B, vec_B = nl.eig(B) DA = nl.inv(vec_A) * A * vec_A DB = nl.inv(vec_B) * B * vec_B