Aleksandra
Aleksandra

Reputation: 163

Randomly increasing sequence- Wolfram Mathematica

Good afternoon, I have a problem making recurrence table with randomly increasing sequence. I want it to return an increasing sequence with a random difference between two elements. Right now I've got:

RecurrenceTable[{a[k+1]==a[k] + RandomInteger[{0,4}], a[1]==-12},a,{k,1,5}]

But it returns me an arithmetic progression with chosen d for all k (e.g. {-12,-8,-4,0,4,8,12,16,20,24}).

Also, I will be really grateful for explaining why if I replace every k in my code with n I get:

RecurrenceTable[{4+a[n] == a[n],a[1] == -12},a,{n,1,10}]

Thank You very much for Your time!

Upvotes: 1

Views: 152

Answers (1)

Bill
Bill

Reputation: 3977

I don't believe that RecurrenceTable is what you are looking for.

Try this instead

FoldList[Plus,-12,RandomInteger[{0,4},5]]

which returns, this time,

{-12,-8,-7,-3,1,2}

and returns, this time,

{-12,-9,-5,-3,0,1}

Upvotes: 2

Related Questions