1
$\begingroup$

I am trying to plot a function, but the output is not continuous. Here is my code

Plot[(
  E^(-(s/lm))
    v (lm - 
     2 lm Hypergeometric2F1[1, -(lg/lm), 1 - lg/lm, E^(s/lg)] - 
     2 E^(s/lm) (s - lg Log[1 - E^(s/lg)])))/H, {s, 3, 4}]

I then tried to plot the imaginary part to see if the empty space between the lines in the above graph comes from an imaginary number.

Plot[Im[(
  E^(-(s/lm))
    v (lm - 
     2 lm Hypergeometric2F1[1, -(lg/lm), 1 - lg/lm, E^(s/lg)] - 
     2 E^(s/lm) (s - lg Log[1 - E^(s/lg)])))/H], {s, 3, 4}]

The imaginary part is small, and I am not sure if the imaginary part is numerical error, or they are these small imaginary parts that make the output of the plot to have empty spaces between the lines. Could someone please help me?

I used H=0.1, v=0.5, lg=1; lm=2;

$\endgroup$
2
  • 1
    $\begingroup$ Without the values that you used for {H, lg, lm, v}, we cannot reproduce your results. $\endgroup$
    – Bob Hanlon
    Commented Jun 20 at 19:14
  • $\begingroup$ Thanks for your comments. Added @BobHanlon $\endgroup$ Commented Jun 20 at 19:25

1 Answer 1

2
$\begingroup$
$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global`*"]

f = (E^(-(s/lm))  v  (lm - 
       2  lm  Hypergeometric2F1[1, -(lg/lm), 1 - lg/lm, E^(s/lg)] - 
       2  E^(s/lm)  (s - lg  Log[1 - E^(s/lg)])))/H /. {H -> 0.1, v -> 0.5, 
   lg -> 1, lm -> 2}

(* 5. E^(-s/2) (2 - 4 Hypergeometric2F1[-(1/2), 1, 1/2, E^s] - 
   2 E^(s/2) (s - Log[1 - E^s])) *)

If you are getting imaginary artifacts with your version, try using exact values and simplifying.

f2 = (E^(-(s/lm))  v  (lm - 
         2  lm  Hypergeometric2F1[1, -(lg/lm), 1 - lg/lm, E^(s/lg)] - 
         2  E^(s/lm)  (s - lg  Log[1 - E^(s/lg)])))/H /. {H -> 1/10, v -> 1/2,
      lg -> 1, lm -> 2} // FunctionExpand // Simplify

(* 10 (-E^(-s/2) - s + 2 E^(-s/2) Sqrt[E^s] ArcTanh[Sqrt[E^s]] + Log[1 - E^s]) *)

Both plots are continuous

Plot[{f, f2}, {s, 3, 4},
 PlotStyle -> {Automatic, Dashed}]

enter image description here

EDIT: Or for a more robust solution, use ComplexExpand with f2

f3 = Assuming[s > 0, 
  f2 // ComplexExpand[#, TargetFunctions -> {Re, Im}] & // Simplify]

(* 10 (-E^(-s/2) - s + 2 Log[1 + E^(s/2)]) *)

FunctionDomain[f3, s]

(* True *)

Although f3 was developed assuming s > 0, f3 == f2 for real s

Assuming[s ∈ Reals, 
 ComplexExpand[f2 == f3, TargetFunctions -> {Re, Im}] // FullSimplify]

(* True *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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