zimopbas.tst 8.7 KB

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