1 ## Copyright (C) 1995-2012 Auburn University. All rights reserved.
3 ## This file is part of Octave.
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
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
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.
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING. If not, see
17 ## <http://www.gnu.org/licenses/>.
20 ## @deftypefn {Function File} {} polyout (@var{c})
21 ## @deftypefnx {Function File} {} polyout (@var{c}, @var{x})
22 ## @deftypefnx {Function File} {@var{str} =} polyout (@dots{})
23 ## Write formatted polynomial
25 ## $$ c(x) = c_1 x^n + \ldots + c_n x + c_{n+1} $$
30 ## c(x) = c(1) * x^n + @dots{} + c(n) x + c(n+1)
34 ## and return it as a string or write it to the screen (if @var{nargout} is
35 ## zero). @var{x} defaults to the string @code{"s"}.
36 ## @seealso{polyreduce}
39 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu>
41 ## Nov 1998: Correctly handles complex coefficients
43 function y = polyout (c, x)
45 if (nargin < 1) || (nargin > 2) || (nargout < 0) || (nargout > 1)
50 error ("polyout: first argument must be a vector");
56 error ("polyout: second argument must be a string");
72 tmp = sprintf ("%s*%s^%d%s%s", tmp, x, n1-ii, ns, coeff (c(ii)));
87 function str = coeff (c)
90 str = sprintf ("(%s)", num2str (c, 5));
99 %!assert (polyout ([3 2 1]), '3*s^2 + 2*s^1 + 1')
100 %!assert (polyout ([3 2 1], 'x'), '3*x^2 + 2*x^1 + 1')
101 %!assert (polyout ([3 2 1], 'wxyz'), '3*wxyz^2 + 2*wxyz^1 + 1')
102 %!assert (polyout ([5 4 3 2 1], '1'),'5*1^4 + 4*1^3 + 3*1^2 + 2*1^1 + 1')