0
$\begingroup$

Let's say I have assigned the follow value to s by

s = Floor[Log[n]]

Then I want to compute

Sum[r^j, {j, 0, s}]

but with s as a symbol, because otherwise the result is a bit difficult to read. But replacing s by Hold[s] and HoldForm[s] both fails to achieve what I want. s is always evaluated in the output.

$\endgroup$

1 Answer 1

1
$\begingroup$

You can replace it after Sum

Sum[r^j, {j, 0, s}]

(-1 + r^(1 + s))/(-1 + r)

(-1 + r^(1 + s))/(-1 + r) /. s -> Floor[Log[n]]

(*(-1 + r^(1 + Floor[Log[n]]))/(-1 + r)*)

It's not recommend to directly use = , better in a With , or use /. instead.

$\endgroup$
1
  • $\begingroup$ Yeah, this could work. But I also want a way to remember what the value of s should be. I am not using two symbols s and s0. One used as symbol, the other as its value. Not perfect. $\endgroup$ Nov 6, 2020 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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