0
$\begingroup$

enter image description here

I have an index CC and a set of values CM, and c is an element of CM and CM is a subset of CC. I have two summations shown above. The first summation is over index CC and the subset CM. The light brown colored part of the first summation is telling that the summation should include only if c is an element of CM. The second summation is over the elements of CM.

These two summations appear in an equation (not given here for simplicity). Is there an easy way to perform these summations?

Thank you...

EDIT 1 The answer to the above summations is as follows.

(* first summation *)

tq[1]*PD[1]+
tq[2]*PD[2]+PM[2] +
tq[3]*PD[3]+PM[3] +
tq[4]*PD[4]+
tq[5]*PD[5]+
tq[6]*PD[6]+PM[6]+
tq[7]*PD[7]

(* Second summation *)

tq[2]*(PD[2]+QD[2])+
tq[3]*(PD[3]+QD[3])+
tq[6]*(PD[6]+QD[6])
$\endgroup$
  • 2
    $\begingroup$ Is your first sum = tq[1]*PD[1]+ tq[2]*PD[2]+PM[2]+ tq[3]*PD[3]+PM[3]+ tq[4]*PD[4]+ tq[5]*PD[5]+ tq[6]*PD[6]+PM[6]+ tq[7]*PD[7]? Is your second sum = tq[2]*PD[2]*QD[2]+ tq[3]*PD[3]*QD[3]+ tq[6]*PD[6]*QD[6]? $\endgroup$ – Bill Mar 30 at 2:03
  • $\begingroup$ @Bill: Yes, your answer is right. I edited the question with the expected answer. Thanks. $\endgroup$ – Tugrul Temel Mar 30 at 11:54
1
$\begingroup$

If it is desirable to have everything in a single sum, then the first sum could be written as

cc = 7;
CM = {2, 3, 6};
Sum[tq[c]*PD[c] + PM[c] Boole[MemberQ[CM, c]], {c, cc}]
(* PM[2] + PM[3] + PM[6] + PD[1] tq[1] + PD[2] tq[2] + PD[3] tq[3] + 
   PD[4] tq[4] + PD[5] tq[5] + PD[6] tq[6] + PD[7] tq[7] *)
$\endgroup$
  • $\begingroup$ Thank you very much indeed because you helped me solve another question for which I was preparing a MM example. Tugrul $\endgroup$ – Tugrul Temel Mar 30 at 14:20
3
$\begingroup$

Try,

Sum[tq[c] PD[c], {c, 7}] + Sum[PM[c], {c, CM}]
(* PM[2] + PM[3] + PM[6] + PD[1] tq[1] + PD[2] tq[2] + PD[3] tq[3] + 
   PD[4] tq[4] + PD[5] tq[5] + PD[6] tq[6] + PD[7] tq[7] *)

Sum[tq[c] pd[c] qd[c], {c, CM}]
(* pd[2] qd[2] tq[2] + pd[3] qd[3] tq[3] + pd[6] qd[6] tq[6] *)

If desired, Sum[tq[c] PD[c], {c, 7}] can be replaced by Sum[tq[c] PD[c], {c, CC}], yielding the same result.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.