3424
|
1 ## Copyright (C) 1995, 1998 Auburn University. All rights reserved. |
|
2 ## |
|
3 ## This file is part of Octave. |
|
4 ## |
|
5 ## Octave is free software; you can redistribute it and/or modify it |
|
6 ## under the terms of the GNU General Public License as published by the |
|
7 ## Free Software Foundation; either version 2, or (at your option) any |
|
8 ## later version. |
|
9 ## |
|
10 ## Octave is distributed in the hope that it will be useful, but WITHOUT |
|
11 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 ## for more details. |
|
14 ## |
|
15 ## You should have received a copy of the GNU General Public License |
|
16 ## along with Octave; see the file COPYING. If not, write to the Free |
|
17 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. |
|
18 |
|
19 ## -*- texinfo -*- |
3457
|
20 ## @deftypefn {Function File} polyout (@var{c}, @var{x}) |
|
21 ## Write formatted polynomial |
3424
|
22 ## @example |
|
23 ## c(x) = c(1) * x^n + ... + c(n) x + c(n+1) |
|
24 ## @end example |
3457
|
25 ## and return it as a string or write it to the screen (if |
|
26 ## @var{nargout} is zero). |
3424
|
27 ## @var{x} defaults to the string @code{"s"} |
|
28 ## @end deftypefn |
3426
|
29 ## @seealso{polyval, polyvalm, poly, roots, conv, deconv, residue, |
3424
|
30 ## filter, polyderiv, and polyinteg} |
|
31 |
|
32 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
33 ## Created: May 1995 |
|
34 ## Nov 1998: Correctly handles complex coefficients |
3426
|
35 |
3424
|
36 function y = polyout (c, x) |
|
37 |
3457
|
38 if (nargin < 1) || (nargin > 2) || (nargout < 0) || (nargout > 1) |
|
39 usage("polyout (c, x)"); |
3424
|
40 endif |
|
41 |
3457
|
42 if (! is_vector (c)) |
3424
|
43 error("polyout: first argument must be a vector"); |
|
44 endif |
3426
|
45 |
3424
|
46 if (nargin == 1) |
|
47 x = "s"; |
3457
|
48 elseif (! isstr(x)) |
3424
|
49 error("polyout: second argument must be a string"); |
|
50 endif |
|
51 |
|
52 n = length(c); |
|
53 if(n > 0) |
|
54 n1 = n+1; |
|
55 |
3457
|
56 if (imag (c(1))) |
|
57 tmp = com2str(c(1)) |
|
58 else |
|
59 tmp = num2str(c(1)); |
|
60 endif |
3424
|
61 |
3457
|
62 for ii = 2:n |
|
63 if (real (c(ii)) < 0) |
|
64 ns = " - "; |
|
65 c(ii) = -c(ii); |
|
66 else |
|
67 ns = " + "; |
|
68 endif |
3424
|
69 |
3457
|
70 if (imag (c(ii))) |
|
71 nstr = sprintf ("(%s)", com2str (c(ii))); |
|
72 else |
|
73 nstr = num2str (c(ii)); |
|
74 endif |
3424
|
75 |
3457
|
76 tmp = sprintf ("%s*%s^%d%s%s", tmp, x, n1-ii, ns, nstr); |
3426
|
77 |
3424
|
78 endfor |
|
79 else |
|
80 tmp = " "; |
|
81 endif |
|
82 |
|
83 if(nargout == 0) |
|
84 disp(tmp) |
|
85 else |
|
86 y = tmp; |
|
87 endif |
|
88 |
|
89 endfunction |