tps.rlg 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. Tue Feb 10 12:28:30 2004 run on Linux
  2. % Author: Alan Barnes <barnesa@aston.ac.uk>
  3. psexplim 8;
  4. 6
  5. % expand as far as 8th power (default is 6)
  6. cos!-series:=ps(cos x,x,0);
  7. 1 2 1 4 1 6 1 8 9
  8. cos-series := 1 - ---*x + ----*x - -----*x + -------*x + O(x )
  9. 2 24 720 40320
  10. sin!-series:=ps(sin x,x,0);
  11. 1 3 1 5 1 7 9
  12. sin-series := x - ---*x + -----*x - ------*x + O(x )
  13. 6 120 5040
  14. atan!-series:=ps(atan x,x,0);
  15. 1 3 1 5 1 7 9
  16. atan-series := x - ---*x + ---*x - ---*x + O(x )
  17. 3 5 7
  18. tan!-series:=ps(tan x,x,0);
  19. 1 3 2 5 17 7 9
  20. tan-series := x + ---*x + ----*x + -----*x + O(x )
  21. 3 15 315
  22. cos!-series*tan!-series;
  23. 1 3 1 5 1 7 9
  24. x - ---*x + -----*x - ------*x + O(x )
  25. 6 120 5040
  26. % should series for sin(x)
  27. df(cos!-series,x);
  28. 1 3 1 5 1 7 9
  29. - x + ---*x - -----*x + ------*x + O(x )
  30. 6 120 5040
  31. % series for sin(x) again
  32. cos!-series/atan!-series;
  33. -1 1 77 3 313 5 104539 7 9
  34. x - ---*x - -----*x + ------*x - ---------*x + O(x )
  35. 6 360 3024 1814400
  36. % should be expanded
  37. tmp:=ps(1/(1+x^2),x,infinity);
  38. 1 1 1 1 1
  39. tmp := ---- - ---- + ---- - ---- + O(----)
  40. 2 4 6 8 9
  41. x x x x x
  42. df(tmp,x);
  43. 1 1 1 1
  44. - 2*---- + 4*---- - 6*---- + O(----)
  45. 3 5 7 9
  46. x x x x
  47. ps(df(1/(1+x^2),x),x,infinity);
  48. 1 1 1 1
  49. - 2*---- + 4*---- - 6*---- + O(----)
  50. 3 5 7 9
  51. x x x x
  52. tmp*x;
  53. 1 1 1 1 1
  54. (---- - ---- + ---- - ---- + O(----))*x
  55. 2 4 6 8 9
  56. x x x x x
  57. % not expanded as a single power series
  58. ps(tmp*x,x,infinity);
  59. 1 1 1 1 1
  60. --- - ---- + ---- - ---- + O(----)
  61. x 3 5 7 9
  62. x x x x
  63. % now expanded
  64. ps(1/(a*x-b*x^2),x,a/b);
  65. 2 3 4
  66. 1 a -1 b b a b a 2 b a 3
  67. - ---*(x - ---) + ---- - ----*(x - ---) + ----*(x - ---) - ----*(x - ---)
  68. a b 2 3 b 4 b 5 b
  69. a a a a
  70. 5 6 7 8
  71. b a 4 b a 5 b a 6 b a 7
  72. + ----*(x - ---) - ----*(x - ---) + ----*(x - ---) - ----*(x - ---)
  73. 6 b 7 b 8 b 9 b
  74. a a a a
  75. 9
  76. b a 8 a 9
  77. + -----*(x - ---) + O((x - ---) )
  78. 10 b b
  79. a
  80. % pole at expansion point
  81. ps(cos!-series*x,x,2);
  82. 2
  83. 2*cos(2) + (cos(2) - 2*sin(2))*(x - 2) - (cos(2) + sin(2))*(x - 2)
  84. - 3*cos(2) + 2*sin(2) 3 cos(2) + 2*sin(2) 4
  85. + ------------------------*(x - 2) + -------------------*(x - 2)
  86. 6 12
  87. 5*cos(2) - 2*sin(2) 5 - cos(2) - 3*sin(2) 6
  88. + ---------------------*(x - 2) + ----------------------*(x - 2)
  89. 120 360
  90. - 7*cos(2) + 2*sin(2) 7 cos(2) + 4*sin(2) 8
  91. + ------------------------*(x - 2) + -------------------*(x - 2)
  92. 5040 20160
  93. 9
  94. + O((x - 2) )
  95. tmp:=ps(x/atan!-series,x,0);
  96. 1 2 4 4 44 6 428 8 9
  97. tmp := 1 + ---*x - ----*x + -----*x - -------*x + O(x )
  98. 3 45 945 14175
  99. tmp1:=ps(atan!-series/x,x,0);
  100. 1 2 1 4 1 6 1 8 9
  101. tmp1 := 1 - ---*x + ---*x - ---*x + ---*x + O(x )
  102. 3 5 7 9
  103. tmp*tmp1;
  104. 1
  105. % should be 1, of course
  106. cos!-sin!-series:=ps(cos sin!-series,x,0);
  107. 1 2 5 4 37 6 457 8 9
  108. cos-sin-series := 1 - ---*x + ----*x - -----*x + -------*x + O(x )
  109. 2 24 720 40320
  110. % cos(sin(x))
  111. tmp:=cos!-sin!-series^2;
  112. 2 2 4 14 6 37 8 9
  113. tmp := 1 - x + ---*x - ----*x + -----*x + O(x )
  114. 3 45 315
  115. tmp1:=ps((sin(sin!-series))^2,x,0);
  116. 2 2 4 14 6 37 8 9
  117. tmp1 := x - ---*x + ----*x - -----*x + O(x )
  118. 3 45 315
  119. tmp+tmp1;
  120. 9
  121. 1 + O(x )
  122. % sin^2 + cos^2
  123. psfunction tmp1;
  124. 2
  125. sin(sin(x))
  126. % function represented by power series tmp1
  127. tmp:=tan!-series^2;
  128. 2 2 4 17 6 62 8 9
  129. tmp := x + ---*x + ----*x + -----*x + O(x )
  130. 3 45 315
  131. psdepvar tmp;
  132. x
  133. % in case we have forgotten the dependent variable
  134. psexpansionpt tmp;
  135. 0
  136. % .... or the expansion point
  137. psterm(tmp,6);
  138. 17
  139. ----
  140. 45
  141. % select 6th term
  142. psterm(tmp,10);
  143. 1382
  144. -------
  145. 14175
  146. % select 10th term (series extended automtically)
  147. tmp1:=ps(1/(cos x)^2,x,0);
  148. 2 2 4 17 6 62 8 9
  149. tmp1 := 1 + x + ---*x + ----*x + -----*x + O(x )
  150. 3 45 315
  151. tmp1-tmp;
  152. 9
  153. 1 + O(x )
  154. % sec^2-tan^2
  155. ps(int(e^(x^2),x),x,0);
  156. 1 3 1 5 1 7 9
  157. x + ---*x + ----*x + ----*x + O(x )
  158. 3 10 42
  159. % integrator not called
  160. tmp:=ps(1/(y+x),x,0);
  161. 1 1 1 2 1 3 1 4 1 5 1 6 1 7
  162. tmp := --- - ----*x + ----*x - ----*x + ----*x - ----*x + ----*x - ----*x
  163. y 2 3 4 5 6 7 8
  164. y y y y y y y
  165. 1 8 9
  166. + ----*x + O(x )
  167. 9
  168. y
  169. ps(int(tmp,y),x,0);
  170. 1 1 2 1 3 1 4 1 5 1 6
  171. log(y) + ---*x - ------*x + ------*x - ------*x + ------*x - ------*x
  172. y 2 3 4 5 6
  173. 2*y 3*y 4*y 5*y 6*y
  174. 1 7 1 8 9
  175. + ------*x - ------*x + O(x )
  176. 7 8
  177. 7*y 8*y
  178. % integrator called on each coefficient
  179. pscompose(cos!-series,sin!-series);
  180. 1 2 5 4 37 6 457 8 9
  181. 1 - ---*x + ----*x - -----*x + -------*x + O(x )
  182. 2 24 720 40320
  183. % power series composition cos(sin(x)) again
  184. cos!-sin!-series;
  185. 1 2 5 4 37 6 457 8 9
  186. 1 - ---*x + ----*x - -----*x + -------*x + O(x )
  187. 2 24 720 40320
  188. % should be same as previous result
  189. psfunction cos!-sin!-series;
  190. cos(sin(x))
  191. tmp:=ps(log x,x,1);
  192. 1 2 1 3 1 4 1 5
  193. tmp := x - 1 - ---*(x - 1) + ---*(x - 1) - ---*(x - 1) + ---*(x - 1)
  194. 2 3 4 5
  195. 1 6 1 7 1 8 9
  196. - ---*(x - 1) + ---*(x - 1) - ---*(x - 1) + O((x - 1) )
  197. 6 7 8
  198. tmp1:=pscompose(tmp, cos!-series);
  199. 1 2 1 4 1 6 17 8 9
  200. tmp1 := - ---*x - ----*x - ----*x - ------*x + O(x )
  201. 2 12 45 2520
  202. % power series composition of log(cos(x))
  203. df(tmp1,x);
  204. 1 3 2 5 17 7 9
  205. - x - ---*x - ----*x - -----*x + O(x )
  206. 3 15 315
  207. % series for -tan x
  208. psreverse tan!-series;
  209. 1 3 1 5 1 7 9
  210. x - ---*x + ---*x - ---*x + O(x )
  211. 3 5 7
  212. % should be series for atan x
  213. atan!-series;
  214. 1 3 1 5 1 7 9
  215. x - ---*x + ---*x - ---*x + O(x )
  216. 3 5 7
  217. tmp:=ps(e^x,x,0);
  218. 1 2 1 3 1 4 1 5 1 6 1 7
  219. tmp := 1 + x + ---*x + ---*x + ----*x + -----*x + -----*x + ------*x
  220. 2 6 24 120 720 5040
  221. 1 8 9
  222. + -------*x + O(x )
  223. 40320
  224. psreverse tmp;
  225. 1 2 1 3 1 4 1 5 1 6
  226. x - 1 - ---*(x - 1) + ---*(x - 1) - ---*(x - 1) + ---*(x - 1) - ---*(x - 1)
  227. 2 3 4 5 6
  228. 1 7 1 8 9
  229. + ---*(x - 1) - ---*(x - 1) + O((x - 1) )
  230. 7 8
  231. % NB expansion of log x in powers of (x-1)
  232. pschangevar(tan!-series,y);
  233. 1 3 2 5 17 7 9
  234. y + ---*y + ----*y + -----*y + O(y )
  235. 3 15 315
  236. end;
  237. Time for test: 30 ms