[1]:
import numpy as N
import matplotlib.pyplot as P
# Insert figures within notebook
%matplotlib inline

Quadratuređź”—

Calcul de l’intégrale

\[\int_0^\infty \frac{x^3}{e^x - 1}\mathrm{d}x = \frac{\pi^4}{15}\]
[2]:
import scipy.integrate as SI
[3]:
def integrand(x):

    return x**3 / (N.exp(x) - 1)
[4]:
q, dq = SI.quad(integrand, 0, N.inf)
print("Intégrale:", q)
print("Erreur estimée:", dq)
print("Erreur absolue:", (q - (N.pi ** 4 / 15)))
Intégrale: 6.49393940226683
Erreur estimée: 2.628470028924825e-09
Erreur absolue: 1.7763568394002505e-15
/home/ycopin/Softwares/VirtualEnvs/Python3/lib/python3.5/site-packages/ipykernel_launcher.py:3: RuntimeWarning: overflow encountered in exp
  This is separate from the ipykernel package so we can avoid doing imports until

Zéro d’une fonction🔗

Résolution numérique de l’équation

\[f(x) = \frac{x\,e^x}{e^x - 1} - 5 = 0\]
[5]:
def func(x):

    return x * N.exp(x) / (N.exp(x) - 1) - 5

Il faut d’abord déterminer un intervalle contenant la solution, c.-à-d. le zéro de func. Puisque \(f(0^+) = -4 < 0\) et \(f(10) \simeq 5 > 0\), il est intéressant de tracer l’allure de la courbe sur ce domaine:

[6]:
x = N.logspace(-1, 1)  # 50 points logarithmiquement espacé de 10**-1 = 0.1 à 10**1 = 10
P.plot(x, func(x));
../_images/Exercices_numerique_10_0.png
[7]:
import scipy.optimize as SO
[8]:
zero = SO.brentq(func, 1, 10)
print("Solution:", zero)
Solution: 4.965114231744277

This page was generated from Exercices/numerique.ipynb.