]> Creatis software - CreaPhase.git/blob - octave_packages/odepkg-0.8.2/odepkg.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / odepkg-0.8.2 / odepkg.m
1 %# Copyright (C) 2006-2012, 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
17 %# -*- texinfo -*-
18 %# @deftypefn {Function File} {[@var{}] =} odepkg ()
19 %#
20 %# 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.
21 %#
22 %# 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
23 %#
24 %# @example
25 %# doc odepkg
26 %# @end example
27 %# @end deftypefn
28
29 function [] = odepkg (vstr)
30
31   %# Check number and types of all input arguments
32   if (nargin == 0)
33     doc ('odepkg');
34   elseif (nargin > 1)
35     error ('Number of input arguments must be zero or one');
36   elseif (ischar (vstr))
37     feval (vstr);
38   else
39     error ('Input argument must be a valid string');
40   end
41
42 function [] = odepkg_validate_mfiles ()
43
44   %# From command line in the 'inst' directory do something like this: 
45   %#   octave --quiet --eval "odepkg ('odepkg_validate_mfiles')"
46
47   vfun = {'ode23', 'ode45', 'ode54', 'ode78', ...
48           'ode23d', 'ode45d', 'ode54d', 'ode78d', ...
49           'odeget', 'odeset', 'odeplot', 'odephas2', 'odephas3', 'odeprint', ...
50           'odepkg_structure_check', 'odepkg_event_handle', ...
51           'odepkg_testsuite_calcscd', 'odepkg_testsuite_calcmescd'};
52   %# vfun = sort (vfun);
53
54   for vcnt=1:length(vfun)
55     printf ('Testing function %s ... ', vfun{vcnt});
56     test (vfun{vcnt}, 'quiet'); fflush (1);
57   end
58
59 function [] = odepkg_validate_ccfiles ()
60
61   %# From command line in the 'src' directory do something like this: 
62   %#   octave --quiet --eval "odepkg ('odepkg_validate_ccfiles')"
63
64   vfile = {'odepkg_octsolver_mebdfdae.cc', 'odepkg_octsolver_mebdfi.cc', ... 
65            'odepkg_octsolver_ddaskr.cc', ...
66            'odepkg_octsolver_radau.cc', 'odepkg_octsolver_radau5.cc', ...
67            'odepkg_octsolver_rodas.cc', 'odepkg_octsolver_seulex.cc'};
68   vsolv = {'odebda', 'odebdi', 'odekdi', ...
69            'ode2r', 'ode5r', 'oders', 'odesx'};
70   %# vfile = {'odepkg_octsolver_ddaskr.cc'};
71   %# vsolv = {'odekdi'};
72
73   for vcnt=1:length(vfile)
74     printf ('Testing function %s ... ', vsolv{vcnt});
75     autoload (vsolv{vcnt}, which ('dldsolver.oct'));
76     test (vfile{vcnt}, 'quiet'); fflush (1);
77   end
78
79 function [] = odepkg_internal_mhelpextract ()
80
81   %# In the inst directory do
82   %#   octave --quiet --eval "odepkg ('odepkg_internal_mhelpextract')"
83
84   vfun = {'odepkg', 'odeget', 'odeset', ...
85           'ode23', 'ode45', 'ode54', 'ode78', ...
86           'ode23d', 'ode45d', 'ode54d', 'ode78d', ...
87           'odebwe', ...
88           'odeplot', 'odephas2', 'odephas3', 'odeprint', ...
89           'odepkg_structure_check', 'odepkg_event_handle', ...
90           'odepkg_testsuite_calcscd', 'odepkg_testsuite_calcmescd', ...
91           'odepkg_testsuite_oregonator', 'odepkg_testsuite_pollution', ...
92           'odepkg_testsuite_hires', ...
93           'odepkg_testsuite_robertson', 'odepkg_testsuite_chemakzo', ...
94           'odepkg_testsuite_transistor', ...
95           'odepkg_testsuite_implrober', 'odepkg_testsuite_implakzo', ...
96           'odepkg_testsuite_imptrans', ...
97           'odeexamples', 'odepkg_examples_ode', 'odepkg_examples_dae', ...
98           'odepkg_examples_ide', 'odepkg_examples_dde'};
99   vfun = sort (vfun);
100
101   [vout, vmsg] = fopen ('../doc/mfunref.texi', 'w');
102   if ~(isempty (vmsg)), error (vmsg); end
103   for vcnt = 1:length (vfun)
104     if (exist (vfun{vcnt}, 'file'))
105       [vfid, vmsg] = fopen (which (vfun{vcnt}), 'r');
106       if ~(isempty (vmsg)), error (vmsg); end
107       while (true)
108         vlin = fgets (vfid);
109         if ~(ischar (vlin)), break; end
110         if (regexp (vlin, '^(%# -\*- texinfo -\*-)'))
111           while (~isempty (regexp (vlin, '^(%#)')) && ...
112                   isempty (regexp (vlin, '^(%# @end deftypefn)')))
113             vlin = fgets (vfid);
114             if (length (vlin) > 3), fprintf (vout, '%s', vlin(4:end));
115             else fprintf (vout, '%s', vlin(3:end));
116             end
117           end
118           fprintf (vout, '\n');
119         end
120       end
121       fclose (vfid);
122     end
123   end
124   fclose (vout);
125
126 function [] = odepkg_internal_octhelpextract ()
127
128   %# In the src directory do
129   %#   octave --quiet --eval "odepkg ('odepkg_internal_octhelpextract')"
130
131   vfiles = {'../src/odepkg_octsolver_mebdfdae.cc', ...
132             '../src/odepkg_octsolver_mebdfi.cc', ...
133             '../src/odepkg_octsolver_ddaskr.cc', ...
134             '../src/odepkg_octsolver_radau.cc', ...
135             '../src/odepkg_octsolver_radau5.cc', ...
136             '../src/odepkg_octsolver_rodas.cc', ...
137             '../src/odepkg_octsolver_seulex.cc', ...
138            };
139   %# vfiles = sort (vfiles); Don't sort these files
140
141   [vout, vmsg] = fopen ('../doc/dldfunref.texi', 'w');
142   if ~(isempty (vmsg)), error (vmsg); end
143   for vcnt = 1:length (vfiles)
144     if (exist (vfiles{vcnt}, 'file'))
145       [vfid, vmsg] = fopen (vfiles{vcnt}, 'r');
146       if ~(isempty (vmsg)), error (vmsg); end
147       while (true)
148         vlin = fgets (vfid);
149         if ~(ischar (vlin)), break; end
150           if (regexp (vlin, '^("-\*- texinfo -\*-\\n\\)')) %#"
151           vlin = ' * '; %# Needed for the first call of while()
152           while (isempty (regexp (vlin, '^(@end deftypefn)')) && ischar (vlin))
153             vlin = fgets (vfid);
154             vlin = sprintf (regexprep (vlin, '\\n\\', ''));
155             vlin = regexprep (vlin, '\\"', '"');
156             fprintf (vout, '%s', vlin);
157           end
158           fprintf (vout, '\n');
159         end
160       end
161       fclose (vfid);
162     end
163   end
164   fclose (vout);
165
166 function [] = odepkg_performance_mathires ()
167   vfun = {@ode113, @ode23, @ode45, ...
168           @ode15s, @ode23s, @ode23t, @ode23tb};
169   for vcnt=1:length(vfun)
170     vsol{vcnt, 1} = odepkg_testsuite_hires (vfun{vcnt}, 1e-7);
171   end
172   odepkg_testsuite_write (vsol);
173
174 function [] = odepkg_performance_octavehires ()
175   vfun = {@ode23, @ode45, @ode54, @ode78, ...
176           @ode2r, @ode5r, @oders, @odesx, @odebda};
177   for vcnt=1:length(vfun)
178     vsol{vcnt, 1} = odepkg_testsuite_hires (vfun{vcnt}, 1e-7);
179   end
180   odepkg_testsuite_write (vsol);
181
182 function [] = odepkg_performance_matchemakzo ()
183   vfun = {@ode23, @ode45, ...
184           @ode15s, @ode23s, @ode23t, @ode23tb};
185   for vcnt=1:length(vfun)
186     vsol{vcnt, 1} = odepkg_testsuite_chemakzo (vfun{vcnt}, 1e-7);
187   end
188   odepkg_testsuite_write (vsol);
189
190 function [] = odepkg_performance_octavechemakzo ()
191   vfun = {@ode23, @ode45, @ode54, @ode78, ...
192           @ode2r, @ode5r, @oders, @odesx, @odebda};
193   for vcnt=1:length(vfun)
194     vsol{vcnt, 1} = odepkg_testsuite_chemakzo (vfun{vcnt}, 1e-7);
195   end
196   odepkg_testsuite_write (vsol);
197
198 function [] = odepkg_testsuite_write (vsol)
199
200   fprintf (1, ['-----------------------------------------------------------------------------------------\n']);
201   fprintf (1, [' Solver  RelTol  AbsTol   Init   Mescd    Scd  Steps  Accept  FEval  JEval  LUdec    Time\n']);
202   fprintf (1, ['-----------------------------------------------------------------------------------------\n']);
203
204   [vlin, vcol] = size (vsol);
205   for vcntlin = 1:vlin
206     if (isempty (vsol{vcntlin}{9})), vsol{vcntlin}{9} = 0; end
207     %# if (vcntlin > 1) %# Delete solver name if it is the same as before
208     %#   if (strcmp (func2str (vsol{vcntlin}{1}), func2str (vsol{vcntlin-1}{1})))
209     %#     vsol{vcntlin}{1} = ' ';
210     %#   end
211     %# end
212     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'], ...
213              func2str (vsol{vcntlin}{1}), vsol{vcntlin}{2:12});
214   end
215   fprintf (1, ['-----------------------------------------------------------------------------------------\n']);
216
217 function [] = odepkg_internal_demos ()
218
219   vfun = {'odepkg', 'odeget', 'odeset', ...
220           'ode23', 'ode45', 'ode54', 'ode78', ...
221           'ode23d', 'ode45d', 'ode54d', 'ode78d', ...
222           'odeplot', 'odephas2', 'odephas3', 'odeprint', ...
223           'odepkg_structure_check', 'odepkg_event_handle'};
224   vfun = sort (vfun);
225
226   for vcnt = 1:length (vfun), demo (vfun{vcnt}); end
227
228 %# Local Variables: ***
229 %# mode: octave ***
230 %# End: ***