Re: Problem with using /.

*To*: mathgroup at smc.vnet.net*Subject*: [mg69231] Re: Problem with using /.*From*: Peter Pein <petsie at dordos.net>*Date*: Sun, 3 Sep 2006 01:39:32 -0400 (EDT)*References*: <edadil$pd0$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Nag schrieb: > Hello: > > I am trying to compute the moments of a distribution using the moment > generating function, MGF[t,k]. Here is the relevant function for > computing the j'th moment. > > M[j_, t_, k_] := D[MGF[t, k], {t, j}] /. {u -> 0, Sum[Subscript[p, > i],{i, 0, k}] = 1}; > > After taking the j'th derivative, need to set u to 0 and the sum of > p(i)'s to 1. > > When I execute M[3, u, 5], get the following error.(converted output to > input form) > > \!\(\* > StyleBox[ > ErrorBox[\(Set:: > "\<write\>" : > "\<Tag \!\(Sum\) in \!\(\(â??\+\(i = 0\)\%5\) p\_i\) is > Protected. \!\(\*ButtonBox[\"Moreâ?¦\", > ButtonStyle->\"RefGuideLinkText\ > \", ButtonFrame->None, ButtonData:>\"General::write\"]\)\>"\)], > ShowStringCharacters->True]\) > > Of course I can explicitly set p0+p1+..+p5 = 1 after executing M[3,u,5] > but involves more effort as k increases. > Is it possible to make the substitution work for general k in the > function definition M[....]? > > Best > Nag > Hi Nag, you try to assign a value to Sum[...]; this becomes Set[Sum[...],0] -- but Sum is a Protected function. Furthermore, Set is not Rule. I guess you wanted: M[j_, t_, k_] := FullSimplify[D[MGF[t, k], {t, j}] /. u -> 0, Sum[Subscript[p, i], {i, 0, k}] == 1]; You can use Simplfy instead of FullSimplify too. Peter