Mercurial > octave
annotate scripts/polynomial/polyaffine.m @ 31706:597f3ee61a48 stable
update Octave Project Developers copyright for the new year
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 06 Jan 2023 13:11:27 -0500 |
parents | 5d3faba0342e |
children | 2e484f9f1f18 |
rev | line source |
---|---|
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
1 ######################################################################## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
2 ## |
31706
597f3ee61a48
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
30875
diff
changeset
|
3 ## Copyright (C) 2009-2023 The Octave Project Developers |
27918
b442ec6dda5c
use centralized file for copyright info for individual contributors
John W. Eaton <jwe@octave.org>
parents:
26376
diff
changeset
|
4 ## |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
5 ## See the file COPYRIGHT.md in the top-level directory of this |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
6 ## distribution or <https://octave.org/copyright/>. |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
7 ## |
11104 | 8 ## This file is part of Octave. |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
9 ## |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
10 ## Octave is free software: you can redistribute it and/or modify it |
11104 | 11 ## 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
|
12 ## the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
13 ## (at your option) any later version. |
11104 | 14 ## |
15 ## Octave is distributed in the hope that it will be useful, but | |
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
18 ## GNU General Public License for more details. |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
19 ## |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
20 ## You should have received a copy of the GNU General Public License |
11104 | 21 ## 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
|
22 ## <https://www.gnu.org/licenses/>. |
27923
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
23 ## |
bd51beb6205e
update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents:
27919
diff
changeset
|
24 ######################################################################## |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
25 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
26 ## -*- texinfo -*- |
30875
5d3faba0342e
doc: Ensure documentation lists output argument when it exists for all m-files.
Rik <rik@octave.org>
parents:
30564
diff
changeset
|
27 ## @deftypefn {} {@var{g} =} polyaffine (@var{f}, @var{mu}) |
11538
6eded7561d9d
Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
28 ## Return the coefficients of the polynomial vector @var{f} after an affine |
20165
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
29 ## transformation. |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
30 ## |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
31 ## If @var{f} is the vector representing the polynomial f(x), then |
f1d0f506ee78
doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
32 ## @code{@var{g} = polyaffine (@var{f}, @var{mu})} is the vector representing: |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
9758
diff
changeset
|
33 ## |
9116
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
34 ## @example |
14327
4d917a6a858b
doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
35 ## g(x) = f( (x - @var{mu}(1)) / @var{mu}(2) ) |
9116
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
36 ## @end example |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11575
diff
changeset
|
37 ## |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
38 ## @seealso{polyval, polyfit} |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
39 ## @end deftypefn |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
40 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
41 function g = polyaffine (f, mu) |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
42 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
43 if (nargin != 2) |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
44 print_usage (); |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
45 endif |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
46 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
47 if (! isvector (f)) |
11588
d5bd2766c640
style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
48 error ("polyaffine: F must be a vector"); |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
49 endif |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
50 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
51 if (! isvector (mu) || length (mu) != 2) |
11588
d5bd2766c640
style fixes for warning and error messages in script files
John W. Eaton <jwe@octave.org>
parents:
11587
diff
changeset
|
52 error ("polyaffine: MU must be a two-element vector"); |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
53 endif |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
54 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
55 lf = length (f); |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
56 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
57 ## Ensure that f is a row vector |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
58 if (rows (f) > 1) |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
59 f = f.'; |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
60 endif |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
61 |
9116
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
62 g = f; |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
63 |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
64 ## Scale. |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
65 if (mu(2) != 1) |
20231
83792dd9bcc1
Use in-place operators in m-files where possible.
Rik <rik@octave.org>
parents:
20165
diff
changeset
|
66 g ./= mu(2) .^ (lf-1:-1:0); |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
67 endif |
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
68 |
9116
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
69 ## Translate. |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
70 if (mu(1) != 0) |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
71 w = (-mu(1)) .^ (0:lf-1); |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
72 ii = lf:-1:1; |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
73 g = g(ii) * (toeplitz (w) .* pascal (lf, -1)); |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
74 g = g(ii); |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
75 endif |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
76 |
9114
79e90381b402
merge polytrans & polyscale -> polyaffine, make compatible with polyval
Jaroslav Hajek <highegg@gmail.com>
parents:
diff
changeset
|
77 endfunction |
9116
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
78 |
11538
6eded7561d9d
Add undocumented polyaffine function to documentation.
Rik <octave@nomad.inbox5.com>
parents:
11523
diff
changeset
|
79 |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
80 %!demo |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
81 %! f = [1/5 4/5 -7/5 -2]; |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
82 %! g = polyaffine (f, [1, 1.2]); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
83 %! x = linspace (-4,4,100); |
14868
5d3a684236b0
maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
84 %! plot (x,polyval (f, x), x,polyval (g, x)); |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
85 %! legend ("original", "affine"); |
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
86 %! axis ([-4 4 -3 5]); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
87 %! grid on; |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
88 |
9116
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
89 %!test |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
90 %! f = [1/5 4/5 -7/5 -2]; |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
91 %! mu = [1, 1.2]; |
a8be2f7c81ee
improve docs for polyaffine, fix bugs
Jaroslav Hajek <highegg@gmail.com>
parents:
9114
diff
changeset
|
92 %! g = polyaffine (f, mu); |
14237
11949c9795a0
Revamp %!demos in m-files to use Octave coding conventions on spacing, etc.
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
93 %! x = linspace (-4,4,100); |
14104
614505385171
doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents:
11588
diff
changeset
|
94 %! assert (polyval (f, x, [], mu), polyval (g, x), 1e-10); |