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

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

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