]> Creatis software - CreaPhase.git/blob - octave_packages/odepkg-0.8.2/odepkg_testsuite_calcmescd.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / odepkg-0.8.2 / odepkg_testsuite_calcmescd.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{mescd}] =} odepkg_testsuite_calcmescd (@var{solution}, @var{reference}, @var{abstol}, @var{reltol})
19 %#
20 %# If this function is called with four input arguments of type double scalar or column vector then return a normalized value for the minimum number of correct digits @var{mescd} that is calculated from the solution at the end of an integration interval @var{solution} and a set of reference values @var{reference}. The input arguments @var{abstol} and @var{reltol} are used to calculate a reference solution that depends on the relative and absolute error tolerances.
21 %# 
22 %# Run examples with the command
23 %# @example
24 %# demo odepkg_testsuite_calcmescd
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
33 function vmescd = odepkg_testsuite_calcmescd (vsol, vref, vatol, vrtol)
34   vsol = vsol(:); vref = vref(:); vatol = vatol(:); vrtol = vrtol(:);
35   vtmp = (vref - vsol) ./ (vatol ./ vrtol + vref);
36   vmescd = -log10 (norm (vtmp, inf));
37
38 %!demo
39 %! # Display the value for the mimum number of correct digits in the vector
40 %! # sol = [1, 2, 2.9] compared to the reference vector ref = [1, 2, 3].
41 %!
42 %! odepkg_testsuite_calcmescd ([1, 2, 2.9], [1, 2, 3], 1e-3, 1e-6)
43 %!
44 %!demo
45 %! # Display the value for the mimum number of correct digits in the vector
46 %! # sol = [1 + 1e10, 2 + 1e10, 3 + 1e10] compared to the reference vector 
47 %! # ref = [1, 2, 3].
48 %!
49 %! odepkg_testsuite_calcmescd ([1 + 1e10, 2 + 1e10, 3 + 1e10], [1, 2, 3], ...
50 %!   [1e-3, 1e-4, 1e-5], [1e-6, 1e-6, 1e-6])
51
52 %!assert (odepkg_testsuite_calcmescd ([1, 2, 3], [1, 2, 3], NaN, NaN), Inf);
53 %!assert (odepkg_testsuite_calcmescd ([1, 2, 3], [1, 2, 3], 1, 1), Inf);
54 %!assert (odepkg_testsuite_calcmescd ([1, 2, 3], [1, 2.1, 3], 1, 1), 1.5, 0.1);
55 %!assert (odepkg_testsuite_calcmescd ([1, 2, 3], [1+1e-6, 2, 3], 1, 1), 6.5, 0.2);
56
57 %# Local Variables: ***
58 %# mode: octave ***
59 %# End: ***