Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

8/27/2021 27 aug_IT lab - Jupyter Notebook

HALF RANGE COSINE AND SINE SERIES ¶


In [1]: 

import numpy as np
import sympy as sp
from sympy import *
x = sp.Symbol('x')
ao=(2/np.pi)*(sp.integrate(x,(x,0,np.pi/2))+sp.integrate((np.pi-x),(x,np.pi/2,np.pi)))
fx = ao/2
n = int(input('enter the no of terms up to each of sin or cos terms in the expansion : '))
for i in range(1,n+1):

ai = (2/np.pi)*(sp.integrate(x*sp.cos(i*x),(x,0,np.pi/2))+sp.integrate((np.pi-x)*sp.cos
fx = fx + (ai)*sp.cos(i*x)
print(fx)

enter the no of terms up to each of sin or cos terms in the expansion : 5

0.785398163397448

0.785398163397448 - 0.636619772367581*cos(2*x)

0.785398163397448 - 0.636619772367581*cos(2*x)

0.785398163397448 - 0.636619772367581*cos(2*x)

-0.636619772367581*cos(2*x) + 3.53394964607057e-17*cos(5*x) + 0.785398163397


448

In [2]: 

import numpy as np
import sympy as sp
from sympy import *
x = sp.Symbol('x')

n = int(input('enter the no of terms up to each of sin terms in the expansion : '))


for i in range(1,n+1):

bi = (2/2)*(sp.integrate((2-x)*sp.sin((i*x*np.pi)/2),(x,0,2)))
fx =(bi)*sp.sin((i*x*np.pi)/2)
print(fx)

enter the no of terms up to each of sin terms in the expansion : 5

1.27323954473516*sin(1.5707963267949*x)

0.636619772367581*sin(3.14159265358979*x)

0.424413181578388*sin(4.71238898038469*x)

0.318309886183791*sin(6.28318530717959*x)

0.254647908947033*sin(7.85398163397448*x)

localhost:8888/notebooks/27 aug_IT lab.ipynb 1/4


8/27/2021 27 aug_IT lab - Jupyter Notebook

In [3]: 

import numpy as np
import sympy as sp
from sympy import *
x = sp.Symbol('x')

n = int(input('enter the no of terms up to each of sin terms in the expansion : '))


for i in range(1,n+1):

bi = (2/1)*sp.integrate(x*sp.sin(i*x*np.pi),(x,0,1/4))+(2/1)*sp.integrate((1/3)*(1-x)*s
fx =(bi)*sp.sin(i*x*np.pi)
print(fx)

enter the no of terms up to each of sin terms in the expansion : 5

0.191053056083585*sin(3.14159265358979*x)

0.0675474557615585*sin(6.28318530717959*x)

0.0212281173426206*sin(9.42477796076938*x)

-0.00764212224334341*sin(15.707963267949*x)

In [4]: 

import numpy as np
import sympy as sp
from sympy import *
x = sp.Symbol('x')

n = int(input('enter the no of terms up to each of sin terms in the expansion : '))


for i in range(1,n+1):

bi = (2/2)*sp.integrate(x*sp.sin(i*x*np.pi/2),(x,0,2))
fx =(bi)*sp.sin(i*x*np.pi/2)
print(fx)

enter the no of terms up to each of sin terms in the expansion : 5

1.27323954473516*sin(1.5707963267949*x)

-0.636619772367581*sin(3.14159265358979*x)

0.424413181578388*sin(4.71238898038469*x)

-0.318309886183791*sin(6.28318530717959*x)

0.254647908947033*sin(7.85398163397448*x)

localhost:8888/notebooks/27 aug_IT lab.ipynb 2/4


8/27/2021 27 aug_IT lab - Jupyter Notebook

In [10]: 

import numpy as np
import sympy as sp
from sympy import *
x = sp.Symbol('x')
ao=(2/2)*sp.integrate(x,(x,0,2))
fx=ao/2
n = int(input('enter the no of terms up to each of cos terms in the expansion : '))
for i in range(1,n+1):

ai = (2/2)*sp.integrate(x*sp.cos(i*x*np.pi/2),(x,0,2))
fx =fx +(ai)*sp.cos(i*x*np.pi/2)
print(fx)

enter the no of terms up to each of cos terms in the expansion : 5

1.0 - 0.810569469138702*cos(1.5707963267949*x)

-0.810569469138702*cos(1.5707963267949*x) - 1.52655665885959e-16*cos(3.14159
265358979*x) + 1.0

-0.810569469138702*cos(1.5707963267949*x) - 1.52655665885959e-16*cos(3.14159
265358979*x) - 0.0900632743487445*cos(4.71238898038469*x) + 1.0

-0.810569469138702*cos(1.5707963267949*x) - 1.52655665885959e-16*cos(3.14159
265358979*x) - 0.0900632743487445*cos(4.71238898038469*x) - 1.56125112837913
e-16*cos(6.28318530717959*x) + 1.0

-0.810569469138702*cos(1.5707963267949*x) - 1.52655665885959e-16*cos(3.14159
265358979*x) - 0.0900632743487445*cos(4.71238898038469*x) - 1.56125112837913
e-16*cos(6.28318530717959*x) - 0.0324227787655479*cos(7.85398163397448*x) +
1.0

In [11]: 

import numpy as np
import sympy as sp
from sympy import *
x = sp.Symbol('x')

n = int(input('enter the no of terms up to each of sin terms in the expansion : '))


for i in range(1,n+1):

bi = (2/np.pi)*sp.integrate(x*sp.sin(i*x),(x,0,np.pi/2))+(2/np.pi)*sp.integrate(x/2*sp.
fx =(bi)*sp.sin(i*x)
print(fx)

enter the no of terms up to each of sin terms in the expansion : 5

1.31830988618379*sin(x)

-0.25*sin(2*x)

0.297965568201801*sin(3*x)

-0.375*sin(4*x)

0.212732395447352*sin(5*x)

localhost:8888/notebooks/27 aug_IT lab.ipynb 3/4


8/27/2021 27 aug_IT lab - Jupyter Notebook

In [13]: 

import numpy as np
import sympy as sp
from sympy import *
x = sp.Symbol('x')
ao=(2/4)*sp.integrate(sp.sin(np.pi*x/4),(x,0,4))
fx=ao/2
n = int(input('enter the no of terms up to each of cos terms in the expansion : '))
for i in range(1,n+1):

ai = (2/4)*sp.integrate(sp.sin(np.pi*x/4)*sp.cos(i*x*np.pi/4),(x,0,4))
fx =fx +(ai)*sp.cos(i*x*np.pi/4)
print(fx)

enter the no of terms up to each of cos terms in the expansion : 5

4.77388365722123e-33*cos(0.785398163397448*x) + 0.636619772367581

4.77388365722123e-33*cos(0.785398163397448*x) - 0.424413181578388*cos(1.5707
963267949*x) + 0.636619772367581

4.77388365722123e-33*cos(0.785398163397448*x) - 0.424413181578388*cos(1.5707
963267949*x) + 0.636619772367581

4.77388365722123e-33*cos(0.785398163397448*x) - 0.424413181578388*cos(1.5707
963267949*x) - 0.0848826363156775*cos(3.14159265358979*x) + 0.63661977236758
1

4.77388365722123e-33*cos(0.785398163397448*x) - 0.424413181578388*cos(1.5707
963267949*x) - 0.0848826363156775*cos(3.14159265358979*x) + 0.63661977236758
1

In [ ]: 

localhost:8888/notebooks/27 aug_IT lab.ipynb 4/4

You might also like