```python
import numpy as np
import matplotlib.pyplot as plt
```

## Superposition of waves

### Example: 1
\begin{equation}
y=a+a\cos2\theta+a\cos4\theta +a\cos6\theta+... +\cos2n\theta+..............
\end{equation}

\begin{equation}
y=a\sum_{n=0}^N{\cos2n\theta}
\end{equation}


```python
step = 1000  #step
a=50  #amplitude
theta = np.arange(0,4*np.pi,4*np.pi/step)  
```


```python
plt.figure(figsize = [20,6])
for n in range(4):
    y = a*np.cos(2*n*theta)
    plt.plot(theta,y, label= "a*cos("+str(2*n)+r"$\theta$)")
    
plt.xlabel("theta") 
plt.ylabel("Displacement")
plt.legend()
plt.show()
```


```python
plt.figure(figsize = [15,4])
y =a* sum([np.sin(2*n*theta) for n in [i for i in range(6)]])
plt.plot(theta,y)
plt.xlabel(r"$\theta$",fontsize =14,color='b')
plt.ylabel("Displacement",fontsize =14,color='b')
plt.title('Superpostion of Waves ',fontsize =18,color='r')
#plt.tight_layout() 
plt.savefig("image/wave1.pdf") # dpi dot per inch
plt.show()
```

### Example: 2
\begin{equation}
y=a\sin\theta+a\sin3\theta +a\sin5\theta+... +a\sin(2n+1)\theta+.......
\end{equation}

\begin{equation}
y=a\sum_{n=0}^N{\sin(2n+1)\theta}
\end{equation}


```python
plt.figure(figsize = [20,6])
for n in range(4):
    y = a*np.sin((2*n+1)*theta)
    plt.plot(theta,y, label= "a*sin("+str(2*n+1)+r"$\theta$)")
    
plt.xlabel("theta ") 
plt.ylabel("y")
plt.legend()
plt.show()
```


```python
plt.figure(figsize = [15,4])
y = sum([a*np.sin((2*n+1)*theta) for n in [i for i in range(6)]])
plt.plot(theta,y,label ="wave")
plt.legend()
plt.xlabel(r"$\theta$",fontsize =14,color='b')
plt.ylabel("y",fontsize =14,color='b')
plt.title('Superposition of Waves ',fontsize =18,color='r')
plt.tight_layout() 
plt.savefig("image/wave2.pdf", dpi = 300) # dpi dot per inch
plt.show()
```

---------------

## Fourier Series: 
\begin{equation}
f(x)=\frac{a_0}{2}+\sum_{n=1}^\infty{[a_n\cos(\frac{n\pi x}{L})+b_n\sin(\frac{n\pi x}{L})]}
\end{equation}

### 1 Full wave rectifier
\begin{equation}
f(x)=\frac{2}{\pi}-\frac{4}{\pi}\sum_{n=0}^N{\frac{\cos nx}{n^2-1}}
\end{equation}
here n is even


```python
x=np.arange(0,4*np.pi,4*np.pi/step)  
```


```python
plt.figure(figsize = [20,6])
for i in range(6):
    n=2*i
    y = (2/np.pi)-(4/np.pi)*np.cos(n*x)/(n**2-1)
    plt.plot(x,y, label= "2/pi - 4/pi"+str(1/(n**2-1))+"sin("+str(n)+"x)")
    
plt.xlabel("x") 
plt.ylabel("f(x)")
plt.legend()
plt.show()
```


```python
plt.figure(figsize = [15,4])
y =(2/np.pi)-(4/np.pi)* sum([np.cos(n*x)/(n**2-1) for n in [i for i in range(10)if i%2 ==0 ]])
plt.plot(theta,y)
plt.xlabel("x",fontsize =14,color='b')
plt.ylabel("f(x)",fontsize =14,color='b')
plt.title('Full wave rectifier ',fontsize =18,color='r')
plt.tight_layout() 
plt.savefig("image/fullwave.pdf", dpi = 300) # dpi dot per inch
plt.show()
```

### 2 well
\begin{equation}
f(x)=\frac{\pi ^2}{3}+4\sum_{n=1}^N{\frac{(-1)^n}{n^2}\cos nx}
\end{equation}


```python
plt.figure(figsize = [20,6])
for n in range(1,6):
    y = (np.pi**2/3)+4*np.cos(n*x)/n**2
    plt.plot(x,y, label= r"$\pi^2$/3+ 4"+str((-1)**n/n**2)+"cos("+str(n)+"x)")
    
plt.xlabel("x") 
plt.ylabel("f(x)")
plt.legend()
plt.show()
```


```python
plt.figure(figsize = [15,4])
y =(np.pi**2/3)+4* sum([np.cos(n*x)/n**2 for n in [i for i in range(1,10)]])
plt.plot(x,y)
plt.xlabel("x",fontsize =14,color='b')
plt.ylabel("f(x)",fontsize =14,color='b')
plt.title('Well',fontsize =18,color='r')
plt.tight_layout() 
plt.savefig("image/well.pdf", dpi = 300) # dpi dot per inch
plt.show()
```

### 3 Home Work(Triangular wave) 
\begin{equation}
f(x)=\frac{8}{\pi ^2}\sum_{n=1,3,5..}^N{\frac{(-1)^{(n-1)/2}}{n^2}\sin(\frac{n\pi x}{L})}
\end{equation}


```python
L = 1
xs =1000
x = np.arange(0,2,10/xs)
plt.figure(figsize = [15,4])
for n in [i for i in range(10) if i%2 !=0]:
    y = (8/np.pi**2)*(-1)**(0.5*(n-1))*np.sin(n*np.pi*x/float(L))/n**2
    plt.plot(x,y, label = str(n)+" wave")
plt.xlabel('x')
plt.ylabel('f(x)')
plt.legend() 
plt.show()                      
```


```python
x = np.arange(0,10,10/xs)
plt.figure(figsize = [15,4])
y = (8/np.pi**2)*sum([(-1)**(0.5*(n-1))*np.sin(n*np.pi*x/float(L))/n**2 for n in [i for i in range(20) if i%2 !=0]])
plt.plot(x,y)
plt.xlabel("x",fontsize =14,color='b')
plt.ylabel("f(x)",fontsize =14,color='b')
plt.title('Triangular wave',fontsize =18,color='r')
plt.tight_layout() 
plt.savefig("image/triangularl.pdf", dpi = 300) # dpi dot per inch
plt.show()
```


```python

```

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