How to restrict the domain of a function
I think the easiest way is to use Condition
which has the operator form /;
.
f[x_ /; -1 <= x <= 1, c_] := -(x + c)^2
Then
With[{c = -1/4}, Plot[f[x, c], {x, -2, 2}]]
Amplifying on m_goldberg's answer: The Condition
can include a Message
to use when the argument is outside the allowed interval.
ClearAll[f]
f::arg = "Argument value of `1` must be in the closed interval {-1, 1}.";
f[x_, c_] /; If[TrueQ[-1 <= x <= 1], True, Message[f::arg, x]] := -(x + c)^2
Then, an argument outside the interval generates a Message
f[2, c]
The Message
can be turned Off
With[{c = -1/4}, Off[f::arg]; Plot[f[x, c], {x, -2, 2}]]