extend.tst 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. % Test and demonstration of the ODESolve extension interface
  2. % F.J.Wright@Maths.QMW.ac.uk, Time-stamp: <17 July 2000>
  3. % Load odesolve before inputting this file if not using test interface:
  4. % load_package odesolve;
  5. % Hook into the general ODE solver:
  6. algebraic procedure ODESolve_Hook_Demo (ode, y, x);
  7. %% For any ODE, if the dependent variable is z then this hook
  8. %% procedure returns a solution corresponding to ODESolve failing
  9. %% to find any solution; otherwise it returns nil (nothing) and so
  10. %% is ignored.
  11. if y=z then {ode=0};
  12. % Set the hook:
  13. symbolic(ODESolve_Before_Hook := '(ODESolve_Hook_Demo));
  14. % Hook into the nonlinear ODE solver:
  15. algebraic procedure ODESolve_Non_Hook_Demo (ode, y, x, n);
  16. %% If the ODE is nontrivially nonlinear and the order is 3 then
  17. %% this hook procedure returns a solution corresponding to ODESolve
  18. %% failing to find any solution; otherwise it returns nil (nothing)
  19. %% and so is ignored.
  20. if n=3 then {ode=0};
  21. % Set the hook:
  22. symbolic(ODESolve_Before_Non_Hook := '(ODESolve_Non_Hook_Demo));
  23. % Hook into the general linear ODE solver:
  24. algebraic procedure ODESolve_Lin_Hook_Demo
  25. (odecoeffs, driver, y, x, n, m);
  26. %% If the ODE is linear and the order is 3 then this hook procedure
  27. %% returns a solution corresponding to ODESolve failing to find any
  28. %% solution; otherwise it returns nil (nothing) and so is ignored.
  29. %% (NB: Algebraic-mode lists are indexed from 1 in REDUCE!)
  30. if n=3 then
  31. {(for i := m : n sum part(odecoeffs,i+1)*df(y,x,i)) = driver};
  32. % Set the hook:
  33. symbolic(ODESolve_Before_Lin_Hook := '(ODESolve_Lin_Hook_Demo));
  34. % Test all the hooks:
  35. % The general ODE solver:
  36. odesolve(df(y,x)); % hook ignored
  37. odesolve(df(z,x)); % hook operates
  38. % The nonlinear ODE solver:
  39. odesolve(y*df(y,x,2)+1); % hook ignored
  40. odesolve(y*df(y,x,3)+1); % hook operates
  41. % The general linear ODE solver:
  42. odesolve(df(y,x,2)+1); % hook ignored
  43. odesolve(df(y,x,3)+1); % hook operates
  44. % Clear the hooks:
  45. symbolic(ODESolve_Before_Hook := nil);
  46. symbolic(ODESolve_Before_Non_Hook := nil);
  47. symbolic(ODESolve_Before_Lin_Hook := nil);
  48. end;