Second try. (old answer preserved below for reference)
In the comments below Spawn's answer you said that you are trying to construct a table of functions. Does this do what you want?:
Pstatesalpha[λ_] = 0;
RankMatrix = {};
For[jsum = 1, jsum <= 3, jsum++,
Pstatesalpha[λ_] = (delem*a0)^2*SumPstatesalpha[λ] + Pstatesalpha[λ];
AppendTo[RankMatrix, {Alpharank, Function @@ {λ, Pstatesalpha[λ]}}]
]
The key detail is appending Function @@ {λ, Pstatesalpha[λ]}
which will build a function with the evaluated expression Pstatesalpha[λ]
as the body and the parameter λ
.
Now:
RankMatrix[[1, 2]][17]
a0^2 delem^2 SumPstatesalpha[17]
The question isSince the above was Accepted (thanks) let me explain a bit ambiguous, but here's a guess at what you want:better.
You hadI use the method fn @@ {args}
to evaluate args
and pass them to a function:
f[a_, b_] := a^2 + b/3
Somewhere it was transformed like: fn
(using Apply
) that otherwise holds its arguments (has a Hold attribute).
expr = f[a, b]
a^2 + b/3
AndIn the definition was lost:
Clear[f]
Now you can recovercode above, copied from the definition withquestion, there is a global symbol λ
which if assigned a value will break the code. One method to avoid this is to use a Formal Symbol, entered Esc$x
Esc where x
is any a-z letter. These symbols exist specifically for cases like this. Another method is to use Slot
as in the syntax # + 2 &
(notethe =FullForm
rather than usualof :=#
is Slot[1]
). That might look like this (in context):
f[a_AppendTo[RankMatrix, b_]{Alpharank, =Evaluate[Pstatesalpha[#]] expr;&}]
TestEvaluate
is used instead of Apply
and List
, but many methods are possible:
f[5Evaluate[Pstatesalpha[#]] &
Function @@ {Pstatesalpha[#]}
With[{body = Pstatesalpha[#]}, 7]body &]
Pstatesalpha[#] /. x_ :> (x &)
82/3
With each of these Pstatesalpha[#]
is evaluated outside of Function
and then inserted into it.