import sympy,math,numpy
print "finding the fourier series of given function"
x = sympy.Symbol('x')
ao = 1/math.pi*sympy.integrate(sympy.exp(-1*x),(x,0,2*math.pi))
s = ao/2
n = int(raw_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 = 1/math.pi*sympy.integrate(sympy.exp(-x)*sympy.cos(i*x),(x,0,2*math.pi))
bi = 1/math.pi*sympy.integrate(sympy.exp(-x)*sympy.sin(i*x),(x,0,2*math.pi))
s = s+float(ai)*sympy.cos(i*x)+float(bi)*sympy.sin(i*x)
print s
import numpy,math,sympy
print "To find the fourier transform of given function"
x = sympy.Symbol('x')
s = sympy.Symbol('s')
F = sympy.integrate(sympy.exp(1j*s*x),(x,-1,1))
print F
F1 = sympy.integrate(sympy.sin(x)/x,(x,0,numpy.inf))
print F1
import numpy,sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
ao = 1/math.pi*(sympy.integrate(-1*math.pi*x**0,(x,-math.pi,0))+sympy.integrate(x,(x,0,math.pi)))
s = ao/2
n = int(raw_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 = 1/math.pi*(sympy.integrate(-1*math.pi*sympy.cos(i*x),(x,-1*math.pi,0))+sympy.integrate(x*sympy.cos(i*x),(x,0,math.pi)))
bi = 1/math.pi*(sympy.integrate(-1*math.pi*x**0*sympy.sin(i*x),(x,-1*math.pi,0))+sympy.integrate(x*sympy.sin(i*x),(x,0,math.pi)))
s = s+float(ai)*sympy.cos(i*x)+float(bi)*sympy.sin(i*x)
print s
import sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
l = sympy.Symbol('l')
ao = 1/l*sympy.integrate(sympy.exp(-1*x),(x,-l,l))
s = ao/2
n = int(raw_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 = 1/l*sympy.integrate(sympy.exp(-x)*sympy.cos(i*math.pi*x/l),(x,-l,l))
bi = 1/l*sympy.integrate(sympy.exp(-x)*sympy.sin(i*math.pi*x/l),(x,-l,l))
s = s+float(ai)*sympy.cos(i*math.pi*x/l)+float(bi)*sympy.sin(i*math.pi*x/l)
print s
import math,sympy
print "finding the fourier series of given function"
x = sympy.Symbol('x')
l = sympy.Symbol('l')
s = 0
n = int(raw_input("enter the no of terms up to each of terms in the expansion : "))
for i in range(1,n+1):
bi = 2/math.pi*sympy.integrate(x*sympy.sin(i*x),(x,0,math.pi))
s = s+float(bi)*sympy.sin(i*x)
print s
import math,sympy
print "finding the fourier series of given function"
x = sympy.Symbol('x')
l = sympy.Symbol('l')
ao = 2/l*sympy.integrate(x**2,(x,0,l))
s = ao/2
n = int(raw_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/l*sympy.integrate(x**2*sympy.cos(i*math.pi*x/l),(x,0,l))
s = s+float(ai)*sympy.cos(i*math.pi*x/l)
print s
import sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
ao = 2/math.pi*(sympy.integrate(sympy.cos(x),(x,0,math.pi/2))+sympy.integrate(-sympy.cos(x),(x,math.pi/2,math.pi)))
s = ao/2
n = int(raw_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/math.pi*(sympy.integrate(sympy.cos(x)*sympy.cos(i*x),(x,0,math.pi/2))+sympy.integrate(-sympy.cos(x)*sympy.cos(i*x),(x,math.pi/2,math.pi)))
s = s+float(ai)*sympy.cos(i*x)
print s
import sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
ao = 2/math.pi*(sympy.integrate((1-2*x/math.pi),(x,0,math.pi)))
s = ao/2
n = int(raw_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/math.pi*(sympy.integrate((1-2*x/math.pi)*sympy.cos(i*x),(x,0,math.pi)))
s = s+float(ai)*sympy.cos(i*x)
print s
import sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
l = sympy.Symbol('l')
s = 0
n = int(raw_input("enter the no of terms up to each of sin or cos terms in the expansion : "))
for i in range(1,n+1):
bi = sympy.integrate(x*sympy.sin(i*math.pi*x/2),(x,0,2))
s = s+float(bi)*sympy.sin(i*math.pi*x/2)
print float(s)
import sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
ao = 2/2*(sympy.integrate(x,(x,0,2)))
s = ao/2
n = int(raw_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/2*(sympy.integrate(x*sympy.cos(i*math.pi*x/2),(x,0,2)))
s = s +float(ai)*sympy.cos(i*math.pi*x/2)
print float(s)
import sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
ao = 0
s = ao
n = int(raw_input("enter the no of terms up to each of sin or cos terms in the expansion : "))
for i in range(1,n+1):
bi = 2/1*(sympy.integrate((1/4-x)*sympy.sin(i*math.pi*x),(x,0,1/2))+sympy.integrate((x-3/4)*sympy.sin(i*math.pi*x),(x,1/2,1)))
s = s+float(bi)*sympy.sin(i*math.pi*x)
print float(s)
import sympy,math
print "finding the fourier series of given function"
x = sympy.Symbol('x')
ao = 1/math.pi*sympy.integrate(x**2,(x,-math.pi,math.pi))
s = ao/2
n = int(raw_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 = 1/math.pi*sympy.integrate((x**2)*sympy.cos(i*x),(x,-math.pi,math.pi))
bi = 1/math.pi*sympy.integrate((x**2)*sympy.sin(i*x),(x,-math.pi,math.pi))
s = s+float(ai)*sympy.cos(i*x)+float(bi)*sympy.sin(i*x)
print s
import sympy,math
print "The complex form of series is summation of f(n,x) where n varies from −%inf to %inf and f(n,x) is given by : "
n = sympy.Symbol('n')
x = sympy.Symbol('x')
a = sympy.exp(-x)
b = sympy.exp(-1j*math.pi*n*x)
cn = 1/2*sympy.Integral(sympy.exp(-x)*sympy.exp(-1j*math.pi*n*x),(x,-sympy.oo,sympy.oo))
fnx = float(cn)*sympy.exp(1j*n*math.pi*x)
print fnx
import sympy, math, numpy
print "Practical harmoninc analysis"
x = sympy.Symbol('x')
xo = numpy.array([math.pi/6, math.pi/3, math.pi/2, 2*math.pi/3, 5*math.pi/6, math.pi, 7*math.pi/6, 4*math.pi/3, \
3*math.pi/2, 5*math.pi/3, 11*math.pi/6])
yo = numpy.array([1.10, 0.30, 0.16, 1.50, 1.30, 2.16, 1.25, 1.30, 1.52, 1.76, 2.00])
ao = 2*numpy.sum(yo)/len(xo)
s = ao/2
n = int(raw_input('No of sin or cos term in expansion : '))
for i in range(1,n+1):
an = 2*sum(yo*numpy.cos(i*xo))/len(yo)
bn = 2*sum(yo*numpy.sin(i*xo))/len(yo)
s = s+float(an)*sympy.cos(i*x)+float(bn)*sympy.sin(i*x)
print s
import math,sympy,numpy
print "Practical harmonic analysis"
x = sympy.Symbol('x')
T = sympy.Symbol('T')
xo = numpy.array([1/6,1/3,1/2,2/3,5/6,1])
yo = numpy.array([1.30,1.05,1.30,-0.88,-0.25,1.98])
ao = 2*sum(yo)/len(xo)
s = ao/2
n = int(raw_input("No of sin or cos term in expansion :"))
i = 1
an = 2*sum(yo*numpy.cos(i*xo*2*math.pi))/len(yo)
bn = 2*sum(yo*numpy.sin(i*xo*2*math.pi))/len(yo)
s = s+float(an)*sympy.cos(i*x*2*math.pi/T)+float(bn)*sympy.sin(i*x*2*math.pi/T)
print s
print "Direct current :"
i = math.sqrt(an**2+bn**2)
print i
import math,sympy,numpy
print "Practical harmonic analysis"
x = sympy.Symbol('x')
T = sympy.Symbol('T')
xo = int(raw_input("Input xo matrix (in factor of T):"))
yo = numpy.array([1.30,1.05,1.30,-0.88,-0.25,1.98])
ao = 2*sum(yo)/xo
s = ao/2
n = int(raw_input("No of sin or cos term in expansion :"))
i = 1
an = 2*sum(yo*numpy.cos(i*xo*2*math.pi))/len(yo)
bn = 2*sum(yo*numpy.sin(i*xo*2*math.pi))/len(yo)
s = s+float(an)*sympy.cos(i*x*2*math.pi/T)+float(bn)*sympy.sin(i*x*2*math.pi/T)
print s
print "Direct current :"
i = math.sqrt(an**2+bn**2)
print i
import math,sympy,numpy
print "Practical harmonic analysis"
x = sympy.Symbol('x')
T = sympy.Symbol('T')
xo = int(raw_input("Input xo matrix (in factor of T):"))
yo = numpy.array([1.30,1.05,1.30,-0.88,-0.25,1.98])
ao = 2*sum(yo)/xo
s = ao/2
n = int(raw_input("No of sin or cos term in expansion :"))
i = 1
an = 2*sum(yo*numpy.cos(i*xo*2*math.pi))/len(yo)
bn = 2*sum(yo*numpy.sin(i*xo*2*math.pi))/len(yo)
s = s+float(an)*sympy.cos(i*x*2*math.pi/T)+float(bn)*sympy.sin(i*x*2*math.pi/T)
print s
print "Direct current :"
i = math.sqrt(an**2+bn**2)
print i