Determine the equation of a function knowing the tangent line and points How can I resolve these problems?


*

*Find the equation of a function $f:\mathbb{R}\rightarrow\mathbb{R}$ such that it has the tangent line $y=4x+8$ at $x=-1$ and such that $f(0)=f(1)=0$.

*Find a function $h:\mathbb{R}\rightarrow [0,+\infty)$ such that it has the tangent line $y=2x$ at $x=1$.

*Find a function $g:\mathbb{R}\rightarrow (-\infty,0]$ such that, for all $k\in[-1,0]$, the equation $g(x)=k$ has infinitely many real solutions.
For (2) I thought of reasoning about the exponential function, and for (3) about the sine or cosine function (for example $-1-\sin x$, but this function is $\mathbb{R}\rightarrow [-2,0]$), but what is the reasoning in general?
 A: 1) If the tangent line at $x=-1$ is $y=4x+8$, it implies that $$f'(-1)=4, \quad f(-1)=4(-1)+8=4. $$
Combined with conditions $f(0)=f(1)=0$, if we try  a polynomial, it must have at least degree $3$ and be divisible by $x(x-1)$. So we try with
$$f(x)=x(x-1)(ax+b).$$
The condition  $\,f(-1)=4$ yields the relation $2(b-a)=4$, whence $b=a+2$, and the condition $\,f'(-1)=4$ becomes
$$4=5a-3b=-1-3a,$$
whence $a=-\dfrac53$, $\;b=\dfrac13$, and finally
$$f(x)=\frac13x(x-1)(x-5).$$
3) The function $g$ defined as 
$$g(x)=\begin{cases}
-\biggl|\sin \dfrac1x\biggr|&\text{if }\,x\ne 0,\\[1ex]
0&\text{if }\,x=0,
 \end{cases}$$
satisfies the condition.
A: 1) $f'(-1) = 4, f(0)= 0, f(1) = 0$
We have 3 variables to solve for.
For the sake of easy calculations lets assume that $f(x)$ is a polynomial.
$f(x) = ax^2 + bx + c\\
f'(x) = 2ax + b$
Now plug the values above, and we get 3 linear equations.
$-2a + b = 4\\
c = 0\\
a+b = 0$
$f(x) = -\frac {4}{3} x^2 + \frac {4}{3}x$
But we could choose a trig function if we wanted to.
$f(x) = -\frac {4}{\pi} \sin \pi x$ will work just as well.
Is surjectivity a requirement?  Usually, it is not.
If you need a surjective function.  Start with a cubic.
$f(x) = ax^3 + bx^2 + cx\\
f'(x) = 3ax^2 + 2bx + c\\
3a - 2b + c = 4\\
a+b+ c = 0\\
f(x) = 2x^3 -2x$
2) $h(x) = 2|x|$ is the simplest function I see that fits the bill.
3) A periodic function sounds like a good idea.  $g(x) = -\sin x - 1$ will work.  unless it is a requirement that your function be surjective.
you could say $g(x) = \begin{cases} \tan x &\frac {\pi}{2}<x\le \pi\\\sin x - 1 & \text {elsewhere} \end {cases}$ 
