If you just want the function to return unevaluated for values of n
that do not meet the conditions:
ClearAll[Z];
Z[n_Integer?(-5 <= # <= 1 &)] :=
A*Exp[I*k*n] + B*Exp[-I*k*n];
Z[n_Integer?(2 <= # <= 5 &)] := T*Exp[I*k*n];
For example,
Z /@ {-6, -3., -3, 3, 3., 6}
(* {Z[-6], Z[-3.], A E^(-3 I k) + B E^(3 I k), E^(3 I k) T, Z[3.], Z[6]} *)
If you want the function to return unevaluated and an error message for values of n
that do not meet the conditions:
ClearAll[Z]
Z::argni =
"The argument `1` is not an integer in the closed interval {-5, 5}.";
Z[n_] /; If[TrueQ[Element[n, Integers] && -5 <= n <= 5],
True, Message[Z::argni, n]; False] :=
Piecewise[{{A*Exp[I*k*n] + B*Exp[-I*k*n], -5 <= n <= 1}},
T*Exp[I*k*n]];
For example,
Z /@ {-6, -3., -3, 3, 3., 6}
(* {Z[-6], Z[-3.], A E^(-3 I k) + B E^(3 I k), E^(3 I k) T, Z[3.], Z[6]} *)
If you want the function to evaluate to zero for values of n
that do not meet the conditions:
ClearAll[Z];
Z[n_] := Piecewise[{
{A*Exp[I*k*n] + B*Exp[-I*k*n], IntegerQ[n] && -5 <= n <= 1},
{T*Exp[I*k*n],
IntegerQ[n] && 2 <= n <= 5}}];
For example,
Z /@ {-6, -3., -3, 3, 3., 6}
(* {0, 0, A E^(-3 I k) + B E^(3 I k), E^(3 I k) T, 0, 0} *)
Piecewise
. $\endgroup$n = {-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5}; pw = Piecewise[{{A*E^(I*k*n) + B*E^(-I*k*n), n <= 1}, {T*E^(I*k*n), n >= 2}}]
$\endgroup$pw /@ Range[-5, 5]
$\endgroup$