zimopbas.rlg 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912
  1. REDUCE Development Version, Wed Sep 13 20:40:41 2000 ...
  2. ODESolve 1.065
  3. % -*- REDUCE -*-
  4. % The Postel/Zimmermann (11/4/96) ODE test examples.
  5. % Equation names from Postel/Zimmermann.
  6. % This version uses Maple-style functional notation wherever possible.
  7. % It outputs general solutions of linear ODEs in basis format.
  8. % It also checks all solutions.
  9. on odesolve_basis, odesolve_check;
  10. on div, intstr;
  11. off allfac;
  12. % to look prettier
  13. % 1 Single equations without initial conditions
  14. % ==============================================
  15. % 1.1 Linear equations
  16. % ====================
  17. operator y;
  18. % (1) Linear Bernoulli 1
  19. odesolve((x^4-x^3)*df(y(x),x) + 2*x^4*y(x) = x^3/3 + C, y(x), x);
  20. - 2*x
  21. e
  22. {{--------------},
  23. 2
  24. x - 2*x + 1
  25. 1 -2 1 1
  26. ---*c*x + ---*x - ---
  27. 2 6 4
  28. -------------------------}
  29. 2
  30. x - 2*x + 1
  31. % (2) Linear Bernoulli 2
  32. odesolve(-1/2*df(y(x),x) + y(x) = sin x, y(x), x);
  33. 2*x 2 4
  34. {{e },---*cos(x) + ---*sin(x)}
  35. 5 5
  36. % (3) Linear change of variables (FJW: shifted Euler equation)
  37. odesolve(df(y(x),x,2)*(a*x+b)^2 + 4df(y(x),x)*(a*x+b)*a + 2y(x)*a^2 = 0,
  38. y(x), x);
  39. 2
  40. a a
  41. {{----------------------,---------}}
  42. 2 2 2 a*x + b
  43. a *x + 2*a*b*x + b
  44. % (4) Adjoint
  45. odesolve((x^2-x)*df(y(x),x,2) + (2x^2+4x-3)*df(y(x),x) + 8x*y(x) = 1,
  46. y(x), x);
  47. 2 2
  48. {df(y(x),x,2)*x - df(y(x),x,2)*x + 2*df(y(x),x)*x + 4*df(y(x),x)*x
  49. - 3*df(y(x),x) + 8*y(x)*x - 1=0}
  50. % (5) Polynomial solutions
  51. % (FJW: Currently very slow, and fails anyway!)
  52. % odesolve((x^2-x)*df(y(x),x,2) + (1-2x^2)*df(y(x),x) + (4x-2)*y(x) = 0,
  53. % y(x), x);
  54. % (6) Dependent variable missing
  55. odesolve(df(y(x),x,2) + 2x*df(y(x),x) = 2x, y(x), x);
  56. 1
  57. {{---*sqrt(pi)*erf(x),1},x}
  58. 2
  59. % (7) Liouvillian solutions
  60. % (FJW: INTEGRATION IMPOSSIBLY SLOW WITHOUT EITHER ALGINT OR NOINT OPTION)
  61. begin scalar !*allfac; !*allfac := t; return
  62. odesolve((x^3/2-x^2)*df(y(x),x,2) + (2x^2-3x+1)*df(y(x),x) + (x-1)*y(x) = 0,
  63. y(x), x, algint);
  64. end;
  65. -1 1/x
  66. - 1/2 - x - 1/2 e *sqrt(x - 2)
  67. {{x *e *(x - 2) *int(--------------------------,x),
  68. 2
  69. sqrt(x)*x - 2*sqrt(x)*x
  70. -1
  71. - 1/2 - x - 1/2
  72. x *e *(x - 2) }}
  73. % NB: DO NOT RE-EVALUATE RESULT WITHOUT TURNING ON ALGINT OR NOINT SWITCH
  74. % (8) Reduction of order
  75. % (FJW: Attempting to make explicit currently too slow.)
  76. odesolve(df(y(x),x,2) - 2x*df(y(x),x) + 2y(x) = 3, y(x), x);
  77. ***** Cannot convert nonlinear combination solution to basis!
  78. {arbconst(2) + sqrt(pi)*arbconst(1)
  79. erf(i*x)
  80. *int(-----------------------------------------------------------,x)*i
  81. 2
  82. x
  83. sqrt(pi)*arbconst(1)*erf(i*x)*i*x + e *arbconst(1) - 2*x
  84. 1
  85. - 2*int(-----------------------------------------------------------,x)
  86. 2
  87. x
  88. sqrt(pi)*arbconst(1)*erf(i*x)*i*x + e *arbconst(1) - 2*x
  89. 3
  90. - log(y(x) - ---)=0}
  91. 2
  92. % (9) Integrating factors
  93. % (FJW: Currently very slow, and fails anyway!)
  94. % odesolve(sqrt(x)*df(y(x),x,2) + 2x*df(y(x),x) + 3y(x) = 0, y(x), x);
  95. % (10) Radical solution (FJW: omitted for now)
  96. % (11) Undetermined coefficients
  97. odesolve(df(y(x),x,2) - 2/x^2*y(x) = 7x^4 + 3*x^3, y(x), x);
  98. -1 2 1 6 1 5
  99. {{x ,x },---*x + ---*x }
  100. 4 6
  101. % (12) Variation of parameters
  102. odesolve(df(y(x),x,2) + y(x) = csc(x), y(x), x);
  103. {{cos(x),sin(x)}, - cos(x)*x + log(sin(x))*sin(x)}
  104. % (13) Linear constant coefficients
  105. << factor exp(x); write
  106. odesolve(df(y(x),x,7) - 14df(y(x),x,6) + 80df(y(x),x,5) - 242df(y(x),x,4)
  107. + 419df(y(x),x,3) - 416df(y(x),x,2) + 220df(y(x),x) - 48y(x) = 0, y(x), x);
  108. remfac exp(x) >>;
  109. 3*x
  110. {{e ,
  111. 4*x
  112. e ,
  113. 2*x
  114. e *x,
  115. 2*x
  116. e ,
  117. x 2
  118. e *x ,
  119. x
  120. e *x,
  121. x
  122. e }}
  123. % (14) Euler
  124. 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,
  125. y(x), x);
  126. -1 2 4
  127. {{x ,x,x ,x }}
  128. % (15) Exact n-th order
  129. odesolve((1+x+x^2)*df(y(x),x,3) + (3+6x)*df(y(x),x,2) + 6df(y(x),x) = 6x,
  130. y(x), x);
  131. 1 2
  132. ---*x
  133. 2
  134. {{------------,
  135. 2
  136. x + x + 1
  137. x
  138. ------------,
  139. 2
  140. x + x + 1
  141. 1
  142. ------------},
  143. 2
  144. x + x + 1
  145. 1 4
  146. ---*x
  147. 4
  148. ------------}
  149. 2
  150. x + x + 1
  151. % 1.2 Nonlinear equations
  152. % =======================
  153. % (16) Integrating factors 1
  154. odesolve(df(y(x),x) = y(x)/(y(x)*log y(x) + x), y(x), x);
  155. 1 2
  156. {x=arbconst(4)*y(x) + ---*log(y(x)) *y(x)}
  157. 2
  158. % (17) Integrating factors 2
  159. odesolve(2y(x)*df(y(x),x)^2 - 2x*df(y(x),x) - y(x) = 0, y(x), x);
  160. 4 2 - 1/3 - 2/3 1/3
  161. {{y(x)=2*(4*arbparam(1) - 12*arbparam(1) + 9) *arbparam(1) *2
  162. *arbconst(5)*arbparam(1),
  163. 4 2 - 1/3 - 2/3 1/3
  164. x=2*(4*arbparam(1) - 12*arbparam(1) + 9) *arbparam(1) *2
  165. 2 4 2 - 1/3
  166. *arbconst(5)*arbparam(1) - (4*arbparam(1) - 12*arbparam(1) + 9)
  167. - 2/3 1/3
  168. *arbparam(1) *2 *arbconst(5),
  169. arbparam(1)}}
  170. % This parametric solution is correct, cf. Zwillinger (1989) p.168 (41.10)
  171. % (except that first edition is missing the constant C)!
  172. % (18) Bernoulli 1
  173. odesolve(df(y(x),x) + y(x) = y(x)^3*sin x, y(x), x, explicit);
  174. {y(x)
  175. 2*x - 1/2
  176. =(5*e *arbconst(6) + 2*cos(x) + 4*sin(x)) *sqrt(5)*plus_or_minus(tag_1)}
  177. expand_plus_or_minus ws;
  178. 2*x - 1/2
  179. {y(x)=(5*e *arbconst(6) + 2*cos(x) + 4*sin(x)) *sqrt(5),
  180. 2*x - 1/2
  181. y(x)= - (5*e *arbconst(6) + 2*cos(x) + 4*sin(x)) *sqrt(5)}
  182. % (19) Bernoulli 2
  183. operator P, Q;
  184. begin scalar soln, !*exp, !*allfac; % for a neat solution
  185. on allfac;
  186. soln := odesolve(df(y(x),x) + P(x)*y(x) = Q(x)*y(x)^n, y(x), x);
  187. off allfac; return soln
  188. end;
  189. - n (n - 1)*int(p(x),x)
  190. {y(x) *y(x)= - e
  191. - int(p(x),x)*n + int(p(x),x)
  192. *((n - 1)*int(e *q(x),x) - arbconst(7))}
  193. odesolve(df(y(x),x) + P(x)*y(x) = Q(x)*y(x)^(2/3), y(x), x);
  194. 1/3 - 1/3*int(p(x),x)
  195. {y(x) =e *arbconst(8)
  196. 1 - 1/3*int(p(x),x) 1/3*int(p(x),x)
  197. + ---*e *int(e *q(x),x)}
  198. 3
  199. % (20) Clairaut 1
  200. odesolve((x^2-1)*df(y(x),x)^2 - 2x*y(x)*df(y(x),x) + y(x)^2 - 1 = 0,
  201. y(x), x, explicit);
  202. 2
  203. {y(x)=arbconst(9)*x + sqrt(arbconst(9) + 1),
  204. 2
  205. y(x)=arbconst(9)*x - sqrt(arbconst(9) + 1),
  206. 2
  207. y(x)=sqrt( - x + 1),
  208. 2
  209. y(x)= - sqrt( - x + 1)}
  210. % (21) Clairaut 2
  211. operator f, g;
  212. odesolve(f(x*df(y(x),x)-y(x)) = g(df(y(x),x)), y(x), x);
  213. {f(arbconst(10)*x - y(x)) - g(arbconst(10))=0}
  214. % (22) Equations of the form y' = f(x,y)
  215. odesolve(df(y(x),x) = (3x^2-y(x)^2-7)/(exp(y(x))+2x*y(x)+1), y(x), x);
  216. y(x) 2 3
  217. {arbconst(11) + e + y(x) *x + y(x) - x + 7*x=0}
  218. % (23) Homogeneous
  219. odesolve(df(y(x),x) = (2x^3*y(x)-y(x)^4)/(x^4-2x*y(x)^3), y(x), x);
  220. 3 3
  221. {arbconst(12)*y(x)*x + y(x) + x =0}
  222. % (24) Factoring the equation
  223. odesolve(df(y(x),x)*(df(y(x),x)+y(x)) = x*(x+y(x)), y(x), x);
  224. - x
  225. {y(x)=e *arbconst(13) - x + 1,
  226. 1 2
  227. y(x)=arbconst(14) + ---*x }
  228. 2
  229. % (25) Interchange variables
  230. % (NB: Soln in Zwillinger (1989) wrong, as is last eqn in Table 68!)
  231. odesolve(df(y(x),x) = x/(x^2*y(x)^2+y(x)^5), y(x), x);
  232. 3
  233. 2 2/3*y(x) 3 3
  234. {x =e *arbconst(15) - y(x) - ---}
  235. 2
  236. % (26) Lagrange 1
  237. odesolve(y(x) = 2x*df(y(x),x) - a*df(y(x),x)^3, y(x), x);
  238. -1 1 3
  239. {{y(x)=2*arbconst(16)*arbparam(2) + ---*arbparam(2) *a,
  240. 2
  241. -2 3 2
  242. x=arbconst(16)*arbparam(2) + ---*arbparam(2) *a,
  243. 4
  244. arbparam(2)}}
  245. odesolve(y(x) = 2x*df(y(x),x) - a*df(y(x),x)^3, y(x), x, implicit);
  246. 3 2 2 2 2
  247. {64*arbconst(17) *a + 128*arbconst(17) *a*x - 144*arbconst(17)*y(x) *a*x
  248. 4 4 2 3
  249. + 64*arbconst(17)*x + 27*y(x) *a - 16*y(x) *x =0}
  250. % root_of quartic is VERY slow if explicit option used!
  251. % (27) Lagrange 2
  252. odesolve(y(x) = 2x*df(y(x),x) - df(y(x),x)^2, y(x), x);
  253. -1 1 2
  254. {{y(x)=2*arbconst(18)*arbparam(3) + ---*arbparam(3) ,
  255. 3
  256. -2 2
  257. x=arbconst(18)*arbparam(3) + ---*arbparam(3),
  258. 3
  259. arbparam(3)}}
  260. odesolve(y(x) = 2x*df(y(x),x) - df(y(x),x)^2, y(x), x, implicit);
  261. 2 3 3
  262. { - 9*arbconst(19) + 18*arbconst(19)*y(x)*x - 12*arbconst(19)*x - 4*y(x)
  263. 2 2
  264. + 3*y(x) *x =0}
  265. % (28) Riccati 1
  266. odesolve(df(y(x),x) = exp(x)*y(x)^2 - y(x) + exp(-x), y(x), x);
  267. - x - x
  268. e *arbconst(20)*sin(x) - e *cos(x)
  269. {y(x)=------------------------------------------}
  270. arbconst(20)*cos(x) + sin(x)
  271. % (29) Riccati 2
  272. << factor x; write
  273. odesolve(df(y(x),x) = y(x)^2 - x*y(x) + 1, y(x), x);
  274. remfac x >>;
  275. 2
  276. 1/2*x
  277. 2*e *arbconst(21)
  278. {y(x)=x + ------------------------------------------------------}
  279. - 1/2
  280. sqrt(pi)*sqrt(2)*arbconst(21)*erf(2 *x*i)*i - 2
  281. % (30) Separable
  282. odesolve(df(y(x),x) = (9x^8+1)/(y(x)^2+1), y(x), x);
  283. 3 9
  284. {3*arbconst(22) + y(x) + 3*y(x) - 3*x - 3*x=0}
  285. % (31) Solvable for x
  286. odesolve(y(x) = 2x*df(y(x),x) + y(x)*df(y(x),x)^2, y(x), x);
  287. -1
  288. {{y(x)= - 2*arbconst(23)*arbparam(4) ,
  289. -2
  290. x= - arbconst(23)*arbparam(4) + arbconst(23),
  291. arbparam(4)}}
  292. odesolve(y(x) = 2x*df(y(x),x) + y(x)*df(y(x),x)^2, y(x), x, implicit);
  293. 2 2
  294. { - 4*arbconst(24) + 4*arbconst(24)*x + y(x) =0}
  295. % (32) Solvable for y
  296. begin scalar !*allfac; !*allfac := t; return
  297. odesolve(x = y(x)*df(y(x),x) - x*df(y(x),x)^2, y(x), x)
  298. end;
  299. 2
  300. - 1/2*arbparam(5) 2
  301. {{y(x)=e *arbconst(25)*(arbparam(5) + 1),
  302. 2
  303. - 1/2*arbparam(5)
  304. x=e *arbconst(25)*arbparam(5),
  305. arbparam(5)}}
  306. % (33) Autonomous 1
  307. odesolve(df(y(x),x,2)-df(y(x),x) = 2y(x)*df(y(x),x), y(x), x, explicit);
  308. {y(x)
  309. 1 arbconst(27)*arbconst(26) - arbconst(26)*x 1
  310. = - ---*arbconst(26)*tan(--------------------------------------------) - ---,
  311. 2 2 2
  312. y(x)=arbconst(28)}
  313. % (34) Autonomous 2 (FJW: Slow without either algint or noint option.)
  314. odesolve(df(y(x),x,2)/y(x) - df(y(x),x)^2/y(x)^2 - 1 + 1/y(x)^3 = 0,
  315. y(x), x, algint);
  316. {arbconst(31)*plus_or_minus(tag_4) + sqrt(3)
  317. 3 3 - 1/2
  318. *int(sqrt(y(x))*(3*arbconst(30)*y(x) + 6*log(y(x))*y(x) + 2) ,y(x))
  319. - plus_or_minus(tag_4)*x=0}
  320. % (35) Differentiation method
  321. odesolve(2y(x)*df(y(x),x,2) - df(y(x),x)^2 =
  322. 1/3(df(y(x),x) - x*df(y(x),x,2))^2, y(x), x, explicit);
  323. 2 2 2
  324. {y(x)=arbconst(33) *x + 2*sqrt(3)*arbconst(33)*arbconst(32)*x + 4*arbconst(32)
  325. ,
  326. 2 2 2
  327. y(x)=arbconst(34) *x - 2*sqrt(3)*arbconst(34)*arbconst(32)*x + 4*arbconst(32)
  328. ,
  329. y(x)=arbconst(35)}
  330. % (36) Equidimensional in x
  331. odesolve(x*df(y(x),x,2) = 2y(x)*df(y(x),x), y(x), x, explicit);
  332. 1 arbconst(37)*arbconst(36) - arbconst(36)*log(x)
  333. {y(x)= - ---*arbconst(36)*tan(-------------------------------------------------)
  334. 2 2
  335. 1
  336. - ---,
  337. 2
  338. y(x)=arbconst(38)}
  339. % (37) Equidimensional in y
  340. odesolve((1-x)*(y(x)*df(y(x),x,2)-df(y(x),x)^2) + x^2*y(x)^2 = 0, y(x), x);
  341. 3 2
  342. arbconst(40) + arbconst(39)*x + 1/6*x + 1/2*x - x x
  343. e *(x - 1)
  344. {y(x)=---------------------------------------------------------------}
  345. x - 1
  346. % (38) Exact second order
  347. odesolve(x*y(x)*df(y(x),x,2) + x*df(y(x),x)^2 + y(x)*df(y(x),x) = 0,
  348. y(x), x, explicit);
  349. {y(x)=sqrt( - arbconst(42) + log(x))*sqrt(arbconst(41))*sqrt(2),
  350. y(x)= - sqrt( - arbconst(42) + log(x))*sqrt(arbconst(41))*sqrt(2),
  351. y(x)=arbconst(43)}
  352. % (39) Factoring differential operator
  353. odesolve(df(y(x),x,2)^2 - 2df(y(x),x)*df(y(x),x,2) + 2y(x)*df(y(x),x) -
  354. y(x)^2 = 0, y(x), x);
  355. x x
  356. {y(x)=e *arbconst(45) + e *arbconst(44)*x,
  357. x - x
  358. y(x)=e *arbconst(47) + e *arbconst(46)}
  359. % (40) Scale invariant (fails with algint option)
  360. odesolve(x^2*df(y(x),x,2) + 3x*df(y(x),x) = 1/(y(x)^3*x^4), y(x), x);
  361. {2*arbconst(49)*plus_or_minus(tag_7) + log(
  362. 2 - 1/2 2 - 1/2
  363. - 2*(4*arbconst(48) + 1) *arbconst(48) + (4*arbconst(48) + 1)
  364. 2 2 4 4
  365. *sqrt( - 4*arbconst(48)*y(x) *x + y(x) *x - 1)
  366. 2 - 1/2 2 2
  367. + (4*arbconst(48) + 1) *y(x) *x ) - 2*log(x)*plus_or_minus(tag_7)=0}
  368. % Revised scale-invariant example (hangs with algint option):
  369. ode := x^2*df(y(x),x,2) + 3x*df(y(x),x) + 2*y(x) = 1/(y(x)^3*x^4);
  370. 2 -3 -4
  371. ode := df(y(x),x,2)*x + 3*df(y(x),x)*x + 2*y(x)=y(x) *x
  372. % Choose full (explicit and expanded) solution:
  373. odesolve(ode, y(x), x, full);
  374. 1
  375. {y(x)= - ---*sqrt(15*arbconst(50)
  376. 2
  377. 2 - 1/2 -1
  378. - sqrt(225*arbconst(50) - 64)*sin(2*(arbconst(51) - log(x))))*2 *x ,
  379. 1
  380. y(x)= - ---*sqrt(15*arbconst(50)
  381. 2
  382. 2 - 1/2 -1
  383. + sqrt(225*arbconst(50) - 64)*sin(2*(arbconst(51) - log(x))))*2 *x ,
  384. 1
  385. y(x)=---*sqrt(15*arbconst(50)
  386. 2
  387. 2
  388. - sqrt(225*arbconst(50) - 64)*sin(2*(arbconst(51) - log(x))))
  389. - 1/2 -1
  390. *2 *x ,
  391. 1
  392. y(x)=---*sqrt(15*arbconst(50)
  393. 2
  394. 2
  395. + sqrt(225*arbconst(50) - 64)*sin(2*(arbconst(51) - log(x))))
  396. - 1/2 -1
  397. *2 *x }
  398. % or "explicit, expand"
  399. % Check it -- each solution should simplify to 0:
  400. foreach soln in ws collect
  401. trigsimp sub(soln, num(lhs ode - rhs ode));
  402. {0,0,0,0}
  403. % (41) Autonomous, 3rd order
  404. odesolve((df(y(x),x)^2+1)*df(y(x),x,3) - 3df(y(x),x)*df(y(x),x,2)^2 = 0,
  405. y(x), x);
  406. 2 2
  407. {y(x)=arbconst(55) + sqrt(arbconst(53) *arbconst(52)
  408. 2 2 2
  409. - 2*arbconst(53)*arbconst(52) *x + 2*arbconst(53) + arbconst(52) *x - 2*x)
  410. -1
  411. *arbconst(52) *i,
  412. y(x)=arbconst(56) + i*x,
  413. y(x)=arbconst(57) - i*x,
  414. y(x)=arbconst(58) + arbconst(54)*x}
  415. % odesolve((df(y(x),x)^2+1)*df(y(x),x,3) - 3df(y(x),x)*df(y(x),x,2)^2 = 0,
  416. % y(x), x, implicit);
  417. % Implicit form is currently too messy!
  418. % (42) Autonomous, 4th order
  419. odesolve(3*df(y(x),x,2)*df(y(x),x,4) - 5df(y(x),x,3)^2 = 0, y(x), x);
  420. {y(x)=arbconst(63)*x + arbconst(62)
  421. -3
  422. - 3*sqrt(arbconst(60) - x)*sqrt(6)*arbconst(59) ,
  423. y(x)=arbconst(65)*x + arbconst(64)
  424. -3
  425. + 3*sqrt(arbconst(60) - x)*sqrt(6)*arbconst(59) ,
  426. 1 2
  427. y(x)=arbconst(67)*x + arbconst(66) + ---*arbconst(61)*x }
  428. 2
  429. % 1.3 Special equations
  430. % =====================
  431. % (43) Delay
  432. odesolve(df(y(x),x) + a*y(x-1) = 0, y(x), x);
  433. ***** Arguments of y differ -- solving delay equations is not implemented.
  434. % (44) Functions with several parameters
  435. odesolve(df(y(x,a),x) = a*y(x,a), y(x,a), x);
  436. a*x
  437. {{e }}
  438. % 2 Single equations with initial conditions
  439. % ===========================================
  440. % (45) Exact 4th order
  441. odesolve(df(y(x),x,4) = sin x, y(x), x,
  442. {x=0, y(x)=0, df(y(x),x)=0, df(y(x),x,2)=0, df(y(x),x,3)=0});
  443. 1 3
  444. {y(x)=sin(x) + ---*x - x}
  445. 6
  446. % (46) Linear polynomial coefficients -- Bessel J0
  447. odesolve(x*df(y(x),x,2) + df(y(x),x) + 2x*y(x) = 0, y(x), x,
  448. {x=0, y(x)=1, df(y(x),x)=0});
  449. {y(x)=besselj(0,sqrt(2)*x)}
  450. % (47) Second-degree separable
  451. soln :=
  452. odesolve(x*df(y(x),x)^2 - y(x)^2 + 1 = 0, y(x)=1, x=0, explicit);
  453. 1 2*sqrt(x)*plus_or_minus(tag_9)
  454. soln := {y(x)=---*e
  455. 2
  456. 1 - 2*sqrt(x)*plus_or_minus(tag_9)
  457. + ---*e }
  458. 2
  459. % Alternatively ...
  460. soln where e^~x => cosh x + sinh x;
  461. {y(x)=cosh(2*sqrt(x)*plus_or_minus(tag_9))}
  462. % but this works ONLY with `on div, intstr; off allfac;'
  463. % A better alternative is ...
  464. trigsimp(soln, hyp, combine);
  465. {y(x)=cosh(2*sqrt(x)*plus_or_minus(tag_9))}
  466. expand_plus_or_minus ws;
  467. {y(x)=cosh(2*sqrt(x))}
  468. % (48) Autonomous
  469. odesolve(df(y(x),x,2) + y(x)*df(y(x),x)^3 = 0, y(x), x,
  470. {x=0, y(x)=0, df(y(x),x)=2});
  471. 3
  472. {y(x) + 3*y(x) - 6*x=0}
  473. %% Only one explicit solution satisfies the conditions:
  474. begin scalar !*trode, !*fullroots; !*fullroots := t; return
  475. odesolve(df(y(x),x,2) + y(x)*df(y(x),x)^3 = 0, y(x), x,
  476. {x=0, y(x)=0, df(y(x),x)=2}, explicit);
  477. end;
  478. 2 1/3 2 - 1/3
  479. {y(x)=(sqrt(9*x + 1) + 3*x) - (sqrt(9*x + 1) + 3*x) }
  480. % 3 Systems of equations
  481. % =======================
  482. % (49) Integrable combinations
  483. operator x, z;
  484. odesolve({df(x(t),t) = -3y(t)*z(t), df(y(t),t) = 3x(t)*z(t),
  485. df(z(t),t) = -x(t)*y(t)}, {x(t),y(t),z(t)}, t);
  486. odesolve-system({df(x(t),t) + 3*y(t)*z(t),
  487. df(y(t),t) - 3*x(t)*z(t),
  488. df(z(t),t) + x(t)*y(t)},{x(t),y(t),z(t)},t)
  489. % (50) Matrix Riccati
  490. operator a, b;
  491. odesolve({df(x(t),t) = a(t)*(y(t)^2-x(t)^2) + 2b(t)*x(t)*y(t) + 2c*x(t),
  492. df(y(t),t) = b(t)*(y(t)^2-x(t)^2) - 2a(t)*x(t)*y(t) + 2c*y(t)},
  493. {x(t),y(t)}, t);
  494. 2 2
  495. odesolve-system({a(t)*x(t) - a(t)*y(t) - 2*b(t)*x(t)*y(t) + df(x(t),t)
  496. - 2*c*x(t),
  497. 2 2
  498. 2*a(t)*x(t)*y(t) + b(t)*x(t) - b(t)*y(t) + df(y(t),t)
  499. - 2*c*y(t)},{x(t),y(t)},t)
  500. % (51) Triangular
  501. odesolve({df(x(t),t) = x(t)*(1 + cos(t)/(2+sin(t))),
  502. df(y(t),t) = x(t) - y(t)}, {x(t),y(t)}, t);
  503. odesolve-system({( - cos(t)*x(t) + df(x(t),t)*sin(t) + 2*df(x(t),t)
  504. - sin(t)*x(t) - 2*x(t))/(sin(t) + 2),
  505. df(y(t),t) - x(t) + y(t)},{x(t),y(t)},t)
  506. % (52) Vector
  507. odesolve({df(x(t),t) = 9x(t) + 2y(t), df(y(t),t) = x(t) + 8y(t)},
  508. {x(t),y(t)}, t);
  509. odesolve-system({df(x(t),t) - 9*x(t) - 2*y(t),
  510. df(y(t),t) - x(t) - 8*y(t)},{x(t),y(t)},t)
  511. % (53) Higher order
  512. odesolve({df(x(t),t) - x(t) + 2y(t) = 0,
  513. df(x(t),t,2) - 2df(y(t),t) = 2t - cos(2t)}, {x(t),y(t)}, t);
  514. odesolve-system({df(x(t),t) - x(t) + 2*y(t),
  515. cos(2*t) + df(x(t),t,2) - 2*df(y(t),t) - 2*t},{x(t),y(t)},t)
  516. % (54) Inhomogeneous system
  517. equ := {df(x(t),t) = -1/(t*(t^2+1))*x(t) + 1/(t^2*(t^2+1))*y(t) + 1/t,
  518. df(y(t),t) = -t^2/(t^2+1)*x(t) + (2t^2+1)/(t*(t^2+1))*y(t) + 1};
  519. -1 -2 -1
  520. - x(t)*t + y(t)*t + t + t
  521. equ := {df(x(t),t)=----------------------------------,
  522. 2
  523. t + 1
  524. 2 -1 2
  525. - x(t)*t + 2*y(t)*t + y(t)*t + t + 1
  526. df(y(t),t)=-------------------------------------------}
  527. 2
  528. t + 1
  529. odesolve(equ, {x(t),y(t)}, t);
  530. 2 -1 -1 -2
  531. df(x(t),t)*t + df(x(t),t) - t + t *x(t) - t - y(t)*t
  532. odesolve-system({------------------------------------------------------------,
  533. 2
  534. t + 1
  535. 2 2 2
  536. (df(y(t),t)*t + df(y(t),t) + t *x(t) - t - 2*t*y(t)
  537. -1 2
  538. - y(t)*t - 1)/(t + 1)},{x(t),y(t)},t)
  539. end;
  540. Time for test: 23953 ms, plus GC time: 1807 ms