1
$\begingroup$

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?

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – J. M. will be back soon Jul 2 '16 at 19:59
  • $\begingroup$ I made the edits and now I'm getting as my output: "0." This doesnt make sense. $\endgroup$ – Junaid Aftab Jul 2 '16 at 20:02
  • $\begingroup$ Please edit your post to show the edited version you speak of. $\endgroup$ – J. M. will be back soon Jul 2 '16 at 20:04
  • $\begingroup$ Edited. Same error with the suggestions you suggested. $\endgroup$ – Junaid Aftab Jul 2 '16 at 20:06
  • 1
    $\begingroup$ ...question: did you notice the square bracket after (1/2) in your code? $\endgroup$ – J. M. will be back soon Jul 2 '16 at 20:23
1
$\begingroup$

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])/ω
*)

Mathematica graphics

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

Mathematica graphics

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).

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – Junaid Aftab Jul 2 '16 at 20:50
  • $\begingroup$ Somehow I suspect that 70000 is supposed to be , but @Junaid should be the one to confirm... $\endgroup$ – J. M. will be back soon Jul 2 '16 at 20:53
  • $\begingroup$ Yeah, my instructor just told me to use a very large number when dealling with infinities. $\endgroup$ – Junaid Aftab Jul 2 '16 at 20:54
  • $\begingroup$ 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... $\endgroup$ – mikado Jul 2 '16 at 20:57
  • $\begingroup$ @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. $\endgroup$ – Michael E2 Jul 2 '16 at 20:59

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.