zimmer.tst 7.5 KB

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