I need to find the amount of solutions with non negative integers to the equation $x_1 + x_2 + x_3 = n$ with $x_2 = 2x_1$.
I transformed it to $y_1 + y_2 = n$ when $y_1=3x_1, y_2 = x_3$
(because $x_1 + x_2 + x_3 = n$ here is the same as $x_1 + 2x_1 + x_3 = n$, which is $3x_1 + x_3 = n$).
Using generating functions $$[x^n] = \frac {1}{(1-x^3)(1-x)}$$ which is by expanding $1-x^3$:$$[x^n] = \frac {1}{(1-x)^2(1+x+x^2)}$$ The problem here is that that the expansion of $(1+x+x^2)$ involves complex numbers so I'm not sure how to proceed from here.
You can proceed in two ways. First, you can use the formula
$$ \frac{1}{1 - x} \sum_{n} a_n x^n = \sum_n \left( \sum_{k = 0}^n a_k \right) x^n. $$
That is, multiplication by $(1 - x)^{-1}$ gives you the partial sums of a series. The partial sums of
$$ \frac{1}{1 - x^3} = 1 + x^3 + x^6 + x^9 + \cdots $$
are given by
$$ (1 + x + x^2) + 2(x^3 + x^4 + x^5) + 3(x^6 + x^7 + x^8) + 4\cdots. $$
Which can be described as
$$ [x^n] \frac{1}{(1 - x)^2(1 + x + x^2)} = \left\lfloor \frac{n}{3} \right\rfloor + 1. $$
The second way, which is what you are trying to do, uses the fundamental property of rational generating functions (c.f. Stanley EC1 Theorem 4.1.1) which implies that
$$ [x^n] \frac{1}{(1 - x)^2(1 + x + x^2)} = (A + Bn)1^n + C\left( \cos \frac{\pi}{3} + i \sin \frac{\pi}{3} \right)^n + D \left( \cos \frac{\pi}{3} - i \sin \frac{\pi}{3} \right)^n $$
Which if you look at the first 4 coefficients give you enough information to determine (here it's helpful to use a computer rather than do this by hand)
$$ [x^n] \frac{1}{(1 - x)^2(1 + x + x^2)} = \frac{2}{3} + \frac{1}{3}n + \frac{1}{3} \cos\left(\frac{2 n \pi}{3}\right) + \frac{1}{3 \sqrt 3} \sin\left(\frac{2 n \pi}{3}\right). $$
Then, using the periodicity of sine and cosine, we see that when $n \equiv 0 \pmod 3$ we have
$$ \frac{2}{3} + \frac{1}{3}n + \frac{1}{3} = \frac{n}{3} + 1. $$
When $n \equiv 1 \pmod 3$ we have
$$ \frac{2}{3} + \frac{1}{3}n - \frac{1}{6} + \frac{1}{6} = \frac{n - 1}{3} + 1. $$
And finally, when $n \equiv 2 \pmod 3$ we have
$$ \frac{2}{3} + \frac{1}{3}n - \frac{1}{6} - \frac{1}{6} = \frac{n - 2}{3} + 1. $$
This three cases can be described together as
$$ \left\lfloor \frac{n}{3} \right\rfloor + 1. $$