While trying to compute winding number, i find that Integrate and NIntegrate are giving apparently different answers. Below is the code that i tried:

Clear[μ, λ1, λ2, θ1, θ2, Δ, ϵ, k];
$Assumptions = True;
$Assumptions = {μ, λ1, λ2, θ, k} ∈ Reals;
μ = -2;
ϵ[k_] := -2 λ1*Cos[k] - 2 λ2*Cos[2 k];
Δ[k_] := λ1*Sin[k] + λ2*Sin[2 k];
θ1[k_] := ArcTan[(ϵ[k] - μ)/Δ[k]];
λ1 = 2.5;
λ2 = 0;
Integrate[θ1'[k], {k, -π, π}]
NIntegrate[θ1'[k], {k, -π, π}]
λ1 = 0;
λ2 = 1.5;
Integrate[θ1'[k], {k, -π, π}]
NIntegrate[θ1'[k], {k, -π, π}]

And it gives following output:


It would be extremly helpful if someone can explain as to what is wrong with it?

  • 1
    $\begingroup$ Multiples of pi and arctan... It could be issues with branch cuts. $\endgroup$ – Simon Jun 12 '17 at 6:58
  • $\begingroup$ Using approximate reals (e.g. 2.5, 1.5) with exact solvers (e.g. Integrate) sometimes fails. Try Rationalize[] as a remedy or enter parameters as fractions. $\endgroup$ – Michael E2 Jun 12 '17 at 15:21

This seems to be a numerical issue with Integrate since by rationalizing the input, same result is now obtained.

ClearAll[\[Mu], \[Lambda]1, \[Lambda]2, \[Theta]1, \[CapitalDelta], \
\[Epsilon], k]; 
\[Mu] = -2; 
\[Epsilon][k_] := -2*\[Lambda]1*Cos[k] - 2*\[Lambda]2*Cos[2*k]
\[CapitalDelta][k_] := \[Lambda]1*Sin[k] + \[Lambda]2*Sin[2*k]
\[Theta]1[k_] := ArcTan[(\[Epsilon][k] - \[Mu])/\[CapitalDelta][k]]
\[Lambda]1 = 0; 
\[Lambda]2 = 1.5; 


der = Derivative[1][\[Theta]1][k]
derR = Rationalize@der

Mathematica graphics


Integrate[der, {k, -Pi, Pi}]
Integrate[derR, {k, -Pi, Pi}]

Mathematica graphics

The second answer above $4 \pi$ now matches the numerical result.

NIntegrate[der, {k,-Pi,Pi}]

Mathematica graphics

One also notices that the integrand is continuous, but the anti-derivative as reported by Integrate is discontinuous, which indicates a problem with the result, since one would expect the anti-derivative to be continuous as well.

 Plot[der, {k, -Pi, Pi}]

Mathematica graphics

 Plot[Evaluate@Integrate[der, k],{k,-Pi,Pi}]

Mathematica graphics


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.