Mercurial > octave
annotate scripts/ode/private/kahan.m @ 25054:6652d3823428 stable
maint: Update copyright dates in all source files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Mar 2018 09:19:05 -0400 |
parents | 194eb4bd202b |
children | 00f796120a6d |
rev | line source |
---|---|
25054
6652d3823428
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
24534
diff
changeset
|
1 ## Copyright (C) 2013-2018 Roberto Porcu' <roberto.porcu@polimi.it> |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
2 ## |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
3 ## This file is part of Octave. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
4 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
5 ## Octave is free software: you can redistribute it and/or modify it |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
6 ## under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
7 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
8 ## (at your option) any later version. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
9 ## |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
10 ## Octave is distributed in the hope that it will be useful, but |
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22626
diff
changeset
|
13 ## GNU General Public License for more details. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
14 ## |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
15 ## You should have received a copy of the GNU General Public License |
20536
6256f6e366ac
Fix copyright text in private ode functions
Carlo de Falco <carlo.defalco@polimi.it>
parents:
20533
diff
changeset
|
16 ## along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
17 ## <https://www.gnu.org/licenses/>. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
18 |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
19 ## -*- texinfo -*- |
20852
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20634
diff
changeset
|
20 ## @deftypefn {} {@var{sum} =} kahan (@var{sum}, @var{comp}, @var{term}) |
516bb87ea72e
2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents:
20634
diff
changeset
|
21 ## @deftypefnx {} {[@var{sum}, @var{comp}] =} kahan (@var{sum}, @var{comp}, @var{term}) |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
22 ## |
20621
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
23 ## This function implements the Kahan summation algorithm, also known as |
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
24 ## compensated summation. |
20548
25623ef2ff4f
doc: Rewrite docstrings for ode* family of functions.
Rik <rik@octave.org>
parents:
20536
diff
changeset
|
25 ## |
20621
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
26 ## The algorithm significantly reduces the numerical error in the total |
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
27 ## obtained by adding a sequence of finite precision floating point numbers, |
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
28 ## compared to the straightforward approach. For more details |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
29 ## see @url{http://en.wikipedia.org/wiki/Kahan_summation_algorithm}. |
22626 | 30 ## This function is called by @code{integrate_adaptive} to better catch |
31 ## equality comparisons. | |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
32 ## |
22626 | 33 ## The first input argument is the variable that will contain the summation. |
34 ## This variable is also returned as the first output argument in order to | |
35 ## reuse it in subsequent calls to @code{kahan} function. | |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
36 ## |
22626 | 37 ## The second input argument contains the compensation term and is returned |
20621
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
38 ## as the second output argument so that it can be reused in future calls of |
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
39 ## the same summation. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
40 ## |
21546
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
41 ## The third input argument @var{term} is the variable to be added to |
f7f97d7e9294
doc: Wrap m-file docstrings to 79 characters + newline (80 total).
Rik <rik@octave.org>
parents:
20852
diff
changeset
|
42 ## @var{sum}. |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
43 ## @end deftypefn |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
44 |
20621
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
45 function [sum, comp] = kahan (sum, comp, term) |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
46 |
20621
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
47 y = term - comp; |
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
48 t = sum + y; |
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
49 comp = (t - sum) - y; |
b92f8e148936
maint: Continued clean-up of functions in ode/private dir.
Rik <rik@octave.org>
parents:
20552
diff
changeset
|
50 sum = t; |
20533
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
51 |
fcb792acab9b
Moving ode45, odeset, odeget, and levenshtein from odepkg to core.
jcorno <jacopo.corno@gmail.com>
parents:
diff
changeset
|
52 endfunction |