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.
Det[a]
thousands of times, once for each possible value oft
. If you change it toPlot[Evaluate[Det[a]],{t,0,3}]
then it quickly returns an empty plot because it only needs to evaluate theDet
once and there are no real points to plot andPlot[Evaluate[ReIm[Det[a]]],{t,0,3}]
quickly returns the plot with the real curve and the imaginary curve. $\endgroup$MaxRecursion -> 0
andPlotPoints -> 2
so that there won't be thousands of times of evaluations. But it still freezes. $\endgroup$f[x_] := Module[{}, Print[x]; Det[a]; Abort[];];
, you can see that there is only one call to thef
, which then gets stuck at calculating the determinant. $\endgroup$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.355
3 I, 0.15893 }, {2.305
3, 0.014253}}]]
$\endgroup$