a0,an,bn,n =var('a0,an,bn,n')
# f(x) is neither even nor odd as seen by the figure
an=2/pi*(integral(x*cos(n*x),x,0,pi)+integral((pi-x)*cos(n*x),x,pi,2*pi))
a0=1/(pi)*(integral(x,x,0,pi)+integral(pi-x,x,pi,2*pi))
print 'a0=',a0
print 'an=',an
bn=2/pi*(integral(x*sin(n*x),x,0,pi)+integral((pi-x)*sin(n*x),x,pi,2*pi))
print 'bn=',bn

#Plotting the function
x=var('x')
f1=function('f1',x)
f1=x
f2=function('f2',x)
f2=pi-x
f1.plot(xmin=0,xmax=pi)+f2.plot(xmin=pi,xmax=2*pi)

SageDays/Kreyszig-10.4-14 (last edited 2010-08-12 13:34:51 by Aashita)