This is similar to a problem I had earlier.
I have a variable Gj that is related to the nj, for example:
Clear[nj]
Gj = If[nj[1] == 0, 0, nj[1] Log[nj[1]/(nj[1] + nj[2] + nj[3])]]
I would like to have a way of defining a function getGj
for a given Gj
. For the above example, the function would be defined by:
getGj[{a_,b_,c_}] := If[a == 0, 0,a Log[a/(a+b+c)]]
The closest I have come (thanks, Kuba) is:
Gj := If[nj[[1]]==0,0,nj[[1]] Log[nj[[1]]/(nj[[1]]+nj[[2]]+nj[[3]])]];
Unevaluated[getGj[nj_] := Gj;] /. OwnValues[Gj]
which works well for an input list with numeric values, but
ClearAll[xx,x]
xx=Array[x,3];
getGj[xx]
returns
If[x[1] == 0, 0,
{x[1],x[2],x[3]}[[1]] Log[{x[1],x[2],x[3]}[[1]]/({x[1],x[2],x[3]}[[1]] + {x[1],x[2],x[3]}[[2]]+{x[1],x[2],x[3]}[[3]])]]
rather than
If[x[1] == 0, 0, x[1] Log[x[1]/(x[1]+x[2]+x[3])]]
Gj = If[nj[1] == 0, 0, nj[1] Log[nj[1]/(nj[1] + nj[2] + nj[3])]]
, where does it come from? $\endgroup$