Exemple du circuit RLC
Description du système¶
Le système se compose des éléments suivants:
- une bobine $L$ d'état $\phi_L(t)$ et de fonction de stockage $\mathtt{H}_\phi(\phi_L)=\frac{\phi_L^2}{2L}$,
- un condensateur $C$ d'état $q_C(t)$ et de fonction de stockage $\mathtt{H}_q(q_C)=\frac{q_C^2}{2C}$,
- une résistance $R$ de variable associée $i_r$ et de puissance dissipée $D_r(i_r)=R\, i_r^2$.
On définit:
- l'état $\mathbf{x}=\left(\phi_L(t), q_C(t)\right)^\intercal$,
- le Hamiltonien $\mathtt{H}(\mathbf{x}) = \mathtt{H}_\phi(x_1) + \mathtt{H}_q(x_2)$,
- la variable de dissipation $\mathbf{w}=\left(i_r\right)^\intercal$
- la fonction de dissipation $\mathbf{z}(\mathbf{w})=\left(R\,w_1\right)^\intercal$
In [24]:
import sympy as sp
x = sp.symbols(['phi_L','q_C'])
Out[24]:
le hamiltonien du système
Python ne propose pas directement de fonctionnalités pour le calcul numériqe. Elles sont chargées depuis des modules externes. Les plus utilisés sont numpy
pour les structures de données numériques (numpy.array
, numpy.matrix
).
Python itself does not provide usefool ttools for numerical computations. So we have to import them. Ther is several ways to import modules:
- You can import all the methods and functions with
from module import *
- You can import selected functions
f1
andf2
from a givenmodule
withfrom module import f1, f2
- You can import the module with a specified label with
import module as label
In [16]:
# Load Plot module
import matplotlib.pyplot as plt
# This line configures matplotlib to show figures embedded in the notebook,
# instead of poping up a new window.
%matplotlib inline
# Load numerical module
import numpy as np
eps = np.spacing(1) # numerical precision
from IPython.display import Latex
Array definition¶
On souhaite afficher la courbe $A\sin(2\pi f_0t)$ pour $t\in [0,1]$. Tout d'abord on définit un signal
$$\begin{eqnarray} \nabla \times \vec{\mathbf{B}} -\, \frac1c\, \frac{\partial\vec{\mathbf{E}}}{\partial t} & = \frac{4\pi}{c}\vec{\mathbf{j}} \\ \nabla \cdot \vec{\mathbf{E}} & = 4 \pi \rho \\ \nabla \times \vec{\mathbf{E}}\, +\, \frac1c\, \frac{\partial\vec{\mathbf{B}}}{\partial t} & = \vec{\mathbf{0}} \\ \nabla \cdot \vec{\mathbf{B}} & = 0 \end{eqnarray}$$$s(f_0)=A\sin(2\pi f_0t)$, puis on l'utilise récursivement.
In [22]:
# Time Vector
t = np.linspace(0,1,300)
# Signal function
A = 10 # Amplitude (V)
s = lambda f0: A*np.sin(2*np.pi*f0*t)
axis = plt.axes()
# Plot for a list of f0
for f0 in np.linspace(1,2,3):
label = '$f_0=$'+str(f0)
axis.plot(t, s(f0), label=label)
# Plot axis
axis.set_xlabel('Temps (s)')
axis.set_ylabel('Amplitude (V)')
# Plot label and legend
axis.set_title('$\sin(2\pi f_0 t)$')
axis.legend(loc=0) # option loc=0 set location with minimal overlap
# activate a grid
axis.grid()
Somme¶
Ici on somme les trois signaux pour visualiser une forme d'onde complexe i.e. nonpure.
In [3]:
plt.plot(t, [np.sum(e) for e in zip(*[s(f0) for f0 in [1,2,3]])], label='$\sum_{i=1}^3 S_i(t)$')
# Plot axis
plt.xlabel('Temps (s)')
plt.ylabel('Amplitude (V)')
# Plot label and legend
plt.title('$\sin(2\pi f_0 t)$')
plt.legend(loc=1) # option loc=0 set location with minimal overlap
# Show the plot
plt.show()