Message Boards Message Boards

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

Need help with a double sum (indices)

Posted 9 years ago

Hello all, I would like some help with the following issue. Consider a fooball (soccer) game. I want to create a function that returns the sum of all the possible outcomes, where one team wins and the total number of goals is less than a given line. For example, team 1 wins, and total goals less than 3.5 would return (1,0), (2,0), (2,1), (3,0). I used the following that works correctly:

line = 3.5;
sum = 0;
For[i = 1, i <= Floor[line], i++,
 For[j = 0, And[j < i, i + j < line], j++,
  sum = sum + cs[i, j]
  ]
 ]
sum

The output of this is:

cs[1, 0] + cs[2, 0] + cs[2, 1] + cs[3, 0]

My question is, how would I rewrite the same, using a double sum: Something like

Sum[cs[i,j],{i,1,Floor[line]},{j,a,b}]

where I am seeking for a and b.

Any help would be awsome, thank you in advance.

POSTED BY: Tom Zinger
2 Replies
Posted 9 years ago

Hi, Tom!

something like this could work:

Sum[If[i > j, cs[i, j], 0], {i, 1, Floor[line]}, {j, 0, Floor[line] - i}]

or:

Sum[cs[i, j], {i, 1, Floor[line]}, {j, 0, Min[Floor[line] - i, i - 1]}]
POSTED BY: Sandu Ursu
Posted 9 years ago

Both ways work perfect, great thinking man, thank you for your assistance!

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

Group Abstract Group Abstract