DFPART.LOG 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. REDUCE 3.6, 15-Jul-95, patched to 6 Mar 96 ...
  2. depend y,x;
  3. generic_function f(x,y);
  4. df(f(),x);
  5. df(y,x)*f (x,y) + f (x,y)
  6. y x
  7. df(f(x,y),x);
  8. df(y,x)*f (x,y) + f (x,y)
  9. y x
  10. df(f(x,x**3),x);
  11. 3 3 2
  12. f (x,x ) + 3*f (x,x )*x
  13. x y
  14. df(f(x,z**3),x);
  15. 3
  16. f (x,z )
  17. x
  18. df(a*f(x,y),x);
  19. a*(df(y,x)*f (x,y) + f (x,y))
  20. y x
  21. dfp(a*f(x,y),x);
  22. f (x,y)*a
  23. x
  24. df(f(x,y),x,2);
  25. 2
  26. df(y,x,2)*f (x,y) + df(y,x) *f (x,y) + df(y,x)*f (x,y) + df(y,x)*f (x,y)
  27. y yy xy yx
  28. + f (x,y)
  29. xx
  30. df(dfp(f(x,y),x),x);
  31. df(y,x)*f (x,y) + f (x,y)
  32. xy xx
  33. df(dfp(f(x,x**3),x),x);
  34. 3 3 2
  35. f (x,x ) + 3*f (x,x )*x
  36. xx xy
  37. % using a generic fucntion with commutative derivatives
  38. generic_function u(x,y);
  39. dfp_commute u(x,y);
  40. df(u(x,y),x,x);
  41. 2
  42. df(y,x,2)*u (x,y) + df(y,x) *u (x,y) + 2*df(y,x)*u (x,y) + u (x,y)
  43. y yy xy xx
  44. % explicitly declare 1st and second derivative commutative
  45. generic_function v(x,y);
  46. let dfp(v(~a,~b),{y,x}) => dfp(v(a,b),{x,y});
  47. df(v(),x,2);
  48. 2
  49. df(y,x,2)*v (x,y) + df(y,x) *v (x,y) + 2*df(y,x)*v (x,y) + v (x,y)
  50. y yy xy xx
  51. % substitute expressions for the arguments
  52. w:=df(f(),x,2);
  53. 2
  54. w := df(y,x,2)*f (x,y) + df(y,x) *f (x,y) + df(y,x)*f (x,y) + df(y,x)*f (x,y)
  55. y yy xy yx
  56. + f (x,y)
  57. xx
  58. sub(x=0,y=x,w);
  59. f (0,x) + f (0,x) + f (0,x) + f (0,x)
  60. xx xy yx yy
  61. % composite generic functions
  62. generic_function g(x,y);
  63. generic_function h(y,z);
  64. depend z,x;
  65. w:=df(g()*h(),x);
  66. w :=
  67. df(y,x)*g (x,y)*h() + df(y,x)*h (y,z)*g() + df(z,x)*h (y,z)*g() + g (x,y)*h()
  68. y y z x
  69. sub(y=0,w);
  70. df(z,x)*h (0,z)*g(x,0) + g (x,0)*h(0,z)
  71. z x
  72. % substituting g*h for f in a partial derivative of f,
  73. % inheriting the arguments of f. Here no derivative of h
  74. % appears because h does not depend of x.
  75. sub(f=g*h,dfp(f(a,b),x));
  76. g (a,b)*h(b,z)
  77. x
  78. % indexes.
  79. % in the following total differential the partial
  80. % derivatives wrt i and j do not appear because i and
  81. % j do not depend of x.
  82. generic_function m(i,j,x,y);
  83. df(m(i,j,x,y),x);
  84. df(y,x)*m (i,j,x,y) + m (i,j,x,y)
  85. y x
  86. % computation with a differential equation.
  87. generic_function f(x,y);
  88. operator y;
  89. let df(y(~x),x) => f(x,y(x));
  90. % some derivatives
  91. df(y(x),x);
  92. f(x,y(x))
  93. df(y(x),x,2);
  94. f (x,y(x)) + f (x,y(x))*f(x,y(x))
  95. x y
  96. df(y(x),x,3);
  97. f (x,y(x)) + f (x,y(x))*f(x,y(x)) + f (x,y(x))*f (x,y(x))
  98. xx xy x y
  99. 2 2
  100. + f (x,y(x))*f(x,y(x)) + f (x,y(x))*f(x,y(x)) + f (x,y(x)) *f(x,y(x))
  101. yx yy y
  102. sub(x=22,ws);
  103. f (22,y(22)) + f (22,y(22))*f(22,y(22)) + f (22,y(22))*f (22,y(22))
  104. xx xy x y
  105. 2
  106. + f (22,y(22))*f(22,y(22)) + f (22,y(22))*f(22,y(22))
  107. yx yy
  108. 2
  109. + f (22,y(22)) *f(22,y(22))
  110. y
  111. % taylor expansion for y
  112. load_package taylor;
  113. taylor(y(x0+h),h,0,3);
  114. f (x0,y(x0)) + f (x0,y(x0))*f(x0,y(x0))
  115. x y 2
  116. y(x0) + f(x0,y(x0))*h + -----------------------------------------*h + (
  117. 2
  118. f (x0,y(x0)) + f (x0,y(x0))*f(x0,y(x0)) + f (x0,y(x0))*f (x0,y(x0))
  119. xx xy x y
  120. 2
  121. + f (x0,y(x0))*f(x0,y(x0)) + f (x0,y(x0))*f(x0,y(x0))
  122. yx yy
  123. 2 3 4
  124. + f (x0,y(x0)) *f(x0,y(x0)))/6*h + O(h )
  125. y
  126. clear w;
  127. %------------------------ Runge Kutta -------------------------
  128. % computing Runge Kutta formulas for ODE systems Y'=F(x,y(x));
  129. % forms corresponding to Ralston Rabinowitz
  130. load_package taylor;
  131. operator alpha,beta,w,k;
  132. % s= order of Runge Kutta formula
  133. s:=3;
  134. s := 3
  135. generic_function f(x,y);
  136. operator y;
  137. *** y already defined as operator
  138. % introduce ODE
  139. let df(y(~x),x)=>f(x,y(x));
  140. % formal series for solution
  141. y1_form := taylor(y(x0+h),h,0,s);
  142. f (x0,y(x0)) + f (x0,y(x0))*f(x0,y(x0))
  143. x y 2
  144. y1_form := y(x0) + f(x0,y(x0))*h + -----------------------------------------*h
  145. 2
  146. + (f (x0,y(x0)) + f (x0,y(x0))*f(x0,y(x0))
  147. xx xy
  148. + f (x0,y(x0))*f (x0,y(x0)) + f (x0,y(x0))*f(x0,y(x0))
  149. x y yx
  150. 2 2 3
  151. + f (x0,y(x0))*f(x0,y(x0)) + f (x0,y(x0)) *f(x0,y(x0)))/6*h
  152. yy y
  153. 4
  154. + O(h )
  155. % Runge-Kutta Ansatz:
  156. let alpha(1)=>0;
  157. for i:=1:s do
  158. let k(i) => h*f(x0 + alpha(i)*h,
  159. y(x0) + for j:=1:(i-1) sum beta(i,j)*k(j));
  160. y1_ansatz:= y(x0) + for i:=1:s sum w(i)*k(i);
  161. y1_ansatz := f(alpha(3)*h + x0,
  162. beta(3,2)*f(alpha(2)*h + x0,beta(2,1)*f(x0,y(x0))*h + y(x0))*h
  163. + beta(3,1)*f(x0,y(x0))*h + y(x0))*w(3)*h
  164. + f(alpha(2)*h + x0,beta(2,1)*f(x0,y(x0))*h + y(x0))*w(2)*h
  165. + f(x0,y(x0))*w(1)*h + y(x0)
  166. y1_ansatz := taylor(y1_ansatz,h,0,s);
  167. y1_ansatz := y(x0) + f(x0,y(x0))*(w(3) + w(2) + w(1))*h + (
  168. alpha(3)*f (x0,y(x0))*w(3) + alpha(2)*f (x0,y(x0))*w(2)
  169. x x
  170. + beta(3,2)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  171. y
  172. + beta(3,1)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  173. y
  174. 2
  175. + beta(2,1)*f (x0,y(x0))*f(x0,y(x0))*w(2))*h + (
  176. y
  177. 2
  178. alpha(3) *f (x0,y(x0))*w(3)
  179. xx
  180. + alpha(3)*beta(3,2)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  181. xy
  182. + alpha(3)*beta(3,2)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  183. yx
  184. + alpha(3)*beta(3,1)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  185. xy
  186. + alpha(3)*beta(3,1)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  187. yx
  188. 2
  189. + alpha(2) *f (x0,y(x0))*w(2)
  190. xx
  191. + 2*alpha(2)*beta(3,2)*f (x0,y(x0))*f (x0,y(x0))*w(3)
  192. x y
  193. + alpha(2)*beta(2,1)*f (x0,y(x0))*f(x0,y(x0))*w(2)
  194. xy
  195. + alpha(2)*beta(2,1)*f (x0,y(x0))*f(x0,y(x0))*w(2)
  196. yx
  197. 2 2
  198. + beta(3,2) *f (x0,y(x0))*f(x0,y(x0)) *w(3)
  199. yy
  200. 2
  201. + 2*beta(3,2)*beta(3,1)*f (x0,y(x0))*f(x0,y(x0)) *w(3)
  202. yy
  203. 2
  204. + 2*beta(3,2)*beta(2,1)*f (x0,y(x0)) *f(x0,y(x0))*w(3)
  205. y
  206. 2 2
  207. + beta(3,1) *f (x0,y(x0))*f(x0,y(x0)) *w(3)
  208. yy
  209. 2 2 3 4
  210. + beta(2,1) *f (x0,y(x0))*f(x0,y(x0)) *w(2))/2*h + O(h )
  211. yy
  212. % compute y1_form - y1_ans and collect coeffients of powers of h
  213. y1_diff := num(taylortostandard(y1_ansatz)-taylortostandard(y1_form))$
  214. cl := coeff(y1_diff,h);
  215. cl := {0,
  216. 6*f(x0,y(x0))*(w(3) + w(2) + w(1) - 1),
  217. 3*(2*alpha(3)*f (x0,y(x0))*w(3) + 2*alpha(2)*f (x0,y(x0))*w(2)
  218. x x
  219. + 2*beta(3,2)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  220. y
  221. + 2*beta(3,1)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  222. y
  223. + 2*beta(2,1)*f (x0,y(x0))*f(x0,y(x0))*w(2) - f (x0,y(x0))
  224. y x
  225. - f (x0,y(x0))*f(x0,y(x0))),
  226. y
  227. 2
  228. 3*alpha(3) *f (x0,y(x0))*w(3)
  229. xx
  230. + 3*alpha(3)*beta(3,2)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  231. xy
  232. + 3*alpha(3)*beta(3,2)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  233. yx
  234. + 3*alpha(3)*beta(3,1)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  235. xy
  236. + 3*alpha(3)*beta(3,1)*f (x0,y(x0))*f(x0,y(x0))*w(3)
  237. yx
  238. 2
  239. + 3*alpha(2) *f (x0,y(x0))*w(2)
  240. xx
  241. + 6*alpha(2)*beta(3,2)*f (x0,y(x0))*f (x0,y(x0))*w(3)
  242. x y
  243. + 3*alpha(2)*beta(2,1)*f (x0,y(x0))*f(x0,y(x0))*w(2)
  244. xy
  245. + 3*alpha(2)*beta(2,1)*f (x0,y(x0))*f(x0,y(x0))*w(2)
  246. yx
  247. 2 2
  248. + 3*beta(3,2) *f (x0,y(x0))*f(x0,y(x0)) *w(3)
  249. yy
  250. 2
  251. + 6*beta(3,2)*beta(3,1)*f (x0,y(x0))*f(x0,y(x0)) *w(3)
  252. yy
  253. 2
  254. + 6*beta(3,2)*beta(2,1)*f (x0,y(x0)) *f(x0,y(x0))*w(3)
  255. y
  256. 2 2
  257. + 3*beta(3,1) *f (x0,y(x0))*f(x0,y(x0)) *w(3)
  258. yy
  259. 2 2
  260. + 3*beta(2,1) *f (x0,y(x0))*f(x0,y(x0)) *w(2) - f (x0,y(x0))
  261. yy xx
  262. - f (x0,y(x0))*f(x0,y(x0)) - f (x0,y(x0))*f (x0,y(x0))
  263. xy x y
  264. 2
  265. - f (x0,y(x0))*f(x0,y(x0)) - f (x0,y(x0))*f(x0,y(x0))
  266. yx yy
  267. 2
  268. - f (x0,y(x0)) *f(x0,y(x0))}
  269. y
  270. % f_forms: forms of f and its derivatives which occur in cl
  271. f_forms :=q := {f(x0,y(x0))}$
  272. for i:=1:(s-1) do
  273. <<q:= for each r in q join {dfp(r,x),dfp(r,y)};
  274. f_forms := append(f_forms,q);
  275. >>;
  276. f_forms;
  277. {f(x0,y(x0)),
  278. f (x0,y(x0)),
  279. x
  280. f (x0,y(x0)),
  281. y
  282. f (x0,y(x0)),
  283. xx
  284. f (x0,y(x0)),
  285. xy
  286. f (x0,y(x0)),
  287. yx
  288. f (x0,y(x0))}
  289. yy
  290. % extract coefficients of the f_forms in cl
  291. sys := cl$
  292. for each fr in f_forms do
  293. sys:=for each c in sys join coeff(c,fr);
  294. % and eliminate zeros
  295. sys := for each c in sys join if c neq 0 then {c} else {};
  296. sys := {6*(w(3) + w(2) + w(1) - 1),
  297. 3*(2*alpha(3)*w(3) + 2*alpha(2)*w(2) - 1),
  298. 3*(2*beta(3,2)*w(3) + 2*beta(3,1)*w(3) + 2*beta(2,1)*w(2) - 1),
  299. 2 2
  300. 3*alpha(3) *w(3) + 3*alpha(2) *w(2) - 1,
  301. 6*alpha(2)*beta(3,2)*w(3) - 1,
  302. 3*alpha(3)*beta(3,2)*w(3) + 3*alpha(3)*beta(3,1)*w(3)
  303. + 3*alpha(2)*beta(2,1)*w(2) - 1,
  304. 3*alpha(3)*beta(3,2)*w(3) + 3*alpha(3)*beta(3,1)*w(3)
  305. + 3*alpha(2)*beta(2,1)*w(2) - 1,
  306. 6*beta(3,2)*beta(2,1)*w(3) - 1,
  307. 2 2
  308. 3*beta(3,2) *w(3) + 6*beta(3,2)*beta(3,1)*w(3) + 3*beta(3,1) *w(3)
  309. 2
  310. + 3*beta(2,1) *w(2) - 1}
  311. end;
  312. (TIME: dfpart 2390 2580)