]> Creatis software - CreaPhase.git/blob - octave_packages/odepkg-0.8.2/odepkg_testsuite_hires.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / odepkg-0.8.2 / odepkg_testsuite_hires.m
1 %# Copyright (C) 2007-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{solution}] =} odepkg_testsuite_hires (@var{@@solver}, @var{reltol})
19 %#
20 %# If this function is called with two input arguments and the first input argument @var{@@solver} is a function handle describing an OdePkg solver and the second input argument @var{reltol} is a double scalar describing the relative error tolerance then return a cell array @var{solution} with performance informations about the HIRES testsuite of ordinary differential equations after solving (ODE--test).
21 %#
22 %# Run examples with the command
23 %# @example
24 %# demo odepkg_testsuite_hires
25 %# @end example
26 %#
27 %# This function has been ported from the "Test Set for IVP solvers" which is developed by the INdAM Bari unit project group "Codes and Test Problems for Differential Equations", coordinator F. Mazzia.
28 %# @end deftypefn
29 %#
30 %# @seealso{odepkg}
31
32 function vret = odepkg_testsuite_hires (vhandle, vrtol)
33
34   if (nargin ~= 2) %# Check number and types of all input arguments
35     help  ('odepkg_testsuite_hires');
36     error ('OdePkg:InvalidArgument', ...
37       'Number of input arguments must be exactly two');
38   elseif (~isa (vhandle, 'function_handle') || ~isscalar (vrtol))
39     print_usage;
40   end
41
42   vret{1} = vhandle; %# The handle for the solver that is used
43   vret{2} = vrtol;   %# The value for the realtive tolerance
44   vret{3} = vret{2}; %# The value for the absolute tolerance
45   vret{4} = vret{2} * 10^(-2);  %# The value for the first time step
46   %# Write a debug message on the screen, because this testsuite function
47   %# may be called more than once from a loop over all solvers present
48   fprintf (1, ['Testsuite HIRES, testing solver %7s with relative', ...
49     ' tolerance %2.0e\n'], func2str (vret{1}), vrtol); fflush (1);
50
51   %# Setting the integration algorithms option values
52   vstart = 0.0;      %# The point of time when solving is started
53   vstop  = 321.8122; %# The point of time when solving is stoped
54   vinit  = odepkg_testsuite_hiresinit; %# The initial values
55
56   vopt = odeset ('Refine', 0, 'RelTol', vret{2}, 'AbsTol', vret{3}, ...
57     'InitialStep', vret{4}, 'Stats', 'on', 'NormControl', 'off', ...
58     'Jacobian', @odepkg_testsuite_hiresjac, 'MaxStep', vstop-vstart);
59
60   %# Calculate the algorithm, start timer and do solving
61   tic; vsol = feval (vhandle, @odepkg_testsuite_hiresfun, ...
62     [vstart, vstop], vinit, vopt);
63   vret{12} = toc;                   %# The value for the elapsed time
64   vref = odepkg_testsuite_hiresref; %# Get the reference solution vector
65   if (exist ('OCTAVE_VERSION') ~= 0)
66     vlst = vsol.y(end,:);
67   else
68     vlst = vsol.y(:,end);
69   end
70   vret{5}  = odepkg_testsuite_calcmescd (vlst, vref, vret{3}, vret{2});
71   vret{6}  = odepkg_testsuite_calcscd (vlst, vref, vret{3}, vret{2});
72   vret{7}  = vsol.stats.nsteps + vsol.stats.nfailed; %# The value for all evals
73   vret{8}  = vsol.stats.nsteps;   %# The value for success evals
74   vret{9}  = vsol.stats.nfevals;  %# The value for fun calls
75   vret{10} = vsol.stats.npds;     %# The value for partial derivations
76   vret{11} = vsol.stats.ndecomps; %# The value for LU decompositions
77
78 %# Returns the results for the HIRES problem
79 function f = odepkg_testsuite_hiresfun (t, y, varargin)
80   f(1,1) = -1.71 * y(1) + 0.43 * y(2) + 8.32 * y(3) + 0.0007;
81   f(2,1) =  1.71 * y(1) - 8.75 * y(2);
82   f(3,1) = -10.03 * y(3) + 0.43 * y(4) + 0.035 * y(5);
83   f(4,1) =  8.32 * y(2) + 1.71 * y(3) - 1.12 * y(4);
84   f(5,1) = -1.745 * y(5) + 0.43 * (y(6) + y(7));
85   f(6,1) = -280 * y(6) * y(8) + 0.69 * y(4) + 1.71 * y(5) - 0.43 * y(6) + 0.69 * y(7);
86   f(7,1) =  280 * y(6) * y(8) - 1.81 * y(7);
87   f(8,1) = -f(7);
88
89 %# Returns the INITIAL values for the HIRES problem
90 function vinit = odepkg_testsuite_hiresinit ()
91   vinit = [1, 0, 0, 0, 0, 0, 0, 0.0057];
92
93 %# Returns the JACOBIAN matrix for the HIRES problem
94 function dfdy = odepkg_testsuite_hiresjac (t, y, varargin)
95   dfdy(1,1) = -1.71;
96   dfdy(1,2) =  0.43;
97   dfdy(1,3) =  8.32;
98   dfdy(2,1) =  1.71;
99   dfdy(2,2) = -8.75;
100   dfdy(3,3) = -10.03;
101   dfdy(3,4) =  0.43;
102   dfdy(3,5) =  0.035;
103   dfdy(4,2) =  8.32;
104   dfdy(4,3) =  1.71;
105   dfdy(4,4) = -1.12;
106   dfdy(5,5) = -1.745;
107   dfdy(5,6) =  0.43;
108   dfdy(5,7) =  0.43;
109   dfdy(6,4) =  0.69;
110   dfdy(6,5) =  1.71;
111   dfdy(6,6) = -280 * y(8) - 0.43;
112   dfdy(6,7) =  0.69;
113   dfdy(6,8) = -280 * y(6);
114   dfdy(7,6) =  280 * y(8);
115   dfdy(7,7) = -1.81;
116   dfdy(7,8) =  280 * y(6);
117   dfdy(8,6) = -280 * y(8);
118   dfdy(8,7) =  1.81;
119   dfdy(8,8) = -280 * y(6);
120
121 %# Returns the REFERENCE values for the HIRES problem
122 function y = odepkg_testsuite_hiresref ()
123   y(1,1) = 0.73713125733256e-3;
124   y(2,1) = 0.14424857263161e-3;
125   y(3,1) = 0.58887297409675e-4;
126   y(4,1) = 0.11756513432831e-2;
127   y(5,1) = 0.23863561988313e-2;
128   y(6,1) = 0.62389682527427e-2;
129   y(7,1) = 0.28499983951857e-2;
130   y(8,1) = 0.28500016048142e-2;
131
132 %!demo
133 %! vsolver = {@ode23, @ode45, @ode54, @ode78, ...
134 %!   @odebda, @oders, @ode2r, @ode5r, @odesx};
135 %! for vcnt=1:length (vsolver)
136 %!   vhires{vcnt,1} = odepkg_testsuite_hires (vsolver{vcnt}, 1e-7);
137 %! end
138 %! vhires
139
140 %# Local Variables: ***
141 %# mode: octave ***
142 %# End: ***