4
$\begingroup$

I find that Plot has some strange behavior.

a = {{-5.355`3 I, 0.1589`3 }, {2.305`3, 0.01425`3}};
Det[a] // Abs

gives 0.374

However,

f[x_] := Module[{},Det[a]];
Plot[f[3], {t, 0, 10}]

freezes. I'm not sure what Plot is doing with Det[a].

By removing the I in a to make it all real, Plot does not freeze.

By removing the 3 in a to make it machine precision, Plot does not freeze.

It looks like only arbitratry precision complex will freeze Plot. Can others reproduce this on their machine, or is it just something wrong with mine?

As mentioned in your replies, using Evaluate in Plot will help. But in fact, my code is some kind of short version of a long piece of code for numerical calculation where using Evaluate in Plot is not possible.

So I was tring to figure out what is happening behind the freeze. I tried adding MaxRecursion->0 and PlotPoints->2 so that there won't be thousands of times of evaluations. But it still freezes.

$\endgroup$
7
  • 3
    $\begingroup$ I'm guessing that it is spending all that time finding Det[a] thousands of times, once for each possible value of t. If you change it to Plot[Evaluate[Det[a]],{t,0,3}] then it quickly returns an empty plot because it only needs to evaluate the Det once and there are no real points to plot and Plot[Evaluate[ReIm[Det[a]]],{t,0,3}] quickly returns the plot with the real curve and the imaginary curve. $\endgroup$
    – Bill
    Commented Mar 13 at 15:17
  • $\begingroup$ I tried adding MaxRecursion -> 0 and PlotPoints -> 2 so that there won't be thousands of times of evaluations. But it still freezes. $\endgroup$
    – Ming
    Commented Mar 13 at 15:25
  • $\begingroup$ @Bill, I think there is actually something more seriously wrong (and weird) going on ... For example, using f[x_] := Module[{}, Print[x]; Det[a]; Abort[];];, you can see that there is only one call to the f, which then gets stuck at calculating the determinant. $\endgroup$
    – Domen
    Commented Mar 13 at 16:38
  • 3
    $\begingroup$ It's a plotting bug, which i will (dutifully) report. $\endgroup$ Commented Mar 13 at 19:23
  • 2
    $\begingroup$ Plot uses some tactics to make exponent sizes relatively tame. These are not playing nice with initializations required by bignum linear algebra. Here is distilled version of that hang (wherein I do not try to explain internal context veriables): Block[{Internal$MinExponent = 2*Log10[$MinMachineNumber], Internal$MaxExponent = 2*Log10[$MaxMachineNumber]}, Det[{{-5.3553 I, 0.15893 }, {2.3053, 0.014253}}]] $\endgroup$ Commented Mar 13 at 19:40

1 Answer 1

1
$\begingroup$

Try

a = {{-5.355`3 I, 0.1589`3}, {2.305`3, 0.01425`3}};
Det[a] // Abs

f[x_] := Module[{}, Det[a]];

Plot[Evaluate[ReIm[f[3]]], {t, 0, 10}]

enter image description here

$\endgroup$
1
  • $\begingroup$ I understand how this Evaluate helps, but I was tring to figure out what is happening behind the freeze. I tried adding MaxRecursion -> 0 and PlotPoints -> 2 so that there won't be thousands of times of evaluations. But it still freezes. In fact, my code is some kind of short version of a long piece of code for numerical calculation where using Evaluate in Plot is not possible. $\endgroup$
    – Ming
    Commented Mar 13 at 15:34

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.