zimmerop.tst 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. % -*- REDUCE -*-
  2. % The Postel/Zimmermann (11/4/96) ODE test examples.
  3. % Equation names from Postel/Zimmermann.
  4. % This version uses Maple-style functional notation wherever possible.
  5. % on trode;
  6. on div, intstr; off allfac; % to look prettier
  7. % 1 Single equations without initial conditions
  8. % ==============================================
  9. % 1.1 Linear equations
  10. % ====================
  11. operator y;
  12. % (1) Linear Bernoulli 1
  13. odesolve((x^4-x^3)*df(y(x),x) + 2*x^4*y(x) = x^3/3 + C, y(x), x);
  14. % (2) Linear Bernoulli 2
  15. odesolve(-1/2*df(y(x),x) + y(x) = sin x, y(x), x);
  16. % (3) Linear change of variables (FJW: shifted Euler equation)
  17. odesolve(df(y(x),x,2)*(a*x+b)^2 + 4df(y(x),x)*(a*x+b)*a + 2y(x)*a^2 = 0,
  18. y(x), x);
  19. % (4) Adjoint
  20. odesolve((x^2-x)*df(y(x),x,2) + (2x^2+4x-3)*df(y(x),x) + 8x*y(x) = 1,
  21. y(x), x);
  22. % (5) Polynomial solutions
  23. % (FJW: Currently very slow, and fails anyway!)
  24. % odesolve((x^2-x)*df(y(x),x,2) + (1-2x^2)*df(y(x),x) + (4x-2)*y(x) = 0,
  25. % y(x), x);
  26. % (6) Dependent variable missing
  27. odesolve(df(y(x),x,2) + 2x*df(y(x),x) = 2x, y(x), x);
  28. % (7) Liouvillian solutions
  29. % (FJW: INTEGRATION IMPOSSIBLY SLOW WITHOUT EITHER ALGINT OR NOINT OPTION)
  30. begin scalar !*allfac; !*allfac := t; return
  31. odesolve((x^3/2-x^2)*df(y(x),x,2) + (2x^2-3x+1)*df(y(x),x) + (x-1)*y(x) = 0,
  32. y(x), x, noint);
  33. end;
  34. % WARNING: DO NOT RE-EVALUATE RESULT WITHOUT TURNING ON THE NOINT SWITCH
  35. % (8) Reduction of order
  36. % (FJW: Attempting to make explicit currently too slow.)
  37. odesolve(df(y(x),x,2) - 2x*df(y(x),x) + 2y(x) = 3, y(x), x);
  38. % (9) Integrating factors
  39. % (FJW: Currently very slow, and fails anyway!)
  40. % odesolve(sqrt(x)*df(y(x),x,2) + 2x*df(y(x),x) + 3y(x) = 0, y(x), x);
  41. % (10) Radical solution (FJW: omitted for now)
  42. % (11) Undetermined coefficients
  43. odesolve(df(y(x),x,2) - 2/x^2*y(x) = 7x^4 + 3*x^3, y(x), x);
  44. % (12) Variation of parameters
  45. odesolve(df(y(x),x,2) + y(x) = csc(x), y(x), x);
  46. % (13) Linear constant coefficients
  47. << factor exp(x); write
  48. odesolve(df(y(x),x,7) - 14df(y(x),x,6) + 80df(y(x),x,5) - 242df(y(x),x,4)
  49. + 419df(y(x),x,3) - 416df(y(x),x,2) + 220df(y(x),x) - 48y(x) = 0, y(x), x);
  50. remfac exp(x) >>;
  51. % (14) Euler
  52. odesolve(df(y(x),x,4) - 4/x^2*df(y(x),x,2) + 8/x^3*df(y(x),x) - 8/x^4*y(x) = 0,
  53. y(x), x);
  54. % (15) Exact n-th order
  55. odesolve((1+x+x^2)*df(y(x),x,3) + (3+6x)*df(y(x),x,2) + 6df(y(x),x) = 6x,
  56. y(x), x);
  57. % 1.2 Nonlinear equations
  58. % =======================
  59. % (16) Integrating factors 1
  60. odesolve(df(y(x),x) = y(x)/(y(x)*log y(x) + x), y(x), x);
  61. % (17) Integrating factors 2
  62. odesolve(2y(x)*df(y(x),x)^2 - 2x*df(y(x),x) - y(x) = 0, y(x), x);
  63. % This parametric solution is correct, cf. Zwillinger (1989) p.168 (41.10)
  64. % (except that first edition is missing the constant C)!
  65. % (18) Bernoulli 1
  66. odesolve(df(y(x),x) + y(x) = y(x)^3*sin x, y(x), x, explicit);
  67. expand_plus_or_minus ws;
  68. % (19) Bernoulli 2
  69. operator P, Q;
  70. begin scalar soln, !*exp, !*allfac; % for a neat solution
  71. on allfac;
  72. soln := odesolve(df(y(x),x) + P(x)*y(x) = Q(x)*y(x)^n, y(x), x);
  73. off allfac; return soln
  74. end;
  75. odesolve(df(y(x),x) + P(x)*y(x) = Q(x)*y(x)^(2/3), y(x), x);
  76. % (20) Clairaut 1
  77. odesolve((x^2-1)*df(y(x),x)^2 - 2x*y(x)*df(y(x),x) + y(x)^2 - 1 = 0,
  78. y(x), x, explicit);
  79. % (21) Clairaut 2
  80. operator f, g;
  81. odesolve(f(x*df(y(x),x)-y(x)) = g(df(y(x),x)), y(x), x);
  82. % (22) Equations of the form y' = f(x,y)
  83. odesolve(df(y(x),x) = (3x^2-y(x)^2-7)/(exp(y(x))+2x*y(x)+1), y(x), x);
  84. % (23) Homogeneous
  85. odesolve(df(y(x),x) = (2x^3*y(x)-y(x)^4)/(x^4-2x*y(x)^3), y(x), x);
  86. % (24) Factoring the equation
  87. odesolve(df(y(x),x)*(df(y(x),x)+y(x)) = x*(x+y(x)), y(x), x);
  88. % (25) Interchange variables
  89. % (NB: Soln in Zwillinger (1989) wrong, as is last eqn in Table 68!)
  90. odesolve(df(y(x),x) = x/(x^2*y(x)^2+y(x)^5), y(x), x);
  91. % (26) Lagrange 1
  92. odesolve(y(x) = 2x*df(y(x),x) - a*df(y(x),x)^3, y(x), x);
  93. odesolve(y(x) = 2x*df(y(x),x) - a*df(y(x),x)^3, y(x), x, implicit);
  94. % root_of quartic is VERY slow if explicit option used!
  95. % (27) Lagrange 2
  96. odesolve(y(x) = 2x*df(y(x),x) - df(y(x),x)^2, y(x), x);
  97. odesolve(y(x) = 2x*df(y(x),x) - df(y(x),x)^2, y(x), x, implicit);
  98. % (28) Riccati 1
  99. odesolve(df(y(x),x) = exp(x)*y(x)^2 - y(x) + exp(-x), y(x), x);
  100. % (29) Riccati 2
  101. << factor x; write
  102. odesolve(df(y(x),x) = y(x)^2 - x*y(x) + 1, y(x), x);
  103. remfac x >>;
  104. % (30) Separable
  105. odesolve(df(y(x),x) = (9x^8+1)/(y(x)^2+1), y(x), x);
  106. % (31) Solvable for x
  107. odesolve(y(x) = 2x*df(y(x),x) + y(x)*df(y(x),x)^2, y(x), x);
  108. odesolve(y(x) = 2x*df(y(x),x) + y(x)*df(y(x),x)^2, y(x), x, implicit);
  109. % (32) Solvable for y
  110. begin scalar !*allfac; !*allfac := t; return
  111. odesolve(x = y(x)*df(y(x),x) - x*df(y(x),x)^2, y(x), x)
  112. end;
  113. % (33) Autonomous 1
  114. odesolve(df(y(x),x,2)-df(y(x),x) = 2y(x)*df(y(x),x), y(x), x, explicit);
  115. % (34) Autonomous 2 (FJW: Slow without either algint or noint option.)
  116. odesolve(df(y(x),x,2)/y(x) - df(y(x),x)^2/y(x)^2 - 1 + 1/y(x)^3 = 0,
  117. y(x), x, noint);
  118. % (35) Differentiation method
  119. odesolve(2y(x)*df(y(x),x,2) - df(y(x),x)^2 =
  120. 1/3(df(y(x),x) - x*df(y(x),x,2))^2, y(x), x, explicit);
  121. % (36) Equidimensional in x
  122. odesolve(x*df(y(x),x,2) = 2y(x)*df(y(x),x), y(x), x, explicit);
  123. % (37) Equidimensional in y
  124. odesolve((1-x)*(y(x)*df(y(x),x,2)-df(y(x),x)^2) + x^2*y(x)^2 = 0, y(x), x);
  125. % (38) Exact second order
  126. odesolve(x*y(x)*df(y(x),x,2) + x*df(y(x),x)^2 + y(x)*df(y(x),x) = 0,
  127. y(x), x, explicit);
  128. % (39) Factoring differential operator
  129. odesolve(df(y(x),x,2)^2 - 2df(y(x),x)*df(y(x),x,2) + 2y(x)*df(y(x),x) -
  130. y(x)^2 = 0, y(x), x);
  131. % (40) Scale invariant (fails with algint option)
  132. odesolve(x^2*df(y(x),x,2) + 3x*df(y(x),x) = 1/(y(x)^3*x^4), y(x), x);
  133. % Revised scale-invariant example (hangs with algint option):
  134. ode := x^2*df(y(x),x,2) + 3x*df(y(x),x) + 2*y(x) = 1/(y(x)^3*x^4);
  135. % Choose full (explicit and expanded) solution:
  136. odesolve(ode, y(x), x, full); % or "explicit, expand"
  137. % Check it -- each solution should simplify to 0:
  138. foreach soln in ws collect
  139. trigsimp sub(soln, num(lhs ode - rhs ode));
  140. % (41) Autonomous, 3rd order
  141. odesolve((df(y(x),x)^2+1)*df(y(x),x,3) - 3df(y(x),x)*df(y(x),x,2)^2 = 0,
  142. y(x), x);
  143. % odesolve((df(y(x),x)^2+1)*df(y(x),x,3) - 3df(y(x),x)*df(y(x),x,2)^2 = 0,
  144. % y(x), x, implicit);
  145. % Implicit form is currently too messy!
  146. % (42) Autonomous, 4th order
  147. odesolve(3*df(y(x),x,2)*df(y(x),x,4) - 5df(y(x),x,3)^2 = 0, y(x), x);
  148. % 1.3 Special equations
  149. % =====================
  150. % (43) Delay
  151. odesolve(df(y(x),x) + a*y(x-1) = 0, y(x), x);
  152. % (44) Functions with several parameters
  153. odesolve(df(y(x,a),x) = a*y(x,a), y(x,a), x);
  154. % 2 Single equations with initial conditions
  155. % ===========================================
  156. % (45) Exact 4th order
  157. odesolve(df(y(x),x,4) = sin x, y(x), x,
  158. {x=0, y(x)=0, df(y(x),x)=0, df(y(x),x,2)=0, df(y(x),x,3)=0});
  159. % (46) Linear polynomial coefficients -- Bessel J0
  160. odesolve(x*df(y(x),x,2) + df(y(x),x) + 2x*y(x) = 0, y(x), x,
  161. {x=0, y(x)=1, df(y(x),x)=0});
  162. % (47) Second-degree separable
  163. soln :=
  164. odesolve(x*df(y(x),x)^2 - y(x)^2 + 1 = 0, y(x)=1, x=0, explicit);
  165. % Alternatively ...
  166. soln where e^~x => cosh x + sinh x;
  167. % but this works ONLY with `on div, intstr; off allfac;'
  168. % A better alternative is ...
  169. trigsimp(soln, hyp, combine);
  170. expand_plus_or_minus ws;
  171. % (48) Autonomous
  172. odesolve(df(y(x),x,2) + y(x)*df(y(x),x)^3 = 0, y(x), x,
  173. {x=0, y(x)=0, df(y(x),x)=2});
  174. %% Only one explicit solution satisfies the conditions:
  175. begin scalar !*trode, !*fullroots; !*fullroots := t; return
  176. odesolve(df(y(x),x,2) + y(x)*df(y(x),x)^3 = 0, y(x), x,
  177. {x=0, y(x)=0, df(y(x),x)=2}, explicit);
  178. end;
  179. % 3 Systems of equations
  180. % =======================
  181. % (49) Integrable combinations
  182. operator x, z;
  183. odesolve({df(x(t),t) = -3y(t)*z(t), df(y(t),t) = 3x(t)*z(t),
  184. df(z(t),t) = -x(t)*y(t)}, {x(t),y(t),z(t)}, t);
  185. % (50) Matrix Riccati
  186. operator a, b;
  187. odesolve({df(x(t),t) = a(t)*(y(t)^2-x(t)^2) + 2b(t)*x(t)*y(t) + 2c*x(t),
  188. df(y(t),t) = b(t)*(y(t)^2-x(t)^2) - 2a(t)*x(t)*y(t) + 2c*y(t)},
  189. {x(t),y(t)}, t);
  190. % (51) Triangular
  191. odesolve({df(x(t),t) = x(t)*(1 + cos(t)/(2+sin(t))),
  192. df(y(t),t) = x(t) - y(t)}, {x(t),y(t)}, t);
  193. % (52) Vector
  194. odesolve({df(x(t),t) = 9x(t) + 2y(t), df(y(t),t) = x(t) + 8y(t)},
  195. {x(t),y(t)}, t);
  196. % (53) Higher order
  197. odesolve({df(x(t),t) - x(t) + 2y(t) = 0,
  198. df(x(t),t,2) - 2df(y(t),t) = 2t - cos(2t)}, {x(t),y(t)}, t);
  199. % (54) Inhomogeneous system
  200. equ := {df(x(t),t) = -1/(t*(t^2+1))*x(t) + 1/(t^2*(t^2+1))*y(t) + 1/t,
  201. df(y(t),t) = -t^2/(t^2+1)*x(t) + (2t^2+1)/(t*(t^2+1))*y(t) + 1};
  202. odesolve(equ, {x(t),y(t)}, t);
  203. end;