Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyout.m @ 8334:70dd33450061
Update manual citation
author | David Bateman <dbateman@free.fr> |
---|---|
date | Tue, 18 Nov 2008 22:55:13 +0100 |
parents | 6f2d95255911 |
children | 81d6ab3ac93c |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1995, 1998, 2000, 2002, 2004, 2005, 2006, 2007 |
2 ## Auburn University. All rights reserved. | |
3424 | 3 ## |
4 ## This file is part of Octave. | |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7016 | 7 ## under the terms of the GNU General Public License as published by |
8 ## the Free Software Foundation; either version 3 of the License, or (at | |
9 ## your option) any later version. | |
3424 | 10 ## |
7016 | 11 ## Octave is distributed in the hope that it will be useful, but |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
3424 | 15 ## |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
3424 | 19 |
20 ## -*- texinfo -*- | |
5016 | 21 ## @deftypefn {Function File} {} polyout (@var{c}, @var{x}) |
3457 | 22 ## Write formatted polynomial |
5016 | 23 ## @iftex |
24 ## @tex | |
25 ## $$ c(x) = c_1 x^n + \ldots + c_n x + c_{n+1} $$ | |
26 ## @end tex | |
27 ## @end iftex | |
28 ## @ifinfo | |
3424 | 29 ## @example |
30 ## c(x) = c(1) * x^n + ... + c(n) x + c(n+1) | |
31 ## @end example | |
5016 | 32 ## @end ifinfo |
3457 | 33 ## and return it as a string or write it to the screen (if |
34 ## @var{nargout} is zero). | |
5016 | 35 ## @var{x} defaults to the string @code{"s"}. |
3426 | 36 ## @seealso{polyval, polyvalm, poly, roots, conv, deconv, residue, |
8286
6f2d95255911
fix @seealso references to point to existing anchors
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7017
diff
changeset
|
37 ## filter, polyderiv, polyinteg} |
5642 | 38 ## @end deftypefn |
3424 | 39 |
40 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> | |
41 ## Created: May 1995 | |
42 ## Nov 1998: Correctly handles complex coefficients | |
3426 | 43 |
3424 | 44 function y = polyout (c, x) |
45 | |
3457 | 46 if (nargin < 1) || (nargin > 2) || (nargout < 0) || (nargout > 1) |
6046 | 47 print_usage (); |
3424 | 48 endif |
49 | |
4030 | 50 if (! isvector (c)) |
3424 | 51 error("polyout: first argument must be a vector"); |
52 endif | |
3426 | 53 |
3424 | 54 if (nargin == 1) |
55 x = "s"; | |
5443 | 56 elseif (! ischar(x)) |
3424 | 57 error("polyout: second argument must be a string"); |
58 endif | |
59 | |
60 n = length(c); | |
61 if(n > 0) | |
62 n1 = n+1; | |
63 | |
64 | |
4898 | 65 tmp = coeff (c(1)); |
3457 | 66 for ii = 2:n |
67 if (real (c(ii)) < 0) | |
68 ns = " - "; | |
69 c(ii) = -c(ii); | |
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) | |
82 disp(tmp) | |
83 else | |
84 y = tmp; | |
85 endif | |
86 | |
87 endfunction | |
4898 | 88 |
89 function str = coeff(c) | |
90 if (imag (c)) | |
91 if (real (c)) | |
92 str = sprintf ("(%s)", com2str(c)); | |
93 else | |
94 str = com2str(c); | |
95 endif | |
96 else | |
97 str = num2str(c); | |
98 endif | |
99 |