Example of an RLC circuit
RLC
Import¶
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 [1]:
# 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.
%pylab inline
# Load numerical module
import numpy as np
eps = np.spacing(1) # numerical precision
import seaborn
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 $s(f_0)=A\sin(2\pi f_0t)$, puis on l'utilise récursivement.
In [2]:
# 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)
# Plot for a list of f0
for f0 in np.linspace(1,2,3):
label = '$f_0=$'+str(f0)
plt.plot(t, s(f0), label=label)
# 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=0) # option loc=0 set location with minimal overlap
# Show the plot
plt.show()
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()