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 -*- |
|
20 ## @deftypefn {Function File} {@var{y} =} polyout (@var{c}@{, @var{x}@}) |
|
21 ## write formatted polynomial |
|
22 ## @example |
|
23 ## c(x) = c(1) * x^n + ... + c(n) x + c(n+1) |
|
24 ## @end example |
|
25 ## to string @var{y} or to the screen (if @var{y} is omitted) |
|
26 ## @var{x} defaults to the string @code{"s"} |
|
27 ## @end deftypefn |
|
28 ## @seealso{polyval, polyvalm, poly, roots, conv, deconv, residue, |
|
29 ## filter, polyderiv, and polyinteg} |
|
30 |
|
31 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> |
|
32 ## Created: May 1995 |
|
33 ## Nov 1998: Correctly handles complex coefficients |
|
34 |
|
35 function y = polyout (c, x) |
|
36 |
|
37 if (nargin < 1 ) || (nargin > 2) || (nargout < 0 ) || (nargout > 1) |
|
38 usage("[y = ] polyout(c,[x])"); |
|
39 endif |
|
40 |
|
41 if (!is_vector(c)) |
|
42 error("polyout: first argument must be a vector"); |
|
43 endif |
|
44 |
|
45 if (nargin == 1) |
|
46 x = "s"; |
|
47 elseif( ! isstr(x) ) |
|
48 error("polyout: second argument must be a string"); |
|
49 endif |
|
50 |
|
51 n = length(c); |
|
52 if(n > 0) |
|
53 n1 = n+1; |
|
54 |
|
55 if( imag(c(1)) ) tmp = com2str(c(1)) |
|
56 else tmp = num2str(c(1)); endif |
|
57 |
|
58 for ii=2:n |
|
59 if(real(c(ii)) < 0) ns = " - "; c(ii) = -c(ii); |
|
60 else ns = " + "; endif |
|
61 |
|
62 if( imag(c(ii)) ) nstr = sprintf("(%s)",com2str(c(ii)) ); |
|
63 else nstr = num2str(c(ii)); endif |
|
64 |
|
65 tmp = sprintf("%s*%s^%d%s%s",tmp,x,n1-ii,ns,nstr); |
|
66 |
|
67 endfor |
|
68 else |
|
69 tmp = " "; |
|
70 endif |
|
71 |
|
72 if(nargout == 0) |
|
73 disp(tmp) |
|
74 else |
|
75 y = tmp; |
|
76 endif |
|
77 |
|
78 endfunction |