In[72]:= f = 5 - r^2 - r;
ff[r_] := 5 - r^2;
cf1 = Compile[{{r, _Real}}, f]
cf2 = Compile[{{r, _Real}}, ff[r]]
cf1[2]
cf2[2]
Out[74]= CompiledFunction[{11, 14., 5470}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {{5, {2, 0,
0}}}, {0, 1, 4, 0, 0}, {{46,
Function[{r}, f], 3, 0, 0, 3, 0, 1}, {1}},
Function[{r}, f], Evaluate]
Out[75]= CompiledFunction[{11, 14., 5470}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {}, {0, 0, 2, 0, 0}, {{47, ff,
3, 0, 0, 3, 0, 1}, {1}},
Function[{r},
ff[r]], Evaluate]
\:6B63\:5728\:8BA1\:7B97In[72]:= CompiledFunction::cfse: 被编译表达式 5-r-r^2 应该是一个 machine-size real number.
\:6B63\:5728\:8BA1\:7B97In[72]:= CompiledFunction::cfex: 在说明 1 中不能完成外部计算;继续未编译的计算.
Out[76]= 5 - r - r^2
Out[77]= 4.
ff[r_] := 5 - r^2;
cf1 = Compile[{{r, _Real}}, f]
cf2 = Compile[{{r, _Real}}, ff[r]]
cf1[2]
cf2[2]
Out[74]= CompiledFunction[{11, 14., 5470}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {{5, {2, 0,
0}}}, {0, 1, 4, 0, 0}, {{46,
Function[{r}, f], 3, 0, 0, 3, 0, 1}, {1}},
Function[{r}, f], Evaluate]
Out[75]= CompiledFunction[{11, 14., 5470}, {
Blank[Real]}, {{3, 0, 0}, {3, 0, 1}}, {}, {0, 0, 2, 0, 0}, {{47, ff,
3, 0, 0, 3, 0, 1}, {1}},
Function[{r},
ff[r]], Evaluate]
\:6B63\:5728\:8BA1\:7B97In[72]:= CompiledFunction::cfse: 被编译表达式 5-r-r^2 应该是一个 machine-size real number.
\:6B63\:5728\:8BA1\:7B97In[72]:= CompiledFunction::cfex: 在说明 1 中不能完成外部计算;继续未编译的计算.
Out[76]= 5 - r - r^2
Out[77]= 4.