I need to find a function $f_k: \mathbb R \rightarrow \mathbb R$ which includes the parameter $k \in \mathbb R$. The local maximum point of this function changes with the parameter $k$. This point is given by $M_k = \left(k-1,\quad e^{-k}\cdot\left(k^{2}+\left(k-1\right)\right)\right)$. This has the result that all of these points lie on the curve $y= e^{-x-1} \cdot \left(x^2+3x+1\right)$.
What I have right now is $$ f_k(x) = e^{-k}\left(\left(x-k\right)^{3}-3\left(x-k\right)+k^{2}\right) $$ which is incorrect, but the maximum is at $x = k-1$ (as is given by the point $M_k$).
I have created a desmos file to show this: https://www.desmos.com/calculator/9l8ohitaxp (The black curve is where all the maximum points are on; the red graph is my incorrect $f_k$. Change $k$ with the slider to visualize all the functions $f_k$. You can see that $M_k$ deviates from the graph of $f_k$)
As I understand it, I only need to change the height of the graph of $f_k$ at $x = k-1$ such that it meets the corresponding point. I have no clue how to even approach that. Thank you in advance.
To construct a function $f:\mathbb{R}\longrightarrow \mathbb{R}$ which has a maximum at point $(x_0,y_0)$ one can simply take a parabola of the form $$f(x) = -(x-x_0)^2+y_0\,.$$
So to construct a family of functions $f_k:\mathbb{R}\longrightarrow \mathbb{R}$ whose maxima lie on the curve defined by $y = e^{-x-1}(x^2+3x+1)$, simply choose an appropriate parametrization of that curve e.g. $(k,e^{-k-1}(k^2+3k+1))$ and use above construction, yielding $$f_k(x) = -(x-k)^2+e^{-k-1}(k^2+3k+1)\,.$$ Hope that helps :)