Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyout.m @ 12541:dd2c70b30f28
Add tests for ifftshift.m
author | Robert T. Short <octave@phaselockedsystems.com.com> |
---|---|
date | Sat, 26 Mar 2011 06:50:12 -0700 |
parents | b0084095098e |
children | a44ec6d33cc9 |
rev | line source |
---|---|
11523 | 1 ## Copyright (C) 1995-2011 Auburn University. All rights reserved. |
3424 | 2 ## |
3 ## This file is part of Octave. | |
4 ## | |
5 ## Octave is free software; you can redistribute it and/or modify it | |
7016 | 6 ## under the terms of the GNU General Public License as published by |
7 ## the Free Software Foundation; either version 3 of the License, or (at | |
8 ## your option) any later version. | |
3424 | 9 ## |
7016 | 10 ## Octave is distributed in the hope that it will be useful, but |
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 ## General Public License for more details. | |
3424 | 14 ## |
15 ## You should have received a copy of the GNU General Public License | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
3424 | 18 |
19 ## -*- texinfo -*- | |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
20 ## @deftypefn {Function File} {} polyout (@var{c}) |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
21 ## @deftypefnx {Function File} {} polyout (@var{c}, @var{x}) |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
22 ## @deftypefnx {Function File} {@var{str} =} polyout (@dots{}) |
3457 | 23 ## Write formatted polynomial |
5016 | 24 ## @tex |
25 ## $$ c(x) = c_1 x^n + \ldots + c_n x + c_{n+1} $$ | |
26 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
27 ## @ifnottex |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
28 ## |
3424 | 29 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
30 ## c(x) = c(1) * x^n + @dots{} + c(n) x + c(n+1) |
3424 | 31 ## @end example |
10821
693e22af08ae
Grammarcheck documentation of m-files
Rik <octave@nomad.inbox5.com>
parents:
10687
diff
changeset
|
32 ## |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
33 ## @end ifnottex |
10687
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
34 ## and return it as a string or write it to the screen (if |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
35 ## @var{nargout} is zero). |
a8ce6bdecce5
Improve documentation strings.
Rik <octave@nomad.inbox5.com>
parents:
10549
diff
changeset
|
36 ## @var{x} defaults to the string @code{"s"}. |
3426 | 37 ## @seealso{polyval, polyvalm, poly, roots, conv, deconv, residue, |
10224
f6e0404421f4
point to polyint in @seealso, not polyinteg
John W. Eaton <jwe@octave.org>
parents:
9211
diff
changeset
|
38 ## filter, polyderiv, polyint} |
5642 | 39 ## @end deftypefn |
3424 | 40 |
41 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> | |
42 ## Created: May 1995 | |
43 ## Nov 1998: Correctly handles complex coefficients | |
3426 | 44 |
3424 | 45 function y = polyout (c, x) |
46 | |
3457 | 47 if (nargin < 1) || (nargin > 2) || (nargout < 0) || (nargout > 1) |
6046 | 48 print_usage (); |
3424 | 49 endif |
50 | |
4030 | 51 if (! isvector (c)) |
8685
983ac67dc3d4
polyout.m: additional style fixes
John W. Eaton <jwe@octave.org>
parents:
8684
diff
changeset
|
52 error ("polyout: first argument must be a vector"); |
3424 | 53 endif |
3426 | 54 |
3424 | 55 if (nargin == 1) |
56 x = "s"; | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
57 elseif (! ischar (x)) |
8685
983ac67dc3d4
polyout.m: additional style fixes
John W. Eaton <jwe@octave.org>
parents:
8684
diff
changeset
|
58 error ("polyout: second argument must be a string"); |
3424 | 59 endif |
60 | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
61 n = length (c); |
3424 | 62 if(n > 0) |
63 n1 = n+1; | |
64 | |
4898 | 65 tmp = coeff (c(1)); |
3457 | 66 for ii = 2:n |
67 if (real (c(ii)) < 0) | |
10549 | 68 ns = " - "; |
69 c(ii) = -c(ii); | |
3457 | 70 else |
71 ns = " + "; | |
72 endif | |
3424 | 73 |
4898 | 74 tmp = sprintf ("%s*%s^%d%s%s", tmp, x, n1-ii, ns, coeff (c(ii))); |
3426 | 75 |
3424 | 76 endfor |
77 else | |
78 tmp = " "; | |
79 endif | |
80 | |
81 if(nargout == 0) | |
11589
b0084095098e
missing semicolons in script files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
82 disp (tmp); |
3424 | 83 else |
84 y = tmp; | |
85 endif | |
86 | |
87 endfunction | |
4898 | 88 |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
89 function str = coeff (c) |
4898 | 90 if (imag (c)) |
91 if (real (c)) | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
92 str = sprintf ("(%s)", num2str (c, 5)); |
4898 | 93 else |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
94 str = num2str (c, 5); |
4898 | 95 endif |
96 else | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
97 str = num2str (c, 5); |
4898 | 98 endif |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
99 endfunction |