```python
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import (MultipleLocator, FormatStrFormatter,
                               AutoMinorLocator)
```

# Superposition of two waves in perpendicular direction
\begin{equation}
x = a \sin (2\pi f_1 t)\\
y=b \sin (2\pi f_2 t - \phi)
\end{equation}


```python
a = [10,30]             # amplitude of first wave
f1 = [1,2,4,8,12,16]    # frequency of first wave
b=[10,30]               # amplitude of second wave
f2=[1,2,4,8,12,16]      # frequency of second wave
phi=[0,np.pi/4,np.pi/2] # phase angle(0,30,45,60,90)
t = np.arange(0,8.0,0.01) # time
```

## Example

### 1.same amplitude,phase is zero ,different frequency
 Lissajous figure


```python
plt.figure(figsize = [6,36])
for i in range(len(f2)):
    plt.subplot(len(f2),1,i+1)
    ax = plt.gca()
    ax.set_facecolor('k') # backgound color
    ax.grid(color='xkcd:sky blue') # grid color
    x = a[0]*np.sin(2*np.pi*f1[2]*t)
    y = b[0]*np.sin(2*np.pi*f2[i]*t-phi[0])
    plt.plot(x,y, color ='g',label='f1='+str(f1[2])+',f2='+str(f2[i]))
    plt.xlabel("x",color='r',fontsize=14)
    plt.ylabel("y",color='r',fontsize=14)
    ax.xaxis.set_minor_locator(AutoMinorLocator()) ##
    ax.yaxis.set_minor_locator(AutoMinorLocator()) ###
    ax.tick_params(which='both', width=2)
    ax.tick_params(which='major', length=9)
    ax.tick_params(which='minor', length=4)
    plt.legend()
    plt.subplots_adjust(wspace = 0.5, hspace = 0.5)
plt.show()
```

### 2.same frequency and amplitude,different phase



```python
plt.figure(figsize = [6,24])
for i in range(len(phi)):
    plt.subplot(len(phi),1,i+1)
    ax = plt.gca()
    ax.set_facecolor('xkcd:sky blue')
    ax.grid(color='g')
    x = a[0]*np.sin(2*np.pi*f1[2]*t)
    y = b[0]*np.sin(2*np.pi*f2[2]*t-phi[i])
    plt.plot(x,y, color ='purple',label='phase='+str(phi[i]*180/np.pi))
    plt.xlabel("x",color='g',fontsize=14)
    plt.ylabel("y",color='g',fontsize=14)
    plt.legend()
    plt.subplots_adjust(wspace = 0.5, hspace = 0.5)
plt.show()
```

### 3.same frequency ,different phase and amplitude


```python
plt.figure(figsize = [8,24])
for i in range(len(phi)):
    plt.subplot(len(phi),1,i+1)
    ax = plt.gca()
    ax.grid(color='tab:brown')
    x = a[0]*np.sin(2*np.pi*f1[2]*t)
    y = b[1]*np.sin(2*np.pi*f2[2]*t-phi[i])
    plt.plot(x,y, color ='r',label='phase='+str(phi[i]*180/np.pi))
    plt.xlabel("x",color='r',fontsize=14)
    plt.ylabel("y",color='r',fontsize=14)
    plt.legend()
    plt.subplots_adjust(wspace = 0.5, hspace = 0.5)
plt.show()
```

# Superposition of two waves in same direction
\begin{equation}
y_1 = a \sin (2\pi f_1 t)\\
y_2=b \sin (2\pi f_2 t - \phi)
\end{equation}

## Example

### 1.same amplitude and phase,different frequency


```python
f1=[1,2,3,4,5]
f2=[1,2,3,4,5]
plt.figure(figsize = [12,16])
for i in range(len(f2)):
    plt.subplot(len(f2),1,i+1)
    ax = plt.gca() #graphic current axis
    ax.set_facecolor('k')
    ax.grid(False)
    y1 = a[0]*np.sin(2*np.pi*f1[0]*t)
    y2 = a[0]*np.sin(2*np.pi*f2[i]*t-phi[0])
    y=y1+y2
    plt.plot(t,y,color ='tab:olive',label='f1='+str(f1[0])+',f2='+str(f2[i]))
    plt.xlabel("t",color='r',fontsize=14)
    plt.ylabel("y",color='r',fontsize=14)
    plt.legend()
    plt.subplots_adjust(wspace = 0.5, hspace = 0.5)
plt.show()
```


```python

```

ba6341d873ccba0073742e9b90416a6a7f3a72bb
ipynb
Jupyter Notebook
Lissajous.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
2020-09-16T03:21:55.000Z
2020-09-16T03:21:55.000Z
Lissajous.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
Lissajous.ipynb
AmbaPant/NPS
0500f39f6708388d5c3f2b8d3e5ee5e56a1f646f
MIT
2020-08-10T12:17:21.000Z
2020-09-13T14:31:02.000Z
Qwen/Qwen-72B
1. YES
2. YES