Define a differentiable function on $[-3, 3]$ that has an absolute maximum and minimum at $-1$ and $1$, respectively. This question(2B-6-c) appears in Unit 2 of Exercises(on Applications of Differentiation) MIT's 18.01SC. The original question only seeks a plot of such a function, which I found to be trivial. I'm interested in defining such a function explicitly. A general question I would like to be answered is:

Define a differentiable function $f$ on a given closed interval, with known absolute maximum and minimum.

In this particular case, I tried working with the elementary cubic polynomial $f(x)=\frac{x^3}{3}-x$. This polynomial has $x=\pm 1$ as local maximum and minimum. The endpoints(here, $\pm 3$) serve as the absolute maximum/minimum. In another attempt, I tried the cubic polynomial $f(x)=x(x+3)(x-3)$(which has its roots at the endpoints and 0), but the absolute maximum/minimum do not occur at $x=\pm 1$. I also worked my way around some piecewise functions, but couldn't resolve issues of continuity(which clearly blows up differentiability). How do I resolve this conundrum? I seek answers to this particular case, as well as the general case.
Edit: The identity function and absolute value functions cannot account for given absolute extrema; they are the endpoints of the interval for these functions.
 A: The differentiable function $[-3, 3] \to \mathbb{R},$ $x \mapsto -\sin(\pi x/2)$ has global maxima of value $1$ at $\{-1, 3\}$ and global minima of value $-1$ at $\{-3, 1\}.$
Interpreting the general question in the most stringent way possible (without going overboard!):
Given $a, b, c, d$ and $r, s, v, w$ such that $a < c < d < b$ and $r < v < s$ and $r < w < s,$ we wish to construct a differentiable function $f \colon [a, b] \to [r, s]$ that has a strict global maximum of value $s$ at $c,$ and a strict global minimum of value $r$ at $d,$ and additionally satisfies $f(a) = v,$ $f(b) = w,$ and $f'(a) = f'(b) = 0.$
Thus we want $f$ to increase (let us say strictly) from $v$ to $s$ on $[a, c],$ decrease (strictly) from $s$ to $r$ on $[c, d],$ and increase (strictly) from $r$ to $w$ on $[d, b].$
One solution is this spline function:
$$
f(x) =
\begin{cases}
v + (s - v)g\left(\frac{x-a}{c-a}\right) & \text{if } a \leqslant x \leqslant c, \\
s - (s - r)g\left(\frac{x-c}{d-c}\right) & \text{if } c \leqslant x \leqslant d, \\
r + (w - r)g\left(\frac{x-d}{b-d}\right) & \text{if } d \leqslant x \leqslant b,
\end{cases}
$$
where
\begin{gather*}
g(t) = 3t^2 - 2t^3, \ g'(t) = 6t(1 - t)
\ (0 \leqslant t \leqslant 1), \\
g(0) = 0, g(1) = 1, g'(0) = g'(1) = 0, \\
g'(t) > 0 \ (0 < t < 1).
\end{gather*}
A: A suitable function would be $y=xe^{\frac{-x^2}{2}}$ on $[-3,3]$.
Note that you would be able to adjust the position of the maximum and minimum to arbitrary values, say $u$ and $v$ by replacing $x$ with $\alpha(x-x_0)$ where $x_0=\frac{u+v}{2}$ and $\alpha=\frac{2}{v-u}$. 
