2
$\begingroup$

I'm trying to evaluate a simple expression:

Subscript[λ, n] = (2 n - 1) π/(2 L);

And then sum it up:

Sum[Subscript[λ, n], {n, 1, 3}]

The result is:

π/(2 L) + Subscript[λ, 2] + Subscript[λ, 3]

How can i get Mathematica to write the second and third term in the same way as the first?

$\endgroup$
  • $\begingroup$ Do not understand the question, but may be you wanted this? lam[n_] := (2 n - 1) Pi/(2 L); Sum[ lam[n], {n, 1, 3}] $\endgroup$ – Nasser Dec 1 '13 at 10:33
  • 1
    $\begingroup$ Yes that would work, but would it be possible to write each term separately? Like Pi/2L + 3Pi/2L + 5Pi/2L? $\endgroup$ – Sami Dec 1 '13 at 11:16
2
$\begingroup$

I believe you are trying to limit evaluation in the sum. You can use Defer to accomplish this. I Apply (@@) it to a list for partial evaluation.

Subscript[λ, n_] := Defer @@ {(2 n - 1) Pi/2 L};

Sum[Subscript[λ, n], {n, 1, 3}]
(L π)/2 + (3 L π)/2 + (5 L π)/2

Or perhaps more to your liking:

Subscript[λ, n_] := Defer @@ {(2 n - 1) Pi/Defer[2 L]};

Sum[Subscript[λ, n], {n, 1, 3}]
π/(2 L) + (3 π)/(2 L) + (5 π)/(2 L)

By the way, if you are going to use subscripts for function definitions please read Can we use letter with a subscript as a variable in Mathematica?. A number of users would tell you to avoid them for simplicity.

$\endgroup$
  • $\begingroup$ This was what I was looking for! Thanks! $\endgroup$ – Sami Dec 1 '13 at 11:48

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.