1% Tests and demonstrations for the ODESolve 1+ package -- 2% an updated version of the original odesolve test file. 3 4% Original Author: M. A. H. MacCallum 5% Maintainer: F.J.Wright@Maths.QMW.ac.uk 6 7ODESolve_version; 8on trode, combinelogs; 9 10%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 11 12% First-order differential equations 13% (using automatic variable and dependence declaration). 14 15% First-order quadrature case: 16odesolve(df(y,x) - x^2 - e^x); 17 18% First-order linear equation, with initial condition y = 1 at x = 0: 19odesolve(df(y,x) + y * tan x - sec x, y, x, {x=0, y=1}); 20odesolve(cos x * df(y,x) + y * sin x - 1, y, x, {x=0, y=1}); 21 22% A simple separable case: 23odesolve(df(y,x) - y^2, y, x, explicit); 24 25% A separable case, in different variables, with the initial condition 26% z = 2 at w = 1/2: 27odesolve((1-z^2)*w*df(z,w)+(1+w^2)*z, z, w, {w=1/2, z=2}); 28 29% Now a homogeneous one: 30odesolve(df(y,x) - (x-y)/(x+y), y, x); 31 32% Reducible to homogeneous: 33% (Note this is the previous example with origin shifted.) 34odesolve(df(y,x) - (x-y-3)/(x+y-1), y, x); 35 36% and the special case of reducible to homogeneous: 37odesolve(df(y,x) - (2x+3y+1)/(4x+6y+1), y, x); 38 39% A Bernoulli equation: 40odesolve(x*(1-x^2)*df(y,x) + (2x^2 -1)*y - x^3*y^3, y, x); 41 42% and finally, in this set, an exact case: 43odesolve((2x^3 - 6x*y + 6x*y^2) + (-3x^2 + 6x^2*y - y^3)*df(y,x), y, x); 44 45%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 46 47% Now for higher-order linear equations with constant coefficients 48 49% First, examples without driving terms 50% A simple one to start: 51odesolve(6df(y,x,2) + df(y,x) - 2y, y, x); 52 53% An example with repeated and complex roots: 54odesolve(ode := df(y,x,4) + 2df(y,x,2) + y, y, x); 55 56% A simple right-hand-side using the above example: 57odesolve(ode = exp(x), y, x); 58 59ode := df(y,x,2) + 4df(y,x) + 4y - x*exp(x); 60% At x=1 let y=0 and df(y,x)=1: 61odesolve(ode, y, x, {x=1, y=0, df(y,x)=1}); 62 63% For simultaneous equations you can use the machine, e.g. as follows: 64 65depend z,x; 66ode1 := df(y,x,2) + 5y - 4z + 36cos(7x); 67ode2 := y + df(z,x,2) - 99cos(7x); 68ode := df(ode1,x,2) + 4ode2; 69y := rhs first odesolve(ode, y, x); 70z := rhs first solve(ode1,z); 71clear ode1, ode2, ode, y, z; 72nodepend z,x; 73 74% A "homogeneous" n-th order (Euler) equation: 75odesolve(x*df(y,x,2) + df(y, x) + y/x + (log x)^3, y, x); 76 77% The solution here remains symbolic (because neither REDUCE nor Maple 78% can evaluate the resulting integral): 79odesolve(6df(y,x,2) + df(y,x) - 2y + tan x, y, x); 80 81end; 82