4
$\begingroup$

I'm in a bit of a pickle:

I try to plot a graph of a simple function, and for some reason unknown to me, it is drawn blank even though evaluation of the function at specific points returns the required values. My code is as follows:

A = 0.1;
B = 0.11;
CParam[x_] :=  BesselK[2, A/x] BesselI[0, B/x] + BesselI[2, A/x] BesselK[0, B/x];
Plot[Log[Log[-CParam'[x]]], {x, 10^-8, 10^-5}]

However, typing {Log[Log[-CParam'[10^-5]]], Log[Log[-CParam'[10^-6]]], Log[Log[-CParam'[10^-7]]], Log[Log[-CParam'[10^-8]]]} returns {6.91618835667271168, 9.211416996515317434, 11.5130562034263446895, 13.81552593513862411174}.

Why doesn't Plot work properly?

Thanks

$\endgroup$
7
  • $\begingroup$ try LogLinearPlot, and try manually specifying PlotRange $\endgroup$
    – george2079
    Commented Oct 24, 2016 at 11:25
  • $\begingroup$ you also may need to do Plot[Evaluate[expression],..] because of the derivative $\endgroup$
    – george2079
    Commented Oct 24, 2016 at 11:30
  • $\begingroup$ Nope. Neither work. $\endgroup$
    – EZLearner
    Commented Oct 24, 2016 at 12:19
  • 1
    $\begingroup$ Seems to be a bug. Try ListLinePlot@ Table[Log[Log[-CParam'[x]]], {x, Subdivide[10^-8, 10^-5, 100]}] (I'm on V11.0.0.) $\endgroup$
    – Michael E2
    Commented Oct 24, 2016 at 12:31
  • 1
    $\begingroup$ Works fine under "10.4.1 for Linux x86 (64-bit) (April 11, 2016)". $\endgroup$
    – corey979
    Commented Oct 24, 2016 at 13:29

2 Answers 2

3
$\begingroup$

I think this is a bug in Plot[].

Aside from making a table and ListPlot-ing it, such as in my comment,

ListLinePlot@ Table[Log[Log[-CParam'[x]]], {x, Subdivide[10^-8, 10^-5, 100]}]

one could use NDSolve to get adaptive sampling:

ListLinePlot@
 NDSolveValue[{y[x] == Log[Log[-CParam'[x]]], z'[x] == 1, 
   z[10^-8] == 0}, y, {x, 10^-8, 10^-5}, PrecisionGoal -> 3]

Mathematica graphics


Adaptive sampling is not needed here, but in an oscillatory function, it could be helpful, should Plot[] fail as in this case.

Options[adaptiveListLinePlot] = Options[ListLinePlot];
adaptiveListLinePlot[f_, {x_, a_, b_}, opts : OptionsPattern[]] :=
  Module[{y, z, a1, b1},
   {a1, b1} =              (* open sampling *)
    Rescale[{Sqrt@$MachineEpsilon, 1 - Sqrt@$MachineEpsilon}, {0, 1}, {a, b}]; 
   ListLinePlot[
    NDSolveValue[{y[x] == f, z'[x] == 1, z[a1] == 0}, y, {x, a1, b1}, PrecisionGoal -> 3],
    opts]
   ];

adaptiveListLinePlot[Sin[x^2], {x, 0, 20}]

Mathematica graphics

$\endgroup$
1
$\begingroup$

I can verify the comment of @Michael E2 as I ran into the same problem with LogPlot on Version 11.0. The solution he suggested worked for me by extracting the calculation from inside Plot into Table. So for your problem it works like this:

A = 0.1;
B = 0.11;
CParam[x_] := BesselK[2, A/x] BesselI[0, B/x] + BesselI[2, A/x] BesselK[0, B/x];
stepIncrement = 10^(-8);
data = Table[Log[Log[-CParam'[x]]], {x, 10^-8, 10^-5, stepIncrement}];
ListPlot[data]

Choose the value of stepIncrement to a value that fulfills your requirements regarding precision.

$\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.