# Message Boards

0
|
2389 Views
|
0 Replies
|
0 Total Likes
View groups...
Share
 Can anyone help me understand why the Compile fails here: f = Compile[{{\[Sigma]t, _Real, 1}, {s\[Rho], _Complex, 1}, {dt, _Real, 1}, {x, _Real}, {nnt, _Integer}}, Module[{kz = 1/2 x, \[Sigma] = \[Sigma]t, d = dt, i, kp, c, \[Beta], r, k, \[Rho] = s\[Rho] * 10^-6, nn = nnt}, kp = kz + 0. I; k = Sqrt[kz^2 - 4 \[Pi] (\[Rho][[2]] - \[Rho][[1]])]; r = (kp - k)/(kp + k) E^(-2 kp k \[Sigma][[1]]^2); c = {{1 + 0. I, r }, {r , 1 + 0.}}; kp = k; For[i = 2, i < 2 nn + 2, i++, If[EvenQ[i], k = Sqrt[kz^2 - 4 \[Pi] (\[Rho][[3]] - \[Rho][[1]])]; r = (kp - k)/(kp + k) E^(-2 kp k \[Sigma][[2]]^2); \[Beta] = I kp d[[1]], k = Sqrt[kz^2 - 4 \[Pi] (\[Rho][[2]] - \[Rho][[1]])]; r = (kp - k)/(kp + k) E^(-2 kp k \[Sigma][[3]]^2); \[Beta] = I kp d[[2]] ]; c = c.{{E^\[Beta], r E^\[Beta]}, {r E^-\[Beta], E^-\[Beta]}}; (*previous k*) kp = k ]; Abs[(c[[2, 1]] + 1*^-100 + I 1*^-200 )/( c[[1, 1]] + 1*^-100 + I 1*^-200)]^2] , CompilationTarget -> "C"] In[43]:= f[{0, 0, 0}, {0, 24, 5}, {6, 4}, 0.025, 1000] During evaluation of In[43]:= CompiledFunction::cfne: Numerical error encountered; proceeding with uncompiled evaluation. >> Out[43]= 1.00000000000000