I would like to find the minimum of the function EER[a, v] using parallel computing.
If I write the code like this, it works:
ClearAll["Global`*"]
Kx[a_?NumericQ] :=
NIntegrate[(E^(-((2 r)/a)) (-2 a + r))/(
a^2 r NIntegrate[Exp[-(r/a)]^2 r^2, {r, 0, [Infinity]}])*
r^2, {r, 0, [Infinity]}];
Ko[v_?NumericQ] := ((-1.05 + 0.69* v)* v)/(2.27 + v (-3.02 + 1.1 v));
EER[a_, v_] := Ko[v]*Kx[a];
Exx =
ParallelTable[{v,
FindMinimum[{Etmp = EER[a, v], (0.1 < a < 30)}, {{a, 1}},
EvaluationMonitor :> {Pause[0.1],
Print[" Current a=", a, " E=", Etmp]}]}, {v, {7.5, 10, 12.5,
15}}]
Now I want to denote part of the expression in Kx[a_?NumericQ] like K[a_?NumericQ] but in the case of such entry, the code stops working. Why doesn't the code work?
ClearAll["Global`*"]
K[a_?NumericQ] := (E^(-((2 r)/a)) (-2 a + r))/(
a^2 r NIntegrate[Exp[-(r/a)]^2 r^2, {r, 0, [Infinity]}])
Kx[a_?NumericQ] := NIntegrate[K[a]*r^2, {r, 0, [Infinity]}];
Ko[v_?NumericQ] := ((-1.05 + 0.69* v)* v)/(2.27 + v (-3.02 + 1.1 v));
EER[a_, v_] := Ko[v]*Kx[a];
Exx =
ParallelTable[{v,
FindMinimum[{Etmp = EER[a, v], (0.1 < a < 30)}, {{a, 1}},
EvaluationMonitor :> {Pause[0.1],
Print[" Current a=", a, " E=", Etmp]}]}, {v, {7.5, 10, 12.5,
15}}]






K, rename toK2for example. Longer answer:Kis a built-in symbol, in particularContext[K]isSystem`. This means that the definition you have given forKis not automatically distributed to other kernels, only definitions for symbols inGlobal`are. – user293787 Dec 21 '22 at 19:24