You need to read up on basic Mathematica syntax, and become familiar with the input/output formatting.
Also please see this
to understand how Mathematica formatting is done on this site. I showed both input and output in what is a very common and obvious manner, with the output enclosed in a Mathematica comment. How this became the above proposed input, while losing a final asterisk and thus that comment enclosure, escapes my understanding.
For the stated purposes it would be good to check Mathematica documentation on the function Piecewise
and possibly also the UnitStep
function. Either one can be used to handle the problem most recently posed.
ZTransform[UnitStep[n - 3]*n + UnitStep[2 - n], n, z]
(* Out[350]= (-1 + 2 z - z^3 + z^4)/((-1 + z)^2 z^2) *)
ZTransform[Piecewise[{{1, n < 3}}, n], n, z]
(* Out[349]= (-1 + 2 z - z^3 + z^4)/((-1 + z)^2 z^2) *)