Doubt in derivative problem I'm in trouble with the following problem:
Give $f(x) = x^3 - 3x + 1$ and $g(x) = x^3 + ax^2 + b$, determine the values of $a$ and $b$ in such a way that both $f(x)$ and $g(x)$ have the same relative maximum and minimum.
I already know that the relative maximum and minimum can be found though the roots of the derivative, so $f'(x) = 3x^2 - 3$ and $g'(x) = 3x^2 + 2ax$. As the roots of $f'(x)$ are both ${-1, 1}$, I imagined to build a system of equations to find $a$ and $b$, but I always end in two 'dummy' equations, do someone know a different way to solve this ?
By the way, the dummy equations are when I substitute ${-1, 1}$ in $g(x)$. The equations are $a + b = 4$ and $a + b = -2$

As the comments have pointed out, we must match up the function values at the relative min and max (which, in this case, do not have the same $x$-values).
Since $f'=0$ has $x=\pm1$ as roots, we substitute these critical points into $f$ to obtain $f(-1)=-1+3+1=3$ and $f(1)=1-3+1=-1$. You can verify for yourself that these really are local extrema.
Setting $g'=0$ yields $0=3x^2+2ax=x(3x+2a) \implies x=0,-2a/3$. Substitutng these critical points into $g$ yields $g(0) = 0+0+b=b$ and $g(-2a/3) = -8a^3/27 + 4a^3/9 + b = 4a^3/27 + b$.
For these two function values for $g$, it is a bit difficult to see how they should be matched up with our two function values for $f$, since we can't really tell which one is bigger (since we don't know if $a,b$ are positive or negative). So let's guess.
Case 1: Suppose the local minimum is $f(1)=-1=b=g(0)$. Then the local maximum is $f(-1)=3=4a^3/27 + b=g(-2a/3)$. Substituting $b$ and solving for $a$ yields:
\begin{align*}
\dfrac{4a^3}{27} - 1 &= 3 \\
\dfrac{4a^3}{27} &= 4 \\
\dfrac{a^3}{27} &= 1\\
a^3 &= 27\\
a &= 3\\
\end{align*}
So one possible solution is $a=3, b=-1$. Verify for yourself that $g(0)=-1$ and $g(-2)=3$ really are the local extrema of $g$.
Case 2: Suppose the local minimum is $f(1)=-1=4a^3/27 + b=g(-2a/3)$. Then...?
