0

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

3.99
7376.51

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.

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
lambertmular
  • 119
  • 7
  • 1
    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. – MarcoB Aug 06 '15 at 00:03

1 Answers1

2
Clear[integrand]

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

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

integrand[t][[1]]

t

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

Clear[integrand]

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}]

7376.51

7376.51

Comparing with the exact value

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

2000 Log[20 + Sqrt[399]]

% // N

7376.51

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198
  • 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. – lambertmular Aug 06 '15 at 09:33