PageRenderTime 55ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/tags/R2008-08-24/main/odepkg/inst/odepkg.m

#
MATLAB | 229 lines | 152 code | 30 blank | 47 comment | 29 complexity | 85f3404df880ba07c492aa43a652f64f MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. %# Copyright (C) 2006-2008, Thomas Treichl <treichl@users.sourceforge.net>
  2. %# OdePkg - A package for solving ordinary differential equations and more
  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, see <http://www.gnu.org/licenses/>.
  16. %# -*- texinfo -*-
  17. %# @deftypefn {Function File} {[@var{}] =} odepkg ()
  18. %#
  19. %# OdePkg is part of the GNU Octave Repository (the Octave--Forge project). The package includes commands for setting up various options, output functions etc. before solving a set of differential equations with the solver functions that are also included. At this time OdePkg is under development with the main target to make a package that is mostly compatible to proprietary solver products.
  20. %#
  21. %# If this function is called without any input argument then open the OdePkg tutorial in the Octave window. The tutorial can also be opened with the following command
  22. %#
  23. %# @example
  24. %# doc odepkg
  25. %# @end example
  26. %# @end deftypefn
  27. function [] = odepkg (vstr)
  28. %# Check number and types of all input arguments
  29. if (nargin == 0)
  30. doc ('odepkg');
  31. elseif (nargin > 1)
  32. error ('Number of input arguments must be zero or one');
  33. elseif (ischar (vstr))
  34. feval (vstr);
  35. else
  36. error ('Input argument must be a valid string');
  37. end
  38. function [] = odepkg_validate_mfiles ()
  39. %# From command line in the 'inst' directory do something like this:
  40. %# octave --quiet --eval "odepkg ('odepkg_validate_mfiles')"
  41. vfun = {'ode23', 'ode45', 'ode54', 'ode78', ...
  42. 'ode23d', 'ode45d', 'ode54d', 'ode78d', ...
  43. 'odeget', 'odeset', 'odeplot', 'odephas2', 'odephas3', 'odeprint', ...
  44. 'odepkg_structure_check', 'odepkg_event_handle', ...
  45. 'odepkg_testsuite_calcscd', 'odepkg_testsuite_calcmescd'};
  46. %# vfun = sort (vfun);
  47. for vcnt=1:length(vfun)
  48. printf ('Testing function %s ... ', vfun{vcnt});
  49. test (vfun{vcnt}, 'quiet'); fflush (1);
  50. end
  51. function [] = odepkg_validate_ccfiles ()
  52. %# From command line in the 'src' directory do something like this:
  53. %# octave --quiet --eval "odepkg ('odepkg_validate_ccfiles')"
  54. vfile = {'odepkg_octsolver_mebdfdae.cc', 'odepkg_octsolver_mebdfi.cc', ...
  55. 'odepkg_octsolver_ddaskr.cc', ...
  56. 'odepkg_octsolver_radau.cc', 'odepkg_octsolver_radau5.cc', ...
  57. 'odepkg_octsolver_rodas.cc', 'odepkg_octsolver_seulex.cc'};
  58. vsolv = {'odebda', 'odebdi', 'odekdi', ...
  59. 'ode2r', 'ode5r', 'oders', 'odesx'};
  60. %# vfile = {'odepkg_octsolver_ddaskr.cc'};
  61. %# vsolv = {'odekdi'};
  62. for vcnt=1:length(vfile)
  63. printf ('Testing function %s ... ', vsolv{vcnt});
  64. autoload (vsolv{vcnt}, canonicalize_file_name ('dldsolver.oct'));
  65. test (vfile{vcnt}, 'quiet'); fflush (1);
  66. end
  67. function [] = odepkg_internal_mhelpextract ()
  68. %# In the inst directory do
  69. %# octave --quiet --eval "odepkg ('odepkg_internal_mhelpextract')"
  70. vfun = {'odepkg', 'odeget', 'odeset', ...
  71. 'ode23', 'ode45', 'ode54', 'ode78', ...
  72. 'ode23d', 'ode45d', 'ode54d', 'ode78d', ...
  73. 'odeplot', 'odephas2', 'odephas3', 'odeprint', ...
  74. 'odepkg_structure_check', 'odepkg_event_handle', ...
  75. 'odepkg_testsuite_calcscd', 'odepkg_testsuite_calcmescd', ...
  76. 'odepkg_testsuite_oregonator', 'odepkg_testsuite_pollution', ...
  77. 'odepkg_testsuite_hires', ...
  78. 'odepkg_testsuite_robertson', 'odepkg_testsuite_chemakzo', ...
  79. 'odepkg_testsuite_transistor', ...
  80. 'odepkg_testsuite_implrober', 'odepkg_testsuite_implakzo', ...
  81. 'odepkg_testsuite_imptrans', ...
  82. 'odeexamples', 'odepkg_examples_ode', 'odepkg_examples_dae', ...
  83. 'odepkg_examples_ide', 'odepkg_examples_dde'};
  84. vfun = sort (vfun);
  85. [vout, vmsg] = fopen ('../doc/mfunref.texi', 'w');
  86. if ~(isempty (vmsg)), error (vmsg); end
  87. for vcnt = 1:length (vfun)
  88. if (exist (vfun{vcnt}, 'file'))
  89. [vfid, vmsg] = fopen (which (vfun{vcnt}), 'r');
  90. if ~(isempty (vmsg)), error (vmsg); end
  91. while (true)
  92. vlin = fgets (vfid);
  93. if ~(ischar (vlin)), break; end
  94. if (regexp (vlin, '^(%# -\*- texinfo -\*-)'))
  95. while (~isempty (regexp (vlin, '^(%#)')) && ...
  96. isempty (regexp (vlin, '^(%# @end deftypefn)')))
  97. vlin = fgets (vfid);
  98. if (length (vlin) > 3), fprintf (vout, '%s', vlin(4:end));
  99. else fprintf (vout, '%s', vlin(3:end));
  100. end
  101. end
  102. fprintf (vout, '\n');
  103. end
  104. end
  105. fclose (vfid);
  106. end
  107. end
  108. fclose (vout);
  109. function [] = odepkg_internal_octhelpextract ()
  110. %# In the src directory do
  111. %# octave --quiet --eval "odepkg ('odepkg_internal_octhelpextract')"
  112. vfiles = {'../src/odepkg_octsolver_mebdfdae.cc', ...
  113. '../src/odepkg_octsolver_mebdfi.cc', ...
  114. '../src/odepkg_octsolver_ddaskr.cc', ...
  115. '../src/odepkg_octsolver_radau.cc', ...
  116. '../src/odepkg_octsolver_radau5.cc', ...
  117. '../src/odepkg_octsolver_rodas.cc', ...
  118. '../src/odepkg_octsolver_seulex.cc', ...
  119. };
  120. %# vfiles = sort (vfiles); Don't sort these files
  121. [vout, vmsg] = fopen ('../doc/dldfunref.texi', 'w');
  122. if ~(isempty (vmsg)), error (vmsg); end
  123. for vcnt = 1:length (vfiles)
  124. if (exist (vfiles{vcnt}, 'file'))
  125. [vfid, vmsg] = fopen (vfiles{vcnt}, 'r');
  126. if ~(isempty (vmsg)), error (vmsg); end
  127. while (true)
  128. vlin = fgets (vfid);
  129. if ~(ischar (vlin)), break; end
  130. if (regexp (vlin, '^("-\*- texinfo -\*-\\n\\)')) %#"
  131. vlin = ' * '; %# Needed for the first call of while()
  132. while (isempty (regexp (vlin, '^(@end deftypefn)')) && ischar (vlin))
  133. vlin = fgets (vfid);
  134. vlin = sprintf (regexprep (vlin, '\\n\\', ''));
  135. vlin = regexprep (vlin, '\\"', '"');
  136. fprintf (vout, '%s', vlin);
  137. end
  138. fprintf (vout, '\n');
  139. end
  140. end
  141. fclose (vfid);
  142. end
  143. end
  144. fclose (vout);
  145. function [] = odepkg_performance_mathires ()
  146. vfun = {@ode113, @ode23, @ode45, ...
  147. @ode15s, @ode23s, @ode23t, @ode23tb};
  148. for vcnt=1:length(vfun)
  149. vsol{vcnt, 1} = odepkg_testsuite_hires (vfun{vcnt}, 1e-7);
  150. end
  151. odepkg_testsuite_write (vsol);
  152. function [] = odepkg_performance_octavehires ()
  153. vfun = {@ode23, @ode45, @ode54, @ode78, ...
  154. @ode2r, @ode5r, @oders, @odesx, @odebda};
  155. for vcnt=1:length(vfun)
  156. vsol{vcnt, 1} = odepkg_testsuite_hires (vfun{vcnt}, 1e-7);
  157. end
  158. odepkg_testsuite_write (vsol);
  159. function [] = odepkg_performance_matchemakzo ()
  160. vfun = {@ode23, @ode45, ...
  161. @ode15s, @ode23s, @ode23t, @ode23tb};
  162. for vcnt=1:length(vfun)
  163. vsol{vcnt, 1} = odepkg_testsuite_chemakzo (vfun{vcnt}, 1e-7);
  164. end
  165. odepkg_testsuite_write (vsol);
  166. function [] = odepkg_performance_octavechemakzo ()
  167. vfun = {@ode23, @ode45, @ode54, @ode78, ...
  168. @ode2r, @ode5r, @oders, @odesx, @odebda};
  169. for vcnt=1:length(vfun)
  170. vsol{vcnt, 1} = odepkg_testsuite_chemakzo (vfun{vcnt}, 1e-7);
  171. end
  172. odepkg_testsuite_write (vsol);
  173. function [] = odepkg_testsuite_write (vsol)
  174. fprintf (1, ['-----------------------------------------------------------------------------------------\n']);
  175. fprintf (1, [' Solver RelTol AbsTol Init Mescd Scd Steps Accept FEval JEval LUdec Time\n']);
  176. fprintf (1, ['-----------------------------------------------------------------------------------------\n']);
  177. [vlin, vcol] = size (vsol);
  178. for vcntlin = 1:vlin
  179. if (isempty (vsol{vcntlin}{9})), vsol{vcntlin}{9} = 0; end
  180. %# if (vcntlin > 1) %# Delete solver name if it is the same as before
  181. %# if (strcmp (func2str (vsol{vcntlin}{1}), func2str (vsol{vcntlin-1}{1})))
  182. %# vsol{vcntlin}{1} = ' ';
  183. %# end
  184. %# end
  185. fprintf (1, ['%7s %6.0g %6.0g %6.0g %5.2f %5.2f %5.0d %6.0d %5.0d %5.0d %5.0d %6.3f\n'], ...
  186. func2str (vsol{vcntlin}{1}), vsol{vcntlin}{2:12});
  187. end
  188. fprintf (1, ['-----------------------------------------------------------------------------------------\n']);
  189. function [] = odepkg_internal_demos ()
  190. vfun = {'odepkg', 'odeget', 'odeset', ...
  191. 'ode23', 'ode45', 'ode54', 'ode78', ...
  192. 'ode23d', 'ode45d', 'ode54d', 'ode78d', ...
  193. 'odeplot', 'odephas2', 'odephas3', 'odeprint', ...
  194. 'odepkg_structure_check', 'odepkg_event_handle'};
  195. vfun = sort (vfun);
  196. for vcnt = 1:length (vfun), demo (vfun{vcnt}); end
  197. %# Local Variables: ***
  198. %# mode: octave ***
  199. %# End: ***