
Student Support Forum > General > > "b=a+1, c=b+1, d=c+1... x=?"
| Original Message (ID '198372') By jf: |
| In[2]:= y[0] = 4;
y[n_Integer?Positive] := y[n - 1] + 1;
In[4]:= y[4]
Out[4]= 8
You could probably get away with
y[n_] := y[n - 1] + 1;
for the recursive definition, but the extra will prevent an infinite recursion in case an invalid argument is given.
http://reference.wolfram.com/mathematica/tutorial/PuttingConstraintsOnPatterns.html
|
|
| | | |
 | |
|