extend.rlg 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. REDUCE Development Version, Wed Sep 13 20:40:41 2000 ...
  2. ODESolve 1.065
  3. % Test and demonstration of the ODESolve extension interface
  4. % F.J.Wright@Maths.QMW.ac.uk, Time-stamp: <17 July 2000>
  5. % Load odesolve before inputting this file if not using test interface:
  6. % load_package odesolve;
  7. % Hook into the general ODE solver:
  8. algebraic procedure ODESolve_Hook_Demo (ode, y, x);
  9. %% For any ODE, if the dependent variable is z then this hook
  10. %% procedure returns a solution corresponding to ODESolve failing
  11. %% to find any solution; otherwise it returns nil (nothing) and so
  12. %% is ignored.
  13. if y=z then {ode=0};
  14. odesolve_hook_demo
  15. % Set the hook:
  16. symbolic(ODESolve_Before_Hook := '(ODESolve_Hook_Demo));
  17. (odesolve_hook_demo)
  18. % Hook into the nonlinear ODE solver:
  19. algebraic procedure ODESolve_Non_Hook_Demo (ode, y, x, n);
  20. %% If the ODE is nontrivially nonlinear and the order is 3 then
  21. %% this hook procedure returns a solution corresponding to ODESolve
  22. %% failing to find any solution; otherwise it returns nil (nothing)
  23. %% and so is ignored.
  24. if n=3 then {ode=0};
  25. odesolve_non_hook_demo
  26. % Set the hook:
  27. symbolic(ODESolve_Before_Non_Hook := '(ODESolve_Non_Hook_Demo));
  28. (odesolve_non_hook_demo)
  29. % Hook into the general linear ODE solver:
  30. algebraic procedure ODESolve_Lin_Hook_Demo
  31. (odecoeffs, driver, y, x, n, m);
  32. %% If the ODE is linear and the order is 3 then this hook procedure
  33. %% returns a solution corresponding to ODESolve failing to find any
  34. %% solution; otherwise it returns nil (nothing) and so is ignored.
  35. %% (NB: Algebraic-mode lists are indexed from 1 in REDUCE!)
  36. if n=3 then
  37. {(for i := m : n sum part(odecoeffs,i+1)*df(y,x,i)) = driver};
  38. odesolve_lin_hook_demo
  39. % Set the hook:
  40. symbolic(ODESolve_Before_Lin_Hook := '(ODESolve_Lin_Hook_Demo));
  41. (odesolve_lin_hook_demo)
  42. % Test all the hooks:
  43. % The general ODE solver:
  44. odesolve(df(y,x));
  45. *** Dependent var(s) assumed to be y
  46. *** Independent var assumed to be x
  47. *** depend y , x
  48. {y=arbconst(1)}
  49. % hook ignored
  50. odesolve(df(z,x));
  51. *** Dependent var(s) assumed to be z
  52. *** Independent var assumed to be x
  53. *** depend z , x
  54. {df(z,x)=0}
  55. % hook operates
  56. % The nonlinear ODE solver:
  57. odesolve(y*df(y,x,2)+1);
  58. *** Dependent var(s) assumed to be y
  59. *** Independent var assumed to be x
  60. {2*arbconst(3)*plus_or_minus(tag_1)
  61. sqrt(arbconst(2) - log(y))
  62. + sqrt(2)*int(----------------------------,y) - 2*plus_or_minus(tag_1)*x=0}
  63. arbconst(2) - log(y)
  64. % hook ignored
  65. odesolve(y*df(y,x,3)+1);
  66. *** Dependent var(s) assumed to be y
  67. *** Independent var assumed to be x
  68. {df(y,x,3)*y + 1=0}
  69. % hook operates
  70. % The general linear ODE solver:
  71. odesolve(df(y,x,2)+1);
  72. *** Dependent var(s) assumed to be y
  73. *** Independent var assumed to be x
  74. 2
  75. 2*arbconst(5) + 2*arbconst(4)*x - x
  76. {y=--------------------------------------}
  77. 2
  78. % hook ignored
  79. odesolve(df(y,x,3)+1);
  80. *** Dependent var(s) assumed to be y
  81. *** Independent var assumed to be x
  82. {df(y,x,3)=-1}
  83. % hook operates
  84. % Clear the hooks:
  85. symbolic(ODESolve_Before_Hook := nil);
  86. symbolic(ODESolve_Before_Non_Hook := nil);
  87. symbolic(ODESolve_Before_Lin_Hook := nil);
  88. end;
  89. Time for test: 690 ms, plus GC time: 109 ms