Mercurial > octave
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 |
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 | 7 ## |
8 ## This file is part of Octave. | |
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 | 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 | 14 ## |
7016 | 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:
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 | 19 ## |
20 ## You should have received a copy of the GNU General Public License | |
7016 | 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 | 25 |
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 | 33 ## @tex |
34 ## $$ c(x) = c_1 x^n + \ldots + c_n x + c_{n+1} $$ | |
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 | 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 | 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 | 48 ## @end deftypefn |
3424 | 49 |
50 function y = polyout (c, x) | |
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 | 53 print_usage (); |
3424 | 54 endif |
55 | |
4030 | 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 | 58 endif |
3426 | 59 |
3424 | 60 if (nargin == 1) |
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 | 64 endif |
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 | 68 n1 = n+1; |
69 | |
4898 | 70 tmp = coeff (c(1)); |
3457 | 71 for ii = 2:n |
72 if (real (c(ii)) < 0) | |
10549 | 73 ns = " - "; |
74 c(ii) = -c(ii); | |
3457 | 75 else |
76 ns = " + "; | |
77 endif | |
3424 | 78 |
4898 | 79 tmp = sprintf ("%s*%s^%d%s%s", tmp, x, n1-ii, ns, coeff (c(ii))); |
3426 | 80 |
3424 | 81 endfor |
82 else | |
83 tmp = " "; | |
84 endif | |
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 | 88 else |
89 y = tmp; | |
90 endif | |
91 | |
92 endfunction | |
4898 | 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 | 96 if (imag (c)) |
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 | 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 | 101 endif |
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 | 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 ([]) |