0
$\begingroup$

I have this code:

In[1]:= H[u_] = 
  1/2 ((-2 + Erfc[-((5 u)/Sqrt[2])]) Log[
       1 - 1/2 Erfc[-((5 u)/Sqrt[2])]] - (Erfc[-((5 u)/Sqrt[2])] - 
        Erfc[-((3 u)/Sqrt[2])]) Log[
       1/2 (Erfc[-((5 u)/Sqrt[2])] - 
          Erfc[-((3 u)/Sqrt[2])])] - (Erfc[-((3 u)/Sqrt[2])] - 
        Erfc[-(u/Sqrt[2])]) Log[
       1/2 (Erfc[-((3 u)/Sqrt[2])] - Erfc[-(u/Sqrt[2])])] - 
     Erfc[-(u/Sqrt[2])] Log[1/2 Erfc[-(u/Sqrt[2])]]);

In[2]:= H[2.1] // Log10 // N[#, 10] &

Out[2]= Indeterminate

In[3]:= H[Rationalize[2.1, 10^-10]] // Log10 // N[#, 10] &

Out[3]= -1.047657131

However, when I do

In[4]:= Plot[(H[Rationalize[u, 10^-10]] // Log10 // N[#, 10] &) // 
  Evaluate, {u, 0, 3}, PlotRange -> All]

I get an incomplete plot; the values of the function for u>1.7 (or so) are apparently left unevaluated:

Out[4]= 

enter image description here

How to fix this?

$\endgroup$
1
  • $\begingroup$ Use H[u_] := rather than H[u_] = and things should work fine. $\endgroup$
    – JimB
    Feb 9 '18 at 21:32
3
$\begingroup$

Use the WorkingPrecision option in Plot

H[u_] = 1/2 ((-2 + Erfc[-((5 u)/Sqrt[2])]) Log[
       1 - 1/2 Erfc[-((5 u)/Sqrt[2])]] - (Erfc[-((5 u)/Sqrt[2])] - 
        Erfc[-((3 u)/Sqrt[2])]) Log[1/2 (Erfc[-((5 u)/Sqrt[2])] - 
          Erfc[-((3 u)/Sqrt[2])])] - (Erfc[-((3 u)/Sqrt[2])] - 
        Erfc[-(u/Sqrt[2])]) Log[
       1/2 (Erfc[-((3 u)/Sqrt[2])] - Erfc[-(u/Sqrt[2])])] - 
     Erfc[-(u/Sqrt[2])] Log[1/2 Erfc[-(u/Sqrt[2])]]);

Plot[H[u] // Log10, {u, 0, 3}, WorkingPrecision -> 15, PlotRange -> All]

enter image description here

$\endgroup$
4
  • $\begingroup$ Thank you. A crazy thing is that this works on a Windows 10 computer, but not on Windows 7 one! Cf. the opposite kind of situation described at mathematica.stackexchange.com/questions/165423/… . Can anyone explain these crazy things? $\endgroup$ Feb 11 '18 at 0:53
  • $\begingroup$ @IosifPinelis - what version of Mathematica are you running in each case? If both are the current version (11.2), report it to Wolfram support. $\endgroup$
    – Bob Hanlon
    Feb 11 '18 at 1:23
  • $\begingroup$ @IosifPinelis - if part of the plot is missing it is may be due to imaginary artifacts from precision issues. Since you know that the function is real in the range of interest, try plotting Re[H[u]//Log10] or H[u]//Log10//Chop with Windows 7. $\endgroup$
    – Bob Hanlon
    Feb 11 '18 at 1:32
  • $\begingroup$ Thank you for your additional, helpful comments as well. $\endgroup$ Feb 11 '18 at 4:21

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.