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.

How can I go about setting up a recurrence relation where the first 10 values are a constant and the second 10 values are another constant?

Ideally, I'd like an efficient way to set

a[1] = 200
a[2] = 200
a[3] = 200
a[4] = 100
a[5] = 100

And so on, without having to type each term out explicitly.

share|improve this question

closed as unclear what you're asking by Szabolcs, m_goldberg, bobthechemist, rasher, belisarius Mar 14 '14 at 3:39

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

This question is not formulated very clearly so it is at risk of being closed. I recommend you rephrase it to make sure people understand what you're looking for, preferably by including a simple example. –  Szabolcs Mar 13 '14 at 15:43
Like this? Do[a[i]=100,{i,1,5}]; Do[a[i]=200, {i,6,10}] –  Szabolcs Mar 14 '14 at 0:35

3 Answers 3

Do you mean this?

In[85]:= Clear[f]
Out[87]= {1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2}
share|improve this answer

asked to use recurrance...

share|improve this answer

Here's a general approach using Map (represented by /@)

(a[#] = 1) & /@ Range[1, 5];
(a[#] = 2) & /@ Range[6, 10];

So now, for instance, a[2]=1 and a[7]=2.

share|improve this answer

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