Find an non recursive function from recursive function $f(n) = f(n-1) + 3^n$ We have
$f(0) = 1 , f(1) = 4  , f(2) = 13 , f(n) = f(n-1) + 3^n$
(number of all of triangles in Sierpinski triangle)
I want to find a non recursive function.
I know the answer but I want a solution for it.

You wrote
$$f(n) = f(n-1) + 3^n\tag{1}$$
We note that $f(0) = 3^0 = 1$ and we start rewriting equation $(1)$ by substituting some $f(x)$:
$$f(n) = f(n-1) + 3^n = f(n-2) + 3^{n-1} + 3^n = f(n-3) + 3^{n-2} + 3^{n-1} + 3^n = 3^0 + 3^1 + \cdots + 3^{n-1} + 3^n$$
which is a geometric series of ratio $3$; therefore,
$$f(n) = \frac{3^{n+1} - 1}{2}$$
(assuming you are familiar with geometric series)
