rataprx.tex 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. \chapter[RATAPRX: Rational Approximations]%
  2. {RATAPRX : Rational Approximations Package}
  3. \label{RATAPRX}
  4. \typeout{{RATAPRX : Rational Approximations Package}}
  5. {\footnotesize
  6. \begin{center}
  7. Lisa Temme\\
  8. Wolfram Koepf\\
  9. Konrad-Zuse-Zentrum f\"ur Informationstechnik Berlin\\
  10. Takustra\"se 7 \\
  11. D-14195 Berlin-Dahlem, Germany \\
  12. e-mail: koepf@zib.de
  13. \end{center}
  14. }
  15. \ttindex{RATAPRX}
  16. This package provides functions to
  17. \begin{itemize}
  18. \item convert rational numbers in their periodic representation and vice versa,
  19. \item to compute continued fractions and
  20. \item to compute the Pad\'{e} approximant of a function.
  21. \end{itemize}
  22. The package can be loaded using {\tt load\_package rataprx;} it supersedes
  23. the {\tt contfr} package.
  24. \section{}
  25. \subsection{Periodic Representation}
  26. The function \f{rational2periodic(n)\ttindex{RATIONAL2PERIODIC}}
  27. converts a rational number {\tt n} in its periodic representation.
  28. For example $59/70$ is converted to $0.8\overline{428571}$. \\
  29. Depending on the print function of your \REDUCE\ system, calling the
  30. function \f{rational2periodic} might result in an expression of
  31. the form {\tt periodic(\{a,b\},\{c$_1$,...,c$_n$\})\ttindex{PERIODIC}}.
  32. {\tt a} and {\tt b} is the non-periodic part of the rational number
  33. {\tt n} and {\tt c$_1$,...,c$_n$} are the digits of the periodic part.
  34. In this case $59/70$ would result in {\tt periodic(\{8,10\},\{4,2,8,5,7,1\})}. \\
  35. The function \f{periodic2rational(periodic(\{a,b\},\{c$_1$,...,c$_n$\}))
  36. \ttindex{PERIODIC2RATIONAL}} is the
  37. inverse function and computes the rational expression for a periodic one.
  38. Note that {\tt b} is 1,-1 or a integer multiple of 10. If {\tt a} is zero,
  39. then the input number {\tt b} indicates how many places after the decimal
  40. point the period occurs.
  41. \begin{verbatim}
  42. rational2periodic(6/17);
  43. periodic({0,1},{3,5,2,9,4,1,1,7,6,4,7,0,5,8,8,2})
  44. periodic2rational(ws);
  45. 6
  46. ----
  47. 17
  48. \end{verbatim}
  49. \subsection{Continued Fractions}
  50. A continued fraction (see \cite{Baker:81a} \S 4.2) has the general form
  51. \[b_0 + \frac{a_1}{b_1 +
  52. \frac{a_2}{b_2+
  53. \frac{a_3}{b_3 + \ldots
  54. }}}
  55. \;.\]
  56. A more compact way of writing this is as
  57. \[b_0 + \frac{a_1|}{|b_1} + \frac{a_2|}{|b_2} + \frac{a_3|}{|b_3} + \ldots\,.\]
  58. \\
  59. This is represented in \REDUCE\ as
  60. \[{\tt
  61. contfrac({\mbox{\sl Rational\hspace{2mm} approximant}},
  62. \{b_0, \{a_1,b_1\}, \{a_2,b_2\},.....\}).\ttindex{CONTFRAC}
  63. }\]
  64. There are four different functions to determine the continued fractions
  65. for real numbers and functions {\tt f} in the variable {\tt var}:
  66. \begin{center}
  67. {\tt
  68. \begin{tabular}{l l}
  69. cfrac(number); & cfrac(number,length); \\
  70. cfrac(f, var); & cfrac(f, var, length);
  71. \end{tabular}} \\[1mm]
  72. \end{center}
  73. \ttindex{CFRAC}
  74. The {\tt length} argument is optional and specifies the number of
  75. ordered pairs $\{a_i,b_i\}$ to be returned. It's default value is five.
  76. \begin{verbatim}
  77. cfrac pi;
  78. 1146408
  79. contfrac(---------),
  80. 364913
  81. {3,{1,7},{1,15},{1,1},{1,292},{1,1},{1,1},{1,1},
  82. {1,2},{1,1}})
  83. \end{verbatim}
  84. \newpage
  85. \begin{verbatim}
  86. cfrac((x+2/3)^2/(6*x-5),x);
  87. 2
  88. 9*x + 12*x + 4 6*x + 13 24*x - 20
  89. contfrac(-----------------,{----------,{1,-----------}})
  90. 54*x - 45 36 9
  91. cfrac(e^x,x);
  92. 3 2
  93. x + 9*x + 36*x + 60
  94. contfrac(-----------------------,
  95. 2
  96. 3*x - 24*x + 60
  97. {1,{x,1},{ - x,2},{x,3},{ - x,2},{x,5}})
  98. \end{verbatim}
  99. \subsection{Pad\'{e} Approximation}
  100. The Pad\'{e} approximant represents a function by the ratio of two
  101. polynomials. The coefficients of the powers occuring in the polynomials
  102. are determined by the coefficients in the Taylor series
  103. expansion of the function (see \cite{Baker:81a}). Given a power series
  104. \[ f(x) = c_0 + c_1 (x-h) + c_2 (x-h)^2 \ldots \]
  105. and the degree of numerator, $n$, and of the denominator, $d$,
  106. the {\tt pade} function finds the unique coefficients
  107. $a_i,\, b_i$ in the Pad\'{e} approximant
  108. \[ \frac{a_0+a_1 x+ \cdots + a_n x^n}{b_0+b_1 x+ \cdots + b_d x^d} \; .\]
  109. The function \f{pade(f, x, h ,n ,d)\ttindex{PAD\'{E}}} takes as input the
  110. function {\tt f} in the variable {\tt x} to be approximated , where
  111. {\tt h} is the point at which the approximation is evaluated. {\tt n}
  112. and {\tt d} are the (specified) degrees of the numerator and the denominator.
  113. It returns the Pad\'{e} Approximant, ie. a rational function. \par
  114. Error Messages may occur in the following different cases:
  115. \begin{itemize}
  116. \item The Taylor series expansion for the function {\tt f} has not yet been
  117. implemented in the \REDUCE\ Taylor Package.
  118. \item A Pad\'{e} Approximant of this function does not exist.
  119. \item A Pad\'{e} Approximant of this order (ie. the specified numerator and
  120. denominator orders) does not exist. Please note, there might exist an
  121. approximant of a different order.
  122. \end{itemize}
  123. \newpage
  124. \begin{verbatim}
  125. pade(sin(x),x,0,3,3);
  126. 2
  127. x*( - 7*x + 60)
  128. ------------------
  129. 2
  130. 3*(x + 20)
  131. pade(tanh(x),x,0,5,5);
  132. 4 2
  133. x*(x + 105*x + 945)
  134. -----------------------
  135. 4 2
  136. 15*(x + 28*x + 63)
  137. pade(exp(1/x),x,0,5,5);
  138. ***** no Pade Approximation exists
  139. pade(factorial(x),x,1,3,3);
  140. ***** not yet implemented
  141. 30: pade(sin(x)/x^2,x,0,10,0);
  142. ***** Pade Approximation of this order does not exist
  143. 31: pade(sin(x)/x^2,x,0,10,2);
  144. 10 8 6 4 2
  145. - x + 110*x - 7920*x + 332640*x - 6652800*x + 39916800
  146. --------------------------------------------------------------
  147. 39916800*x
  148. \end{verbatim}