Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyout.m @ 8684:6d15bc6c4c15
polyout.m: Replace com2str with num2str.
author | Thomas D. Dean <tomdean@speakeasy.org> |
---|---|
date | Thu, 05 Feb 2009 13:42:29 -0500 |
parents | 81d6ab3ac93c |
children | 983ac67dc3d4 |
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 | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
28 ## @ifnottex |
3424 | 29 ## @example |
30 ## c(x) = c(1) * x^n + ... + c(n) x + c(n+1) | |
31 ## @end example | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
32 ## @end ifnottex |
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"; | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
56 elseif (! ischar (x)) |
3424 | 57 error("polyout: second argument must be a string"); |
58 endif | |
59 | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
60 n = length (c); |
3424 | 61 if(n > 0) |
62 n1 = n+1; | |
63 | |
4898 | 64 tmp = coeff (c(1)); |
3457 | 65 for ii = 2:n |
66 if (real (c(ii)) < 0) | |
67 ns = " - "; | |
68 c(ii) = -c(ii); | |
69 else | |
70 ns = " + "; | |
71 endif | |
3424 | 72 |
4898 | 73 tmp = sprintf ("%s*%s^%d%s%s", tmp, x, n1-ii, ns, coeff (c(ii))); |
3426 | 74 |
3424 | 75 endfor |
76 else | |
77 tmp = " "; | |
78 endif | |
79 | |
80 if(nargout == 0) | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
81 disp (tmp) |
3424 | 82 else |
83 y = tmp; | |
84 endif | |
85 | |
86 endfunction | |
4898 | 87 |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
88 function str = coeff (c) |
4898 | 89 if (imag (c)) |
90 if (real (c)) | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
91 str = sprintf ("(%s)", num2str (c, 5)); |
4898 | 92 else |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
93 str = num2str (c, 5); |
4898 | 94 endif |
95 else | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
96 str = num2str (c, 5); |
4898 | 97 endif |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
98 endfunction |