7
$\begingroup$

Could someone please tell me how I can increase the accuracy of this plot, please? Or is there some other reason the lines are breaking up?

m = 60;
ContourPlot[{Re[Table[BernoulliB[n, (x + I y)], {n, m, m}]], 
Im[Table[BernoulliB[n, (x + I y)], {n, m, m}]]}, {x, -5, 6}, {y, -10, 10}, 
AspectRatio -> Automatic]

enter image description here

$\endgroup$
  • 1
    $\begingroup$ Have a look at the PlotPoints option $\endgroup$ – ssch Oct 31 '13 at 17:40
  • 2
    $\begingroup$ In addition to PlotPoints, you can increase MaxRecursion too (carefully, increasing it by 1 at a time, as running time depends exponentially on this parameter). Try MaxRecursion -> 3 without touching PlotPoints. $\endgroup$ – Szabolcs Oct 31 '13 at 17:43
  • 2
    $\begingroup$ PlotPoints -> 200 fixes the problem. $\endgroup$ – bill s Oct 31 '13 at 18:18
  • $\begingroup$ Thank you very much for your help on this :-) $\endgroup$ – martin Nov 1 '13 at 10:54
5
$\begingroup$

As you already know from the comments, increasing MaxRecursion or PlotPoints helps, where I would prefer the first one.

In the case of your function, you can gain some speed by compiling the expression. Then, you can set MaxRecursion to a higher value and the plot is still reasonable fast. The code below runs in about 3 seconds here

m = 60;
With[{cf = (Compile[{{x, _Real, 0}, {y, _Real, 0}},
        #, RuntimeOptions -> "Speed", CompilationTarget -> "C"] & /@

           Flatten[{Re[Table[BernoulliB[n, (x + I y)], {n, m, m}]], 
        Im[Table[BernoulliB[n, (x + I y)], {n, m, m}]]}])},
  (#1[args__?NumericQ] := #2[args]) & @@@ Transpose[{{f1, f2}, cf}]
  ];

ContourPlot[{f1[x, y], f2[x, y]}, {x, -5, 6}, {y, -10, 10}, 
 AspectRatio -> Automatic, MaxRecursion -> 3]

Mathematica graphics

$\endgroup$
1
$\begingroup$

Simple and fast solution

m = 60;
f = Evaluate@N@BernoulliB[m, #] &;

ContourPlot[{Re@f[x + I y], Im@f[x + I y]}, {x, -5, 6}, {y, -10, 10}, 
 AspectRatio -> Automatic, MaxRecursion -> 3]

enter image description here

It has the same speed as halirutan's solution with Compile. I think it is because of auto-compilation.

$\endgroup$

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.