/tags/R2007-12-12/main/odepkg/inst/ode8d.m

# · MATLAB · 108 lines · 8 code · 5 blank · 95 comment · 1 complexity · bca94acac794bec60b3dfe70a43070a5 MD5 · raw file

  1. %# Copyright (C) 2006, Thomas Treichl <treichl@users.sourceforge.net>
  2. %# OdePkg - Package for solving ordinary differential equations with octave
  3. %#
  4. %# This program is free software; you can redistribute it and/or modify
  5. %# it under the terms of the GNU General Public License as published by
  6. %# the Free Software Foundation; either version 2 of the License, or
  7. %# (at your option) any later version.
  8. %#
  9. %# This program is distributed in the hope that it will be useful,
  10. %# but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. %# GNU General Public License for more details.
  13. %#
  14. %# You should have received a copy of the GNU General Public License
  15. %# along with this program; if not, write to the Free Software
  16. %# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. %# -*- texinfo -*-
  18. %# @deftypefn {Function File} {[@var{}] =} ode8d (@var{@@fun}, @var{slot}, @var{init}, [@var{opt}], [@var{par1}, @var{par2}, @dots{}])
  19. %# @deftypefnx {Command} {[@var{sol}] =} ode8d (@var{@@fun}, @var{slot}, @var{init}, [@var{opt}], [@var{par1}, @var{par2}, @dots{}])
  20. %# @deftypefnx {Command} {[@var{t}, @var{y}, [@var{xe}, @var{ye}, @var{ie}]] =} ode8d (@var{@@fun}, @var{slot}, @var{init}, [@var{opt}], [@var{par1}, @var{par2}, @dots{}])
  21. %#
  22. %# This function file can be used to solve a set of non--stiff ordinary differential equations (non--stiff ODEs) or non--stiff differential algebraic equations (non--stiff DAEs) with the well known explicit Runge--Kutta method of order (8,5,3).
  23. %#
  24. %# @b{Note: The function files @file{odepkg_mexsolver_dop853} and @file{ode8d} will be removed when version 0.4.0 of OdePkg will be released. A similiar solver method is @file{ode78}, please use the @file{ode78} solver instead.}
  25. %#
  26. %# @end deftypefn
  27. %# @seealso{odepkg}
  28. function [varargout] = ode8d (varargin)
  29. warning ('Solver ode8d is deprecated and will be removed with OdePkg 0.4.0');
  30. warning ('Use the very similiar solver ode78 instead.');
  31. if (exist ('odepkg_mexsolver_dop853') != 3)
  32. error ('Mex-function "odepkg_mexsolver_dop853" is not installed');
  33. else
  34. [varargout{1:nargout}] = odepkg_mexsolver_dop853 (varargin{:});
  35. end
  36. %# The following tests have been added to check the function's input arguments
  37. %# and output arguments
  38. %!test
  39. %! warning ("off", "OdePkg:InvalidOption");
  40. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  41. %! vsol = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0]);
  42. %! end
  43. %!test
  44. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  45. %! [vx, vy] = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0]);
  46. %! end
  47. %!test
  48. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  49. %! [vx, vy, va, vb, vc] = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0]);
  50. %! end
  51. %#
  52. %# Removed the fixed step size tests because they won't work with this solver
  53. %#
  54. %!test
  55. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  56. %! A = odeset ('MaxStep', 0.1, 'RelTol', 1e-2, 'AbsTol', 1e-3);
  57. %! vsol = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0], A);
  58. %! end
  59. %!test
  60. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  61. %! A = odeset ('MaxStep', 0.1, 'RelTol', 1e-2, 'AbsTol', 1e-3);
  62. %! [vx, vy] = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0], A);
  63. %! end
  64. %!test
  65. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  66. %! A = odeset ('MaxStep', 0.1, 'RelTol', 1e-2, 'AbsTol', 1e-3);
  67. %! [vx, vy, va, vb, vc] = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0], A);
  68. %! end
  69. %!test
  70. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  71. %! A = odeset ('MaxStep', 0.1, 'RelTol', 1e-2, 'AbsTol', 1e-3);
  72. %! vsol = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0], A, 1.2);
  73. %! end
  74. %!test
  75. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  76. %! A = odeset ('MaxStep', 0.1, 'RelTol', 1e-2, 'AbsTol', 1e-3);
  77. %! [vx, vy] = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0], A, 1.2);
  78. %! end
  79. %!test
  80. %! if (!strcmp (which ("odepkg_mexsolver_dop853"), ""))
  81. %! A = odeset ('MaxStep', 0.1, 'RelTol', 1e-2, 'AbsTol', 1e-3);
  82. %! [vx, vy, va, vb, vc] = ode8d (@odepkg_equations_vanderpol, [0 2], [2 0], A, 1.2);
  83. %! end
  84. %! warning ("on", "OdePkg:InvalidOption");
  85. %!demo
  86. %!
  87. %! A = odeset ('RelTol', 1e-1, 'AbsTol', 1e-2);
  88. %! [vx, vy] = ode8d (@odepkg_equations_secondorderlag, [0 2.5], [0 0], ...
  89. %! A, 5, 2, 0.02, 0.1);
  90. %!
  91. %! plot (vx, vy(:,1), '-ob;y, x2;', vx, vy(:,2), '-or;x1;', ...
  92. %! vx, ones(length(vx),1)*5, '-og;u;');
  93. %!
  94. %! % ---------------------------------------------------------------------
  95. %! % The figure window shows the state variables x1, x2 as well as the
  96. %! % input signal u and the output signal y(=x2) of a second order lag
  97. %! % implementation (cf. the control theory). The function ode8d was
  98. %! % called with an option argument A that has been set before with the
  99. %! % command "odeset" and with further parameters "5, 2, 0.02, 0.1" that
  100. %! % are passed to the set of ordinary differential equations.
  101. %# Local Variables: ***
  102. %# mode: octave ***
  103. %# End: ***