There are two issues here:
Defining the function
You could use a Condition
to prevent the function from evaluating at the forbidden points:
forbiddenValues = {1, E, Pi};
forbiddenQ[x_] := Or @@ Table[x == value, {value, forbiddenValues}] // Evaluate;
f[x_] /; !forbiddenQ[x] := x^2
f /@ {1, 2, E, 4, Pi}
(* {f[1], 4, f[E], 16, f[Pi]} *)
Plotting
From @Natas's comment, use Exclusions
:
Plot[f[x], {x, 0, 5}
, Exclusions -> forbiddenValues
, ExclusionsStyle -> {None, Directive[Red, PointSize[Large]]}
]
Despite the definition above, you still need to explicitly specify the locations of the exclusions because they do not get detected automatically.
Therefore, if the only goal is to generate a plot with the exclusions, I would not bother with defining the function above. Just plot x^2
and use the appropriate exclusion options.
Exclusions
perhaps? $\endgroup$