I have to do a Plot3D
of a given function which takes very long, so I would like to have an idea of how long it would be. I am looking for the simplest way to monitor this.
Here is my code (well not exactly the one I use but I made a simpler example) :
H2[x_] := If[x != 0, If[x != 1, (-x)*Log[x] - (1 - x)*Log[1 - x], 0], 0]
Si[Theta_] := H2[Cos[Theta/2]^2]
kb = 1;
WextMaxOuiDegenBruitTh[T_, ΔI_] := (-kb)*T*ΔI
ηOuiDegenBruitTh[T_, ΔI_] := WextMaxOuiDegenBruitTh[T, ΔI]/Abs[ΔI]
Plot3D[ηOuiDegenBruitTh[Theta, ΔI], {Theta, 0, Pi/2}, {ΔI, -Log[2], 0},
RegionFunction -> Function[{Theta, ΔI}, -Si[Theta] < ΔI < 0], PlotPoints -> 10]
As you can see I gave the PlotPoints
parameter in my Plot3D so maybe there is a way to tell Mathematica to use the number of points it will have to compute on the plot to make a progress bar from it. But I don't know how to do that.
[EDIT] As suggested in the comment of the answer below, I can use EvaluationMonitor
to help me. However, I don't understand something. I changed my Plot3D line by replacing it with this for the example (all the code before is unchanged).
Plot3D[ηOuiDegenBruitTh[Theta, ΔI], {Theta, 0, Pi/2}, {ΔI, -Log[2], 0}, PlotPoints -> 20,
EvaluationMonitor -> Print["x"]]
As written in the documentation, I should have 20*20 points in this calculation, so 400 calculations in the end.
But when I run this line Mathematica only output "x" 3 times. So it is like Mathematica only did 3 calculations and not 400.
My problem is linked to the fact I probably misunderstood how EvaluationMonitor
works, but I don't know where I am wrong!
[EDIT for MarcoB]: My exact line is :
Monitor[
Plot3D[
ηOuiDegenBruitTh[Theta, ΔI], {Theta,0, Pi/2}, {ΔI, -Log[2], 0},
PlotPoints -> 100, MaxRecursion -> 0, EvaluationMonitor :> (x = x + 1)
],
ProgressIndicator[x, {0, 200^2}]
]
EvaluationMonitor
requires delayed rules,:>
instead of->
. $\endgroup$Plot3D
with a non-trivial function seem to be due to these extra calculations. You can turn that off usingNormalsFunction -> None
. This may affect visual properties of the graphic, so test it out. $\endgroup$