TransWikia.com

How to keep a variable unevaluated when used as parameter for `Sum`?

Mathematica Asked on June 24, 2021

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.

One Answer

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.

Correct answer by wuyudi on June 24, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP