I have to express $a_n$ in terms of $n$. How do I convert this recursive function into a non-recursive one? Is there any methodology to follow in order to do the same with any recursively defined function? Thanks.
$$a_n = \begin{cases} 0 & \text{if }n=1\\ a_{n-1}+n-1 & \text{if }n \ge 2 \end{cases} $$
So the results would be:
$$ a_1 = 0 \\ a_2 = 1 \\ a_3 = 3 \\ a_4 = 6 \\ a_5 = 10 \\ ... \\ $$
OK, with the corrected recursion formula we get:
$$a_1=0\\ a_2=0+(2-1)=0+1\\ a_3=0+(2-1)+(3-1)=0+1+2\\ a_4=0+(2-1)+(3-1)+(4-1)=0+1+2+3\\\vdots\\ a_n=\sum_{k=0}^{n-1}k=\frac{n(n-1)}{2}$$