Question 7
Create an R function \texttt{pwfun()}, which computes values of the piece-wise (mathematical) function \texttt{pwfun} defined in the following way:
Its graph is as follows.
$$\text{pwfun}(x) = \begin{cases} -2x - 2, & x < -1\\ 0, & -1 \le x \le 1\\ x^2 - 1, & 1 < x \end{cases}$$
Your R function \texttt{pwfun()} should also accept \texttt{x} as a vector of arbitrary length and return vector of the same length with entries defined as values of the
mathematical function \texttt{pwfun}, evaluated at the corresponding entries of vector \texttt{x}.
Here are some input vectors and what you should get as a corresponding output.
\texttt{pwfun}(-1)
0
\texttt{pwfun}(c(-2, 0.5, 3))
2 0 8
x = c(-3, -2, -1, 0, 1, 2, 3.2)
\texttt{pwfun}(x)
4 2 0 0 0 3 9.24