Group Abstract Group Abstract

Message Boards Message Boards

0
|
2K Views
|
2 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Sum without "i" as index

Posted 3 years ago

Hi, i have to implement a sum of a function of a squared modulus of a vector and the sum runs from null vector to a certain vector. We are in a discretized space so that the vector components can take only integer values. I first constructed a list of all possible vectors with components (for simplicity) from -1 to +1, in this way:

a = Table[{i, j, k}, {i, -1, 1}, {j, -1, 1}, {k, -1, 1}]
b = Flatten[a, 2]

Now I have to implement the sum. I would construct an index that runs from 1 to the number of vectors in b, for any value of this index take the corresponding vector, calculate the squared modulus of that vector and evaluate the function on that value. Then sum all the values obtained. But I don't know how to construct such a cycle. Can you help me please?

POSTED BY: Davide Alfano
2 Replies
Posted 3 years ago

See if this does what you want.

Define your function f and follow that with

Map[f[Norm[#]]&,b]

to see a list of each of the individual results

and then try

Total[Map[f[Norm[#]]&,b]]

to see the sum of all those

POSTED BY: Bill Nelson
Posted 3 years ago

Thank you, it's perfect!

POSTED BY: Davide Alfano
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard