Automatically generating sums in Mathematica

此生再无相见时 提交于 2019-12-06 06:05:58

I would bunch together the fixed and free variables and specify them all in a list as

variables={{1,{-1}},{3,{9}},{4,Range[5]},{5,Range[6]}};

Then your sumProduct can be implemented quite concisely

sumProduct[f_, factors_, vars_] := Module[{x}, Sum[
   Times @@ ((Subscript[f, ##] @@ (Subscript[x, #] & /@ {##}) &) @@@ factors),
   Sequence @@ ({Subscript[x, #1], #2} & @@@ vars)]]

Which is called as sumProduct[f,factors,variables] to spit out a long thing:

Subscript[f, 1,4][-1,1] Subscript[f, 3,4][9,1] Subscript[f, 3,4,5][9,1,1]+....

Was this what you were after?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!