Group Abstract Group Abstract

Message Boards Message Boards

0
|
8.7K Views
|
4 Replies
|
1 Total Like
View groups...
Share
Share this post:

Summations in Mathematica

Posted 10 years ago

Does anyone know of a way that mathematica can solve the summation below. I understand you cannot use capital letter when defining variable, but this is just to demonstrate the basic idea I am getting at. I am trying to see what I can do and get away with in mathematica, so the variables may seem trivial.

These would be the defined sets

Subscript[X, 1, 1] = 1
Subscript[X, 1, 2] = 2
Subscript[X, 2, 1] = 3
Subscript[X, 1, 2] = 4
A[j] = {1, 2}
J = {1, 2}

enter image description here

POSTED BY: C McKinley
4 Replies

If you want to sum over an irregular index set, you can first build the index set explicitly and then sum over it:

setA[j_] = {1, 2};
setJ = {1, 2};
indexSet = Flatten[Table[{a, j}, {a, setA[j]}, {j, setJ}], 1];
Sum[Subscript[X, Sequence @@ ij], {ij, indexSet}]
POSTED BY: Gianluca Gorni
X = {{1, 2}, {3, 4}}
Sum[X[[i, j]], {i, 2}, {j, 2}]

will do as well

POSTED BY: Hans Dolhaine
Posted 10 years ago
POSTED BY: C McKinley

Subscripts are vauge and have many different meanings and uses. Please trust me and do not use them in Mathematica code until you know more about how Mathematica works and so you can understand how they work. Many newer Mathematica programmers want to use them and it doesn't go well. Math notation is very often not a good way to think about programming.

Are you looking to use tensor notation? There are packages for that you can find online, but they aren't exactly simple. You might be able to write code that looks like this with them, but I wouldn't suggest it unless you were a seasoned Mathematica programmer.

You could write your code like this:

x[1, 1] = 1;
x[1, 2] = 2;
x[2, 1] = 3;
x[2, 2] = 4;
Sum[x[i, j], {i, 1, 2}, {j, 1, 2}]

Or like

x[1, 1] = 1;
x[1, 2] = 2;
x[2, 1] = 3;
x[2, 2] = 4;
ivalues = {1, 2};
jvalues = {1, 2};
Sum[x[i, j], {i, ivalues}, {j, jvalues}]

But I think either of these is still a bit akward.

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