{"cells":[{"metadata":{},"cell_type":"markdown","source":"# Chapitre 1"},{"metadata":{},"cell_type":"markdown","source":"## Exercice 19"},{"metadata":{"trusted":false},"cell_type":"code","source":"# Calcul de la question 1\n\nimport numpy as np\nA = np.array(([-4, 0, 3], [0, 2, 0], [-10, 0, 7]))\nP = np.array(([1, 0, 3], [0, 1, 0], [2, 0, 5]))\nP_inv = np.linalg.inv(P)  # calcule l'inverse de la matrice\nprint(P_inv)\nprint(P_inv @ A @ P)","execution_count":19,"outputs":[{"output_type":"stream","text":"[[-5.  0.  3.]\n [ 0.  1.  0.]\n [ 2.  0. -1.]]\n[[2. 0. 0.]\n [0. 2. 0.]\n [0. 0. 1.]]\n","name":"stdout"}]},{"metadata":{"trusted":false},"cell_type":"code","source":"# Question 2, vérification\nS=np.array(([2**(1/2), 0, 0], [0, 2**(1/2), 0], [0, 0, 1]))\nB=P@S@P_inv\nprint(A-B@B) # Attention aux arrondis","execution_count":23,"outputs":[{"output_type":"stream","text":"[[ 2.66453526e-15  0.00000000e+00 -2.66453526e-15]\n [ 0.00000000e+00 -4.44089210e-16  0.00000000e+00]\n [ 5.32907052e-15  0.00000000e+00 -4.44089210e-15]]\n","name":"stdout"}]},{"metadata":{},"cell_type":"markdown","source":"## Exercice 27"},{"metadata":{},"cell_type":"markdown","source":"Compter le nombre de matrices non-inversibles parmi les matrices de tailles $(25,25)$ :\n$$\n\\mathrm{M}(a, b)=\\left[\\begin{array}{ccccc}\na & b & \\cdots & \\cdots & b \\\\\nb & a & \\ddots & \\cdots & b \\\\\n\\vdots & \\ddots & \\ddots & \\ddots & \\vdots \\\\\n\\vdots & \\ddots & \\ddots & a & b \\\\\nb & b & \\cdots & b & a\n\\end{array}\\right] \\quad \\text { avec } \\quad-50 \\leqslant a, b \\leqslant 50 .\n$$\nIndication. On pourra utiliser les commandes ones([n,p]) qui renvoie une matrice de $\\mathcal{M}_{n,p}(\\mathbb{R})$ ne contenant que des 1, eye(n) pour la matrice $I_n$ et np.linalg.matrix_rank(A) pour le rang de la matrice A."},{"metadata":{"trusted":false},"cell_type":"code","source":"import numpy as np \n\nCompteur=0\nfor a in range(...) : # attention au décalage d'indice en Python\n    for b in range(...) :\n        Mab= ... *np.eye(25)+ ... *np.ones([25,25])\n        if ... \n           Compteur= ....\nprint('Il y a', Compteur, 'matrices de ce type non inversibles')        ","execution_count":12,"outputs":[{"output_type":"stream","text":"Il y a 105 matrices de ce type non inversibles\n","name":"stdout"}]}],"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"}},"nbformat":4,"nbformat_minor":2}