2
$\begingroup$

I am trying to plot the function:

f(x)=(1-exp(-Vx^m))/(1-(1-x^m)^V)-1

for various values of $V$ and $m$ ranging from 1 to 30, and from $0\leq x\leq1$. How can I avoid numerical evaluation errors near zero? I've tried:

LogLinearPlot[(1-Exp[-4*x^6])/(1-(1-x^6)^(4))-1,{x,10^-6,1},PlotRange->{-1,1}]

But get warnings and an oscillatory behavior of the plot which I am not sure is correct, because the limit of the function is 0 at $x=0$.

$\endgroup$
1
  • $\begingroup$ Maybe: LogLinearPlot[ Piecewise[{{0, 0 < x < 10^-3}}, (1 - Exp[-4*x^6])/(1 - (1 - x^6)^(4)) - 1], {x, 0, 1}, PlotRange -> {-1/10, 1/10}, WorkingPrecision -> 15] $\endgroup$ Dec 29, 2020 at 10:28

1 Answer 1

2
$\begingroup$

Your function is numerically ill defined around zero. But you may replace the function by a limit. And you need to increase the working precision

f[x0_] := Limit[(1 - Exp[-4*xx^6])/(1 - (1 - xx^6)^(4)) - 1, xx -> x0]
LogLinearPlot[{f[x]}, {x, 10^-6, 1}, PlotRange -> {-.1, .1}, WorkingPrecision -> 20]

enter image description here

$\endgroup$
2
  • $\begingroup$ Thanks. The limit did the trick. One follow up, out of curiosity. I actually want to plot multiple values of V, so I do, for example for m=6: f[x0_, V0_] := Limit[(1 - Exp[-V0*xx^6])/(1 - (1 - xx^6)^(V0)) - 1, xx -> x0] Plot[Evaluate@Table[f[x, V], {V, 2, 10, 2}], {x, 0, 1}, WorkingPrecision -> 20] The composite plot is correct, because it looks the same as if I do each plot individually. However, the warnings are back (not a big deal, just curious as I said). Any idea why? $\endgroup$ Dec 30, 2020 at 7:14
  • $\begingroup$ I can only guess. But if you call f[x,V] with symbolic parameters, the limit can fail. And Evaluate@Table[f[x, V], {V, 2, 10, 2}] calls f[x,V] with symbolic x. This happens also with Plot[f[x,4],...] because Plothas the attribute HoldAll and tries first to simplify the given function symbolically. Therefore, to be on the safe side, declare: f[x0_?NumericQ, V0_?NumericQ] :=... $\endgroup$ Dec 30, 2020 at 9:44

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.