123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- REDUCE Development Version, Wed Sep 13 20:40:41 2000 ...
- ODESolve 1.065
- % Test and demonstration of the ODESolve extension interface
- % F.J.Wright@Maths.QMW.ac.uk, Time-stamp: <17 July 2000>
- % Load odesolve before inputting this file if not using test interface:
- % load_package odesolve;
- % Hook into the general ODE solver:
- algebraic procedure ODESolve_Hook_Demo (ode, y, x);
- %% For any ODE, if the dependent variable is z then this hook
- %% procedure returns a solution corresponding to ODESolve failing
- %% to find any solution; otherwise it returns nil (nothing) and so
- %% is ignored.
- if y=z then {ode=0};
- odesolve_hook_demo
- % Set the hook:
- symbolic(ODESolve_Before_Hook := '(ODESolve_Hook_Demo));
- (odesolve_hook_demo)
- % Hook into the nonlinear ODE solver:
- algebraic procedure ODESolve_Non_Hook_Demo (ode, y, x, n);
- %% If the ODE is nontrivially nonlinear and the order is 3 then
- %% this hook procedure returns a solution corresponding to ODESolve
- %% failing to find any solution; otherwise it returns nil (nothing)
- %% and so is ignored.
- if n=3 then {ode=0};
- odesolve_non_hook_demo
- % Set the hook:
- symbolic(ODESolve_Before_Non_Hook := '(ODESolve_Non_Hook_Demo));
- (odesolve_non_hook_demo)
- % Hook into the general linear ODE solver:
- algebraic procedure ODESolve_Lin_Hook_Demo
- (odecoeffs, driver, y, x, n, m);
- %% If the ODE is linear and the order is 3 then this hook procedure
- %% returns a solution corresponding to ODESolve failing to find any
- %% solution; otherwise it returns nil (nothing) and so is ignored.
- %% (NB: Algebraic-mode lists are indexed from 1 in REDUCE!)
- if n=3 then
- {(for i := m : n sum part(odecoeffs,i+1)*df(y,x,i)) = driver};
- odesolve_lin_hook_demo
- % Set the hook:
- symbolic(ODESolve_Before_Lin_Hook := '(ODESolve_Lin_Hook_Demo));
- (odesolve_lin_hook_demo)
- % Test all the hooks:
- % The general ODE solver:
- odesolve(df(y,x));
- *** Dependent var(s) assumed to be y
- *** Independent var assumed to be x
- *** depend y , x
- {y=arbconst(1)}
- % hook ignored
- odesolve(df(z,x));
- *** Dependent var(s) assumed to be z
- *** Independent var assumed to be x
- *** depend z , x
- {df(z,x)=0}
- % hook operates
- % The nonlinear ODE solver:
- odesolve(y*df(y,x,2)+1);
- *** Dependent var(s) assumed to be y
- *** Independent var assumed to be x
- {2*arbconst(3)*plus_or_minus(tag_1)
- sqrt(arbconst(2) - log(y))
- + sqrt(2)*int(----------------------------,y) - 2*plus_or_minus(tag_1)*x=0}
- arbconst(2) - log(y)
- % hook ignored
- odesolve(y*df(y,x,3)+1);
- *** Dependent var(s) assumed to be y
- *** Independent var assumed to be x
- {df(y,x,3)*y + 1=0}
- % hook operates
- % The general linear ODE solver:
- odesolve(df(y,x,2)+1);
- *** Dependent var(s) assumed to be y
- *** Independent var assumed to be x
- 2
- 2*arbconst(5) + 2*arbconst(4)*x - x
- {y=--------------------------------------}
- 2
- % hook ignored
- odesolve(df(y,x,3)+1);
- *** Dependent var(s) assumed to be y
- *** Independent var assumed to be x
- {df(y,x,3)=-1}
- % hook operates
- % Clear the hooks:
- symbolic(ODESolve_Before_Hook := nil);
- symbolic(ODESolve_Before_Non_Hook := nil);
- symbolic(ODESolve_Before_Lin_Hook := nil);
- end;
- Time for test: 690 ms, plus GC time: 109 ms
|