0% found this document useful (0 votes)
12 views22 pages

Experiment 5

Uploaded by

Nijil Joseph
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views22 pages

Experiment 5

Uploaded by

Nijil Joseph
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Experiment No.

6
Convergence of Series
Experiment No.8 (in syllabus)
• The experiment aims to understand the lack of convergence
of Fourier series
1. Realize the Fourier series
4 1 2 3t 1 2 5t 1 2 7t
f (t )  [1  cos  cos  cos  ......]
 3 T 5 T 7 T
Realize the vector t = [0, 100] with an increment of 0.01 and keep T = 20.

Plot the first 3 or 4 terms on the same graphic window and


understand how the smooth sinusoids add up to a
discontinuous square function.
2 Compute and plot the series for the first 10, 20, 50 and 100
.

terms of the and understand the lack of convergence at the


points of discontinuity
3. With t made a zero vector, f(0) = 1, resulting in
the Madhava series for π
as π = 4[1 - 1 /3 + 1/ 5 - 1/ 7 + · · · ]
• Use this to compute π for the first 10, 20, 50
and 100 terms.
Fourier Series
• helps to model any arbitrary periodic signal
with a combination of sines and cosines
• makes use of the orthogonality relationships
of the sine and cosine functions.
Fourier series
If f(t) is even function

• Any function f(t) can be written as


I
If f(t) is odd function
Fourier series of square wave

Suppose our Square wave is


Fourier series of square waves
In general

The even-numbered coefficients b2k are all


zero because cos (2kπ) = cos 0 = 1.
The odd-numbered coefficients bk = 4/πk
decrease at the rate 1/k.
A square wave
Problem
6.1Realize the vector t = [0, 100] with an
increment of 0.01 and keep T = 20. Realize the
following Fourier series
4 1 2 3t 1 2 5t 1 2 7t
f (t )  [1  cos  cos  cos  ......]
 3 T 5 T 7 T
• Plot the first 3 or 4 terms on the same graphic window
and understand how the smooth sinusoids add up to a
discontinuous square function.
• So
Program
import numpy as np
import matplotlib.pyplot as plt
import math
T=20
t = np.arange(0, 40, 0.01) # arguments: start, stop, step
n=1
y1 = ((-1)**n)*1/(2*n+1)*np.cos(2*math.pi*(2*n+1)*t/T)
n=2
y2 = ((-1)**n)*1/(2*n+1)*np.cos(2*math.pi*(2*n+1)*t/T)
n=3
y3 = ((-1)**n)*1/(2*n+1)*np.cos(2*math.pi*(2*n+1)*t/T)
y =(4/math.pi)*(1+y1+y2+y3)
fig,a = plt.subplots(4,1)
a[0].plot(t,y1)
a[0].set_title('First term')
a[1].plot(t,y2)
a[1].set_title('Second term')
a[2].plot(t,y3)
a[2].set_title('third')
a[3].plot(t,y)
a[3].set_title('y')
plt.show()
Result
Problem
• Realize the vector t = [0, 100] with an
increment of 0.01 and keep T = 20. Realize
the following Fourier series
4 1 2 3t 1 2 5t 1 2 7t
f (t )  [1  cos  cos  cos  ......]
 3 T 5 T 7 T
Method 1
import numpy as np
import matplotlib.pyplot as plt
import math
T=10
t = np.arange(0, 40, 0.01) # arguments: start, stop, step
N=[4,10,100]
fig,a = plt.subplots(3,1)
i=0
for value in N:
sum=1
for n in range(3,value,2):
k=(n-1)/2
term = (-1)**k/n*np.cos(2*math.pi*n*t/T)
sum=sum+term
y =(4/math.pi)*sum
a[i].plot(t,y)
a[i].set_title('y')
i+=1
plt.show()
Method 2
import numpy as np
import matplotlib.pyplot as plt
import math
T=20
t = np.arange(0, 40, 0.01) # arguments: start, stop, step
N=[3,5,10,20]
fig,a = plt.subplots(4,1)
i=0
for value in N:
sum=1
for n in range(1, value):
term = ((-1)**n)*1/(2*n+1)*np.cos(2*math.pi*(2*n+1)*t/T)
sum=sum+term
y =(4/math.pi)*(1+sum)
a[i].plot(t,y)
a[i].set_title('y')
i+=1
plt.show()
Problem
8.3 Consider the Fourier series:
4 1 2 3t 1 2 5t 1 2 7 t
f (t )  [1  cos  cos  cos  ......]
 3 T 5 T 7 T

• With t made a zero vector, f(0) = 1, resulting


in the Madhava series for π as
π = 4[1 - 1 /3 + 1/ 5 - 1/ 7 + ·· · ].
Use this to compute π for the first 10, 20, 50 and
100 terms.
Pi
• “Pi” (π) is the ratio between the circumference
of a circle and its diameter
• an irrational number-it cannot be written as a
ratio of two whole numbers which are prime
to each other.
• ‘transcendental number- it cannot be
expressed as a root of a polynomial of rational
coefficients
Pi and Madhava Series
• In the fourteenth century, Madhava,- a
mathematician of Sangamgram of Kerala,-
• invention of Infinite Series
• deduced its value up to eleven places of
decimals with precision.
Value of Pi
Value of Pi from Fourier series
Program
import numpy as np • 3.3396825396825403
import matplotlib.pyplot as plt • 3.0418396189294032
import math • 3.1315929035585537
T=20 • 3.140592653839794
N=[5,10,100,1000,10000] • 3.1414926535900345
fig,a = plt.subplots(4,1)
i=0
for value in N:
sum=1
for n in range(1, value):
term = ((-1)**n)*1/(2*n+1)
sum=sum+term
y= sum
pi_value =4*sum
print(pi_value)
i+=1

You might also like