Consider the function
Z[entropy_, beta_] := Sum[E^(entropy[[i, 2]] - beta entropy[[i, 1]])
, {i, 1, Length[entropy]}]
where entropy is a list of pairs (e.g. E, S(E)). I will plot this as a function beta
. Since the parameter "entropy" is fixed in the plot, I wound't need to expand the sum every time, which this function is doing. So, I could try (the difference is =
instead of :=
)
Z[entropy_, beta_] = Sum[E^(entropy[[i, 2]] - beta entropy[[i, 1]])
, {i, 1, Length[entropy]}]
However, in this situation, because "entropy" is not defined, it will always return 0 (sum of 0 terms).
Ideally, I would like to write Z[entropyA, beta]
(where entropyA
is a list) and it return the sum expanded (lazy on beta), and when it is called as Z[entropyA, 1.2]
, it returns the outcome of the calculation (i.e. it replaces beta by 1.2 on the sum).
Which brings me to my question: how can I define a function that is lazy on one parameter (e.g. beta
), but not lazy on the other.
entropy
argument a list or an integer, and does your function have two or three arguments? $\endgroup$Z[entropy_List, beta_] := Total[E^(#2 - beta #1) & @@@ entropy]
; this will not expand unless the first argument is manifestly a list. $\endgroup$beta
? $\endgroup$