Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am new to Mathematica. I want to do this f(x)=summation f(t), summation is over t, where 1<=t<=x-1 and mod(x+1,t+1)=1, i.e. when x+1 is divided by t+1, remainder is 1 and f(1)=1. Should i use loop or something else and how? Thanks.

share|improve this question
add comment

1 Answer

If I understand your question, you want something like:

f[1] = 1;
f[x_] := f[x] = Sum[Boole[Mod[x + 1, t + 1] == 1] f[t], {t, 1, x - 1}]

ListLinePlot[f[#] & /@ Range[1, 100], InterpolationOrder -> 0, 
 PlotRange -> {{1, 100}, All}, AxesOrigin -> {1, 0}]

enter image description here

Note the use of the :=...=... construct: this creates "memoization" of results (since the sum will repeatedly use the same values), providing a potentially huge performance boost.

share|improve this answer
    
Thanks a lot, it really works... –  suruchi Feb 8 at 18:31
    
@suruchi: Glad to help. That's an interesting function - does it have some special purpose? –  rasher Feb 9 at 3:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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