First of all, I am not entirely sure what the problem is. The code I am presenting worked in a previous version of Mathematica but not now in Version 11.0.1. Essentially, I am calculating Point Spread Functions (PSF) according to the theory outlined by Born & Wolf.
{λIll = 0.488, nIll = 1.518, NAIll = 1.3};
optIll = {v -> 2 π n r Sin[α]/λ,
u -> 2 π n z Sin[α]^2/λ, α ->
ArcSin[NA/n], n -> nIll, λ -> λIll,
NA -> NAIll, ρ -> rho};
The integral is split into two parts. The factor bwFIll and the integrand bwIIll are simplified separately.
bwFIll = Function[{r, z},
Evaluate@FullSimplify[-2.0 π I n Sin[α]^2/λ Exp[
I u/Sin[α]^2] //. optIll, ass]]
Output
(* Function[{r, z}, (0. - 14.3343 I) E^((0. + 19.5448 I) z)] *)
Texte
bwIIll = Function[{r, z},
Evaluate@FullSimplify[
BesselJ[0, v ρ] Exp[-0.5 I u ρ^2] ρ //. optIll,
ass]]
Output
(* Function[{r, z}, E^((0. - 7.16713 I) rho^2 z) rho BesselJ[0, 16.738 r rho]] *)
What drives me nuts is the presentation of the complex number as 0.0 - 7.16713 I instead of as simply as -7.16713 I. This was different in my original Notebook. I cannot reproduce this but I still have the notebook.
bwFullIll[r_, z_] :=
bwFIll[r, z] NIntegrate[bwIIll[r, z], {rho, 0.0, 1.0},
AccuracyGoal -> 6, WorkingPrecision -> MachinePrecision]
Calling the function is fine.
bwFullIll0 = bwFullIll[0, 0]
Output
(* 0. - 7.16713 I *)
This function calculates a scalar PSF.
illFull[r_, z_] :=
Block[{uill}, uill = bwFullIll[r, z]/bwFullIll0;
Chop[uill Conjugate[uill]]]
However, this function FindRoot and other functions such as NIntegrate all produce the same error list.
illR0 = (x /. FindRoot[illFull[x, 0.0] == 0.0, {x, 0.22}])
Output
During evaluation of In[9]:= NIntegrate::inumr: The integrand (1. +0. I) rho BesselJ[0,16.738 rho x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0.,1.}}.
During evaluation of In[9]:= NIntegrate::inumr: The integrand (1. +0. I) rho BesselJ[0,16.738 rho x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0.,1.}}.
During evaluation of In[9]:= NIntegrate::inumr: The integrand (1. +0. I) rho BesselJ[0,16.738 rho x] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0.,1.}}.
During evaluation of In[9]:= General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation.
Out[9]= 0.228923
I have no clue what is going on and really need to know what is causing the error message. I should add that I experienced with various options AccuracyGoal -> 6, WorkingPrecision -> MachinePrecision but to no avail. What works is the use of Table.
illFull[r_?NumericQ, z_?NumericQ] ...See http://mathematica.stackexchange.com/questions/18393/what-are-the-most-common-pitfalls-awaiting-new-users/26037#26037 -- As for the display of complex numbers, that seems to be how it's done (and has been for a while, I think). Reformatting output is possible, probably, but maybe not easy. – Michael E2 Jan 17 '17 at 19:00Chophas no effect. The0.is shown independently of whether the real or the imaginary part are zero. I also had another look at an older notebook (2001, no idea which version I used then). Ther_?NumericQ, which I have been using in other circumstances, was not required and the complex values reduced to the expected simpler values or are at least shown in simpler terms. – Ernst Stelzer Jan 18 '17 at 08:12bwFullIll0 = bwFullIll[0, 0] // Chopreturns0. - 7.16713 I. I.e. no effect ofChop. – Ernst Stelzer Jan 18 '17 at 13:02