# Error with Numerical Integration and Graph Plotting

I'm trying to run the following code:

β = 1;
ωc = 15;
G = 0.01;

integral4 :=
G ω Exp[-ω/ωc] ((
1 - Cos[ω τ] )/ω^2 ) Coth [βω/2]

Plot[ - (1/τ) Log[
1/2 + 1/2 Exp[ -
NIntegrate[integral4, {ω, 0, 70000},
Method -> "LocalAdaptive", MaxRecursion -> 15]] ], {τ, 0,
3}]


But I get the errors:

1. NIntegrate::inumr: The integrand integral4 has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,70000}}. >>
2. NIntegrate::inumr: The integrand integral4 has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,70000}}. >>
3. NIntegrate::inumr: The integrand integral4 has evaluated to non-numerical values for all sampling points in the region with boundaries {{0.,70000.}}. >>
4. General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation. >>

How do I get around it?

• You should be using Cos[] and Coth[] (capitalization matters!) and square brackets, not parentheses. Please do read the docs on how to use these functions. Commented Jul 2, 2016 at 19:59
• I made the edits and now I'm getting as my output: "0." This doesnt make sense. Commented Jul 2, 2016 at 20:02
• Please edit your post to show the edited version you speak of. Commented Jul 2, 2016 at 20:04
• Edited. Same error with the suggestions you suggested. Commented Jul 2, 2016 at 20:06
• ...question: did you notice the square bracket after (1/2) in your code? Commented Jul 2, 2016 at 20:23

Spaces matter. If we check the OP's integral4 we find in the output an undefined symbol βω. Probably it was meant to be a β ω, meaning β * ω.

integral4 := G ω Exp[-ω/ωc] ((1 - Cos[ω τ])/ω^2) Coth[βω/2]

integral4
(*
(0.01 E^(-ω/15) (1 - Cos[τ ω]) Coth[βω/2])/ω
*)


integral4 = G ω Exp[-ω/ωc] ((1 - Cos[ω τ])/ω^(2)) Coth[β ω/2];

Plot[-(1/τ) Log[
1/2 + 1/2 Exp[-NIntegrate[integral4, {ω, 0, 70000},
Method -> "LocalAdaptive", MaxRecursion -> 15]]],
{τ, 0, 3}]


By the way, the way I usually check a NIntegrate::inumr error is to evaluate the integrand at a value in the interval (use a real number with a decimal point):

integral4 /. ω -> 0.1    (* using OP's definition of integral4 *)
(*  0.0993356 (1 - Cos[0.1 τ]) Coth[βω/2]  *)


You can see I don't get a number and I see that βω does not have a numeric value. You can also see τ is not numeric either, but here it's important to understand the order of evaluation. Plot holds its argument; the variable τ is set to a value temporarily; then Plot releases its hold and the argument is evaluated (at this point τ has a numeric value and NIntegrate evaluates without error).

• Hi Micheal E2. Thanks, you're a life saver. I'll try and run the command on Mathematica. I'm having a torrid time with time. I need it for my physics project and I went through a one hour tutorial (lists, strings etc.) online and I started figuring out how to use it for my purposes. Any idea how I can better tackle it for my purposes? Is there an effective method to the madness because I have no experience with programming. Commented Jul 2, 2016 at 20:50
• Somehow I suspect that 70000 is supposed to be ∞, but @Junaid should be the one to confirm... Commented Jul 2, 2016 at 20:53
• Yeah, my instructor just told me to use a very large number when dealling with infinities. Commented Jul 2, 2016 at 20:54
• Sometimes replacing infinity with a large number is a good approach to numerical integrals. Other times, it prevents a transformation from an infinite to finite range. Certainly, you should choose a finite upper limit based on where your function becomes negligible... Commented Jul 2, 2016 at 20:57
• @JunaidAftab NIntegrate[integral4, {\[Omega], 0, Infinity}] works just fine without any fancy stuff. Partly you'll get used to the syntax if you learn that every distinct character has a distinct meaning (e.g. (, [, spaces, etc.). Plotting integrals and derivatives seems to be tricky for new users. (We get lots of questions.) Otherwise, play with the examples in the documentation. There's no really quick way to learn a new system as complicated and powerful as Mathematica. Commented Jul 2, 2016 at 20:59