Mathematica 9 is now available
Student Support Forum
-----
Student Support Forum: 'problem with "apply"' topicStudent Support Forum > General > Archives > "problem with "apply""

Next Comment >Help | Reply To Topic
Author Comment/Response
Brian
02/08/13 00:11am

I recently discovered the function "apply", which has really helped me deal with sums over unspecified numbers of variables, eg:

Apply[ Sum, Flatten[ { f[m] , Table[ {m[[j]],0,n} , {j,1,N}] , 1] ]

This gives a sum of the function f[m] over N variables m[[1]],...,m[[N]]].

The problem I'm having is very technical, but necessary for the application I have. Here's a simplified example that illustrates the problem:

Input:
z = {z1, z2};
Sum[ Product[ If[m > 0, z[[i]], 1] , {i, 1, 2}], {m, 0, 1}]
Apply[ Sum , {Product[ If[m > 0, z[[i]], 1], {i, 1, 2}], {m, 0, 1}}]

Output:
1 + z1 z2
1 + {z1, z2}[[i]]^2

Obviously I don't need to use apply for this simple example, but the problem I'm actually doing requires sums over arbitrarily many variables. I have only had this kind of problem with such a product containing an if statement. Can someone explain why the two lines are not identical, as I thought they should be?

URL: ,

Subject (listing for 'problem with "apply"')
Author Date Posted
problem with "apply" Brian 02/08/13 00:11am
Re: problem with yehuda 02/09/13 10:27am
Re: Re: problem with Brian 02/09/13 5:13pm
Re: problem with yehuda 02/11/13 08:41am
Next Comment >Help | Reply To Topic