Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Do I have to clear all my definitions whenever I experiment with different parameter values for my model? For example, I have a simple model as follows:

h = 5

I want to do:

Table[w[t], {t, 0, 10}]

with varying h. But every time I change h, I have to clear the definitions with


Otherwise, the result for w[t] remains the same. This practice is ok with this simple model. But when the model is pretty big, it really is time-consuming. I was expecting to get a new result directly by changing h. Any helpful comments in this direction?

share|improve this question
Could you use w[t_,h_] instead of setting h afterward ? –  William Briand Mar 13 '14 at 20:20
@WilliamBriand, thanks. I can try. But my actual model is pretty big with so many parameters. So it would be impossible to put all of them into the bracket. –  ppp Mar 13 '14 at 20:31
@Kuba, thanks. I think that's what I did. You can see h gets value at the end. –  ppp Mar 13 '14 at 21:17
Enclosing things in Dynamic allow for post hoc update of variables -- though it may make it considerably slower to run. –  William Briand Mar 13 '14 at 21:26

1 Answer 1

You could just clear the DownValues you don't want.

w[t_] := w[t] = w[t - 1] + h
w[0] = 0;

Table[DownValues[w] = Drop[DownValues[w], {2, -2}]; Table[w[t], {t, 0, 3}], {h, 2, 5}]
{{0, 2, 4, 6}, {0, 3, 6, 9}, {0, 4, 8, 12}, {0, 5, 10, 15}}
share|improve this answer
Thank you so much, m_goldberg. But it seems quite complicated. In fact, I was moving over from R. With R, you just change h directly and you will have new results for w[t]. I was expecting something similar to this. It seems R is much more convenience than Mathematica for experimenting with a dynamic model with many variables and parameters. Is it true? –  ppp Mar 13 '14 at 21:47

Your Answer


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.