Question: help needed - evaluating an integrand

Hi guys I am trying to evaluate  an integral of the form

 

A_0 := (1/(2*Pi)+Q*cos(k*phi))^2/(1+(1/(2*Pi)+Q*cos(k*phi))^2);

In this case I specify a value for Q=15 as given below and since maple cannot evaluate the integral directly I have written code to evaluate the integral using the residue theorem. So for each singularity I calculate the residue at that point and multiply the sum of the residues by 2*Pi*I as in the code below. However the final result of this calculation has an imaginary part. Seeing that my integrand is real is it reasonable to expect that the result has an imaginary part or does it show that the result of calculating the integral is completely wrong. Please help.

This is what I do.

 

A_0 := (1/(2*Pi)+Q*cos(k*phi))^2/(1+(1/(2*Pi)+Q*cos(k*phi))^2);Q:=15;

>  s1:=A_0;

s2:=subs(cos(k*phi)=((1-u^2) / (1+u^2)), cos(m*phi)=((1-u^2) / (1+u^2)), sin(m*phi)=((2*u) / (1+u^2)),sin(k*phi)=((2*u) / (1+u^2)), s1)*1/(1 + u^2);

s22 := unapply((eval(s1, [cos(k*phi) = (1-u^2)/(1+u^2),cos(m*phi) = (1-u^2)/(1+u^2), sin(m*phi)=((2*u) / (1+u^2)),sin(k*phi) = 2*u/(1+u^2)]))/(1+u^2), u);

  t:=singular(s2,u); t1a:=map(rhs@op,[t]);# puts elements of call to singular in a list

p1:=(beta,Q,P)->select(x->Im(evalf(eval(x,[beta=beta,Q=Q,P=P])))>0,t1a):#evaluates sign of #imaginary #part

 t1:=p1(beta,Q,P); #selects the poles with positive imaginary parts

# assign the poles to variables and calculate the residues - another for loop within the global for loop

res_count:=0;

for i from 1 to nops(t1) do

u[i]:=t1[i];

res[i]:=residue(s22(u),u=u[i]);# S22 is a mapping function mapping u to s2;residue procedure needs a #mapping function.

res_count:= res_count + res[i];

end do; # this ends the residue calculations. It has summed the residues.

result:=  simplify((2*Pi*I)*(res_count),size);

>

 

 

Result is my final answer. Its meant to be the value of the integral. If its wrong how can it be corrected? Please help or give suggestions.

Please Wait...