ZTRANS.TEX 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. \documentstyle[11pt,reduce]{article}
  2. \title{{\bf $Z$-Transform Package for {\tt REDUCE}}}
  3. \author{Wolfram Koepf \\ Lisa Temme \\ email: {\tt Koepf@zib-berlin.de}}
  4. \date{April 1995 : ZIB Berlin}
  5. \begin{document}
  6. \maketitle
  7. \section{$Z$-Transform}
  8. The $Z$-Transform of a sequence $\{f_n\}$ is the discrete analogue
  9. of the Laplace Transform, and
  10. \[{\cal Z}\{f_n\} = F(z) = \sum^\infty_{n=0} f_nz^{-n}\;.\] \\
  11. This series converges in the region outside the circle
  12. $|z|=|z_0|= \limsup\limits_{n \rightarrow \infty} \sqrt[n]{|f_n|}\;.$
  13. \begin{tabbing}
  14. {\bf SYNTAX:}\ \ {\tt ztrans($f_n$, n, z)}\ \ \ \ \ \ \ \
  15. \=where $f_n$ is an expression, and $n$,$z$ \\
  16. \> are identifiers.\\
  17. \end{tabbing}
  18. \section{Inverse $Z$-Transform}
  19. The calculation of the Laurent coefficients of a regular function
  20. results in the following inverse formula for the $Z$-Transform:
  21. \\
  22. If $F(z)$ is a regular function in the region $|z|> \rho$ then
  23. $\exists$ a sequence \{$f_n$\} with ${\cal Z} \{f_n\}=F(z)$
  24. given by
  25. \[f_n = \frac{1}{2 \pi i}\oint F(z) z^{n-1} dz\]
  26. \begin{tabbing}
  27. {\bf SYNTAX:}\ \ {\tt invztrans($F(z)$, z, n)}\ \ \ \ \ \ \ \
  28. \=where $F(z)$ is an expression, \\
  29. \> and $z$,$n$ are identifiers.
  30. \end{tabbing}
  31. \section{Input for the $Z$-Transform}
  32. \begin{tabbing}
  33. This pack\=age can compute the \= $Z$-Transforms of the \=following
  34. list of $f_n$, and \\ certain combinations thereof.\\ \\
  35. \>$1$
  36. \>$e^{\alpha n}$
  37. \>$\frac{1}{(n+k)}$ \\ \\
  38. \>$\frac{1}{n!}$
  39. \>$\frac{1}{(2n)!}$
  40. \>$\frac{1}{(2n+1)!}$ \\ \\
  41. \>$\frac{\sin(\beta n)}{n!}$
  42. \>$\sin(\alpha n+\phi)$
  43. \>$e^{\alpha n} \sin(\beta n)$ \\ \\
  44. \>$\frac{\cos(\beta n)}{n!}$
  45. \>$\cos(\alpha n+\phi)$
  46. \>$e^{\alpha n} \cos(\beta n)$ \\ \\
  47. \>$\frac{\sin(\beta (n+1))}{n+1}$
  48. \>$\sinh(\alpha n+\phi)$
  49. \>$\frac{\cos(\beta (n+1))}{n+1}$ \\ \\
  50. \>$\cosh(\alpha n+\phi)$
  51. \>${n+k \choose m}$\\
  52. \end{tabbing}
  53. \begin{tabbing}
  54. \underline {{\bf Other Combinations}}\= \\ \\
  55. \underline {Linearity}
  56. \>${\cal Z} \{a f_n+b g_n \} = a{\cal Z} \{f_n\}+b{\cal Z}\{g_n\}$
  57. \\ \\
  58. \underline {Multiplication by $n$}
  59. \>${\cal Z} \{n^k \cdot f_n\} = -z \frac{d}{dz} \left({\cal Z}\{n^{k-1} \cdot f_n,n,z\} \right)$
  60. \\ \\
  61. \underline {Multiplication by $\lambda^n$}
  62. \>${\cal Z} \{\lambda^n \cdot f_n\}=F \left(\frac{z}{\lambda}\right)$
  63. \\ \\
  64. \underline {Shift Equation}
  65. \>${\cal Z} \{f_{n+k}\} =
  66. z^k \left(F(z) - \sum\limits^{k-1}_{j=0} f_j z^{-j}\right)$
  67. \\ \\
  68. \underline {Symbolic Sums}
  69. \> ${\cal Z} \left\{ \sum\limits_{k=0}^{n} f_k \right\} =
  70. \frac{z}{z-1} \cdot {\cal Z} \{f_n\}$ \\ \\
  71. \>${\cal Z} \left\{ \sum\limits_{k=p}^{n+q} f_k \right\}$
  72. \ \ \ combination of the above \\ \\
  73. where $k$,$\lambda \in$ {\bf N}$- \{0\}$; and $a$,$b$ are variables
  74. or fractions; and $p$,$q \in$ {\bf Z} or \\
  75. are functions of $n$; and $\alpha$, $\beta$ \& $\phi$ are angles
  76. in radians.
  77. \end{tabbing}
  78. \section{Input for the Inverse $Z$-Transform}
  79. \begin{tabbing}
  80. This \= package can compute the Inverse \= Z-Transforms of any
  81. rational function, \\ whose denominator can be factored over
  82. ${\bf Q}$, in addition to the following list \\ of $F(z)$.\\ \\
  83. \> $\sin \left(\frac{\sin (\beta)}{z} \ \right)
  84. e^{\left(\frac{\cos (\beta)}{z} \ \right)}$
  85. \> $\cos \left(\frac{\sin (\beta)}{z} \ \right)
  86. e^{\left(\frac{\cos (\beta)}{z} \ \right)}$ \\ \\
  87. \> $\sqrt{\frac{z}{A}} \sin \left( \sqrt{\frac{z}{A}} \ \right)$
  88. \> $\cos \left( \sqrt{\frac{z}{A}} \ \right)$ \\ \\
  89. \> $\sqrt{\frac{z}{A}} \sinh \left( \sqrt{\frac{z}{A}} \ \right)$
  90. \> $\cosh \left( \sqrt{\frac{z}{A}} \ \right)$ \\ \\
  91. \> $z \ \log \left(\frac{z}{\sqrt{z^2-A z+B}} \ \right)$
  92. \> $z \ \log \left(\frac{\sqrt{z^2+A z+B}}{z} \ \right)$ \\ \\
  93. \> $\arctan \left(\frac{\sin (\beta)}{z+\cos (\beta)} \ \right)$
  94. \\
  95. \end{tabbing}
  96. where $k$,$\lambda \in$ {\bf N}$ - \{0\}$ and $A$,$B$ are fractions
  97. or variables ($B>0$) and $\alpha$,$\beta$, \& $\phi$ are angles
  98. in radians.
  99. \section{Application of the $Z$-Transform}
  100. \underline {{\bf Solution of difference equations}}\\
  101. In the same way that a Laplace Transform can be used to
  102. solve differential equations, so $Z$-Transforms can be used
  103. to solve difference equations.\\ \\
  104. Given a linear difference equation of $k$-th order
  105. \begin{equation}
  106. f_{n+k} + a_1 f_{n+k-1}+ \ldots + a_k f_n = g_n
  107. \label{eq:1}
  108. \end{equation}
  109. with initial conditions
  110. $f_0 = h_0$, $f_1 = h_1$, $\ldots$, $f_{k-1} = h_{k-1}$ (where $h_j$
  111. are given), it is possible to solve it in the following way.
  112. If the coefficients $a_1, \ldots , a_k$ are constants, then the
  113. $Z$-Transform of (\ref{eq:1}) can be calculated using the shift
  114. equation, and results in a solvable linear equation for
  115. ${\cal Z} \{f_n\}$. Application of the Inverse $Z$-Transform
  116. then results in the solution of \ (\ref{eq:1}).\\
  117. If the coefficients $a_1, \ldots , a_k$ are polynomials in $n$ then
  118. the $Z$-Transform of (\ref{eq:1}) constitutes a differential
  119. equation for ${\cal Z} \{f_n\}$. If this differential equation can
  120. be solved then the Inverse $Z$-Transform once again yields the
  121. solution of (\ref{eq:1}).
  122. Some examples of these methods of solution can be found in
  123. $\S$\ref{sec:Examples}.
  124. \section{EXAMPLES}
  125. \label{sec:Examples}
  126. \underline {{\bf Here are some examples for the $Z$-Transform}}\\
  127. \begin{verbatim}
  128. 1: ztrans((-1)^n*n^2,n,z);
  129. z*( - z + 1)
  130. ---------------------
  131. 3 2
  132. z + 3*z + 3*z + 1
  133. 2: ztrans(cos(n*omega*t),n,z);
  134. z*(cos(omega*t) - z)
  135. ---------------------------
  136. 2
  137. 2*cos(omega*t)*z - z - 1
  138. 3: ztrans(cos(b*(n+2))/(n+2),n,z);
  139. z
  140. z*( - cos(b) + log(------------------------------)*z)
  141. 2
  142. sqrt( - 2*cos(b)*z + z + 1)
  143. 4: ztrans(n*cos(b*n)/factorial(n),n,z);
  144. cos(b)/z sin(b) sin(b)
  145. e *(cos(--------)*cos(b) - sin(--------)*sin(b))
  146. z z
  147. ---------------------------------------------------------
  148. z
  149. 5: ztrans(sum(1/factorial(k),k,0,n),n,z);
  150. 1/z
  151. e *z
  152. --------
  153. z - 1
  154. 6: operator f$
  155. 7: ztrans((1+n)^2*f(n),n,z);
  156. 2
  157. df(ztrans(f(n),n,z),z,2)*z - df(ztrans(f(n),n,z),z)*z
  158. + ztrans(f(n),n,z)
  159. \end{verbatim}
  160. \underline {{\bf Here are some examples for the Inverse $Z$-Transform}}
  161. \begin{verbatim}
  162. 8: invztrans((z^2-2*z)/(z^2-4*z+1),z,n);
  163. n n n
  164. (sqrt(3) - 2) *( - 1) + (sqrt(3) + 2)
  165. -----------------------------------------
  166. 2
  167. 9: invztrans(z/((z-a)*(z-b)),z,n);
  168. n n
  169. a - b
  170. ---------
  171. a - b
  172. 10: invztrans(z/((z-a)*(z-b)*(z-c)),z,n);
  173. n n n n n n
  174. a *b - a *c - b *a + b *c + c *a - c *b
  175. -----------------------------------------
  176. 2 2 2 2 2 2
  177. a *b - a *c - a*b + a*c + b *c - b*c
  178. 11: invztrans(z*log(z/(z-a)),z,n);
  179. n
  180. a *a
  181. -------
  182. n + 1
  183. 12: invztrans(e^(1/(a*z)),z,n);
  184. 1
  185. -----------------
  186. n
  187. a *factorial(n)
  188. 13: invztrans(z*(z-cosh(a))/(z^2-2*z*cosh(a)+1),z,n);
  189. cosh(a*n)
  190. \end{verbatim}
  191. \underline {{\bf Examples: Solutions of Difference Equations}}\\ \\
  192. \begin{tabbing}
  193. {\bf I} \ \ \ \ \ \ \=
  194. (See \cite{BS}, p.\ 651, Example 1).\\
  195. \> Consider the \= homogeneous linear difference equation\\ \\
  196. \>\> $f_{n+5} - 2 f_{n+3} + 2 f_{n+2} - 3 f_{n+1} + 2 f_{n}=0$\\ \\
  197. \> with \ initial conditions \ $f_0=0$, $f_1=0$, $f_2=9$, $f_3=-2$,
  198. $f_4=23$. \ The\\
  199. \> $Z$-Transform of the left hand side can be written as
  200. $F(z)=P(z)/Q(z)$ \\
  201. \> where \ $P(z)=9z^3-2z^2+5z$ \
  202. and \ $Q(z)=z^5-2z^3+2z^2-3z+2$ \ $=$\\
  203. \> $(z-1)^2(z+2)(z^2+1)$, \ which can be inverted to give\\ \\
  204. \>\> $f_n = 2n + (-2)^n - \cos \frac{\pi}{2}n\;.$ \\ \\
  205. \> The following REDUCE session shows how the present package can
  206. \\ \> be used to solve the above problem.
  207. \end{tabbing}
  208. \begin{verbatim}
  209. 14: operator f$ f(0):=0$ f(1):=0$ f(2):=9$ f(3):=-2$ f(4):=23$
  210. 20: equation:=ztrans(f(n+5)-2*f(n+3)+2*f(n+2)-3*f(n+1)+2*f(n),n,z);
  211. 5 3
  212. equation := ztrans(f(n),n,z)*z - 2*ztrans(f(n),n,z)*z
  213. 2
  214. + 2*ztrans(f(n),n,z)*z - 3*ztrans(f(n),n,z)*z
  215. 3 2
  216. + 2*ztrans(f(n),n,z) - 9*z + 2*z - 5*z
  217. 21: ztransresult:=solve(equation,ztrans(f(n),n,z));
  218. 2
  219. z*(9*z - 2*z + 5)
  220. ztransresult := {ztrans(f(n),n,z)=----------------------------}
  221. 5 3 2
  222. z - 2*z + 2*z - 3*z + 2
  223. 22: result:=invztrans(part(first(ztransresult),2),z,n);
  224. n n n n
  225. 2*( - 2) - i *( - 1) - i + 4*n
  226. result := -----------------------------------
  227. 2
  228. \end{verbatim}
  229. \begin{tabbing}
  230. \\ \\
  231. {\bf II} \ \ \ \ \ \ \=
  232. (See \cite{BS}, p.\ 651, Example 2).\\
  233. \> Consider the \= inhom\=ogeneous difference equation:\\ \\
  234. \>\> $f_{n+2} - 4 f_{n+1} + 3 f_{n} = 1$\\ \\
  235. \> with initial conditions $f_0=0$, $f_1=1$. Giving \\ \\
  236. \>\> $F(z)$\>$ = {\cal Z}\{1\} \left( \frac{1}{z^2-4z+3} + \frac{z}{z^2-4z+3} \right)$\\ \\
  237. \>\>\> $ = \frac{z}{z-1} \left( \frac{1}{z^2-4z+3} + \frac{z}{z^2-4z+3} \right)$.
  238. \\ \\
  239. \> The Inverse $Z$-Transform results in the solution\\ \\
  240. \>\>
  241. $f_n = \frac{1}{2} \left( \frac{3^{n+1}-1}{2}-(n+1) \right)$.\\ \\
  242. \> The following REDUCE session shows how the present package can\\
  243. \> be used to solve the above problem.
  244. \end{tabbing}
  245. \begin{verbatim}
  246. 23: clear(f)$ operator f$ f(0):=0$ f(1):=1$
  247. 27: equation:=ztrans(f(n+2)-4*f(n+1)+3*f(n)-1,n,z);
  248. 3 2
  249. equation := (ztrans(f(n),n,z)*z - 5*ztrans(f(n),n,z)*z
  250. 2
  251. + 7*ztrans(f(n),n,z)*z - 3*ztrans(f(n),n,z) - z )/(z - 1)
  252. 28: ztransresult:=solve(equation,ztrans(f(n),n,z));
  253. 2
  254. z
  255. result := {ztrans(f(n),n,z)=---------------------}
  256. 3 2
  257. z - 5*z + 7*z - 3
  258. 29: result:=invztrans(part(first(ztransresult),2),z,n);
  259. n
  260. 3*3 - 2*n - 3
  261. result := ----------------
  262. 4
  263. \end{verbatim}
  264. \begin{tabbing}
  265. \\ \\
  266. {\bf III} \ \ \ \ \ \ \=
  267. Consider the \=following difference equation, which has a
  268. differential\\
  269. \> equation for ${\cal Z}\{f_n\}$.\\ \\
  270. \>\> $(n+1) \cdot f_{n+1}-f_n=0$\\ \\
  271. \> with initial conditions $f_0=1$, $f_1=1$. It can be solved in REDUCE\\
  272. \> using the present package in the following way.\\
  273. \end{tabbing}
  274. \begin{verbatim}
  275. 30: clear(f)$ operator f$ f(0):=1$ f(1):=1$
  276. 34: equation:=ztrans((n+1)*f(n+1)-f(n),n,z);
  277. 2
  278. equation := - (df(ztrans(f(n),n,z),z)*z + ztrans(f(n),n,z))
  279. 35: operator tmp;
  280. 36: equation:=sub(ztrans(f(n),n,z)=tmp(z),equation);
  281. 2
  282. equation := - (df(tmp(z),z)*z + tmp(z))
  283. 37: load(odesolve);
  284. 38: ztransresult:=odesolve(equation,tmp(z),z);
  285. 1/z
  286. ztransresult := {tmp(z)=e *arbconst(1)}
  287. 39: preresult:=invztrans(part(first(ztransresult),2),z,n);
  288. arbconst(1)
  289. preresult := --------------
  290. factorial(n)
  291. 40: solve({sub(n=0,preresult)=f(0),sub(n=1,preresult)=f(1)},
  292. arbconst(1));
  293. {arbconst(1)=1}
  294. 41: result:=preresult where ws;
  295. 1
  296. result := --------------
  297. factorial(n)
  298. \end{verbatim}
  299. \begin{thebibliography}{9}
  300. \bibitem{BS} Bronstein, I.N. and Semedjajew, K.A.,
  301. {\it Taschenbuch der Mathematik},
  302. Verlag Harri Deutsch, Thun und Frankfurt(Main),
  303. 1981.\\ISBN 3 87144 492 8.
  304. \end{thebibliography}
  305. \end{document}