If I type the following code

τMin0 = 0.1; 
τMax0 = 2; 
integrand[(τ_)?NumericQ] := {1000/Sqrt[τ^2 - τMin0^2], 0}; 
2*NIntegrate[Evaluate[integrand[τ][[1]]], {τ, τMin0, τMax0}]
2*NIntegrate[1000/Sqrt[τ^2 - τMin0^2], {τ, τMin0, τMax0}]

I obtain two different values for the same integrals


The first integral is of course not well calculated (I have checked by comparing with the analytical solutions in arccos). I don't know why and what to do to fix it.

  • 1
    $\begingroup$ The expression Evaluate[integrand[τ][[1]]] actually evaluates to τ. You need to Hold the expression inside NIntegrate to prevent premature application of Part: NIntegrate[Hold[integrand[τ] [[1]] ], {τ, τMin0, τMax0}]. See this and this. $\endgroup$ – MarcoB Aug 6 '15 at 0:03

With your definition that uses an unnecessary list and then takes a part

integrand[t_?NumericQ] := {1000/Sqrt[t^2 - tMin0^2], 0};



This occurs because integrand cannot evaluate with a symbolic input so the first part of the unevaluated expression is the function's argument.


tMin0 = 1/10;
tMax0 = 2;
integrand[t_?NumericQ] := 1000/Sqrt[t^2 - tMin0^2];
2*NIntegrate[integrand[t], {t, tMin0, tMax0}]
2*NIntegrate[1000/Sqrt[t^2 - tMin0^2], {t, tMin0, tMax0}]



Comparing with the exact value

2*Integrate[1000/Sqrt[t^2 - tMin0^2], {t, tMin0, tMax0}]

2000 Log[20 + Sqrt[399]]

% // N


| improve this answer | |
  • $\begingroup$ Of course the list is needed in what I want to do. This piece of code is a part of a much bigger one where the list is needed. I have just simplified it for the sake of clarity and to provide the minimum example. $\endgroup$ – lambertmular Aug 6 '15 at 9:33

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