annotate scripts/polynomial/polyout.m @ 30564:796f54d4ddbf stable

update Octave Project Developers copyright for the new year In files that have the "Octave Project Developers" copyright notice, update for 2021. In all .txi and .texi files except gpl.txi and gpl.texi in the doc/liboctave and doc/interpreter directories, change the copyright to "Octave Project Developers", the same as used for other source files. Update copyright notices for 2022 (not done since 2019). For gpl.txi and gpl.texi, change the copyright notice to be "Free Software Foundation, Inc." and leave the date at 2007 only because this file only contains the text of the GPL, not anything created by the Octave Project Developers. Add Paul Thomas to contributors.in.
author John W. Eaton <jwe@octave.org>
date Tue, 28 Dec 2021 18:22:40 -0500
parents 7854d5752dd2
children 5d3faba0342e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29359
diff changeset
3 ## Copyright (C) 1995-2022 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/>.
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
7 ##
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
8 ## This file is part of Octave.
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
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
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
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: 22737
diff changeset
13 ## (at your option) any later version.
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
14 ##
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
15 ## Octave is distributed in the hope that it will be useful, but
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
16 ## WITHOUT ANY WARRANTY; without even the implied warranty of
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22737
diff changeset
18 ## GNU General Public License for more details.
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
19 ##
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
20 ## You should have received a copy of the GNU General Public License
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 6046
diff changeset
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 ########################################################################
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
25
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
26 ## -*- texinfo -*-
20852
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
27 ## @deftypefn {} {} polyout (@var{c})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
28 ## @deftypefnx {} {} polyout (@var{c}, @var{x})
516bb87ea72e 2015 Code Sprint: remove class of function from docstring for all m-files.
Rik <rik@octave.org>
parents: 20165
diff changeset
29 ## @deftypefnx {} {@var{str} =} polyout (@dots{})
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
30 ## Display a formatted version of the polynomial @var{c}.
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
31 ##
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
32 ## The formatted polynomial
5016
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4898
diff changeset
33 ## @tex
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4898
diff changeset
34 ## $$ c(x) = c_1 x^n + \ldots + c_n x + c_{n+1} $$
bdbee5282954 [project @ 2004-09-22 02:50:35 by jwe]
jwe
parents: 4898
diff changeset
35 ## @end tex
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8286
diff changeset
36 ## @ifnottex
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
37 ##
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
38 ## @example
14327
4d917a6a858b doc: Use Octave coding conventions in @example blocks of docstrings.
Rik <octave@nomad.inbox5.com>
parents: 14138
diff changeset
39 ## c(x) = c(1) * x^n + @dots{} + c(n) x + c(n+1)
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
40 ## @end example
10821
693e22af08ae Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents: 10687
diff changeset
41 ##
8517
81d6ab3ac93c Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents: 8286
diff changeset
42 ## @end ifnottex
20165
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
43 ## is returned as a string or written to the screen if @code{nargout} is zero.
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
44 ##
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
45 ## The second argument @var{x} specifies the variable name to use for each term
f1d0f506ee78 doc: Update more docstrings to have one sentence summary as first line.
Rik <rik@octave.org>
parents: 19697
diff changeset
46 ## and defaults to the string @qcode{"s"}.
14104
614505385171 doc: Overhaul docstrings for polynomial functions.
Rik <octave@nomad.inbox5.com>
parents: 13963
diff changeset
47 ## @seealso{polyreduce}
5642
2618a0750ae6 [project @ 2006-03-06 21:26:48 by jwe]
jwe
parents: 5443
diff changeset
48 ## @end deftypefn
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
49
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
50 function y = polyout (c, x)
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
51
28789
28de41192f3c Eliminate unneeded verification of nargin, nargout in m-files.
Rik <rik@octave.org>
parents: 27985
diff changeset
52 if (nargin < 1)
6046
34f96dd5441b [project @ 2006-10-10 16:10:25 by jwe]
jwe
parents: 5642
diff changeset
53 print_usage ();
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
54 endif
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
55
4030
22bd65326ec1 [project @ 2002-08-09 18:58:13 by jwe]
jwe
parents: 3457
diff changeset
56 if (! isvector (c))
8685
983ac67dc3d4 polyout.m: additional style fixes
John W. Eaton <jwe@octave.org>
parents: 8684
diff changeset
57 error ("polyout: first argument must be a vector");
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
58 endif
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3424
diff changeset
59
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
60 if (nargin == 1)
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
61 x = "s";
8684
6d15bc6c4c15 polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents: 8517
diff changeset
62 elseif (! ischar (x))
8685
983ac67dc3d4 polyout.m: additional style fixes
John W. Eaton <jwe@octave.org>
parents: 8684
diff changeset
63 error ("polyout: second argument must be a string");
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
64 endif
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
65
8684
6d15bc6c4c15 polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents: 8517
diff changeset
66 n = length (c);
22737
7abc25e6206a maint: Clean up code base to follow Octave coding conventions.
Rik <rik@octave.org>
parents: 22323
diff changeset
67 if (n > 0)
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
68 n1 = n+1;
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
69
4898
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
70 tmp = coeff (c(1));
3457
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3426
diff changeset
71 for ii = 2:n
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3426
diff changeset
72 if (real (c(ii)) < 0)
10549
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
73 ns = " - ";
95c3e38098bf Untabify .m scripts
Rik <code@nomad.inbox5.com>
parents: 10224
diff changeset
74 c(ii) = -c(ii);
3457
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3426
diff changeset
75 else
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3426
diff changeset
76 ns = " + ";
e031284eea27 [project @ 2000-01-19 08:49:56 by jwe]
jwe
parents: 3426
diff changeset
77 endif
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
78
4898
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
79 tmp = sprintf ("%s*%s^%d%s%s", tmp, x, n1-ii, ns, coeff (c(ii)));
3426
f8dde1807dee [project @ 2000-01-13 08:40:00 by jwe]
jwe
parents: 3424
diff changeset
80
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
81 endfor
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
82 else
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
83 tmp = " ";
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
84 endif
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
85
14868
5d3a684236b0 maint: Use Octave coding conventions for cuddling parentheses in scripts directory
Rik <octave@nomad.inbox5.com>
parents: 14363
diff changeset
86 if (nargout == 0)
11589
b0084095098e missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents: 11523
diff changeset
87 disp (tmp);
3424
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
88 else
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
89 y = tmp;
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
90 endif
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
91
61e40232a4e8 [project @ 2000-01-13 07:19:43 by jwe]
jwe
parents:
diff changeset
92 endfunction
4898
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
93
8684
6d15bc6c4c15 polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents: 8517
diff changeset
94 function str = coeff (c)
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
95
4898
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
96 if (imag (c))
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
97 if (real (c))
8684
6d15bc6c4c15 polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents: 8517
diff changeset
98 str = sprintf ("(%s)", num2str (c, 5));
4898
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
99 else
8684
6d15bc6c4c15 polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents: 8517
diff changeset
100 str = num2str (c, 5);
4898
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
101 endif
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
102 else
8684
6d15bc6c4c15 polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents: 8517
diff changeset
103 str = num2str (c, 5);
4898
8fd9495f5054 [project @ 2004-06-04 13:29:33 by jwe]
jwe
parents: 4030
diff changeset
104 endif
21758
ffad2baa90f7 maint: Use newlines to make code more readable.
Rik <rik@octave.org>
parents: 20852
diff changeset
105
8684
6d15bc6c4c15 polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents: 8517
diff changeset
106 endfunction
12804
a44ec6d33cc9 codesprint: Wrote 5 tests for polyout.m
David Wells <drwells@vt.edu>
parents: 11589
diff changeset
107
14363
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
108
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
109 %!assert (polyout ([3 2 1]), "3*s^2 + 2*s^1 + 1")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
110 %!assert (polyout ([3 2 1], "x"), "3*x^2 + 2*x^1 + 1")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
111 %!assert (polyout ([3 2 1], "wxyz"), "3*wxyz^2 + 2*wxyz^1 + 1")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
112 %!assert (polyout ([5 4 3 2 1], "1"),"5*1^4 + 4*1^3 + 3*1^2 + 2*1^1 + 1")
f3d52523cde1 Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents: 14327
diff changeset
113
12804
a44ec6d33cc9 codesprint: Wrote 5 tests for polyout.m
David Wells <drwells@vt.edu>
parents: 11589
diff changeset
114 %!error polyout ([])