odesolve.tst 2.5 KB

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