Mercurial > hg > octave-nkf
annotate scripts/polynomial/polyout.m @ 10224:f6e0404421f4
point to polyint in @seealso, not polyinteg
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 29 Jan 2010 12:52:32 -0500 |
parents | f0c3d3fc4903 |
children | 95c3e38098bf |
rev | line source |
---|---|
8920 | 1 ## Copyright (C) 1995, 1998, 2000, 2002, 2004, 2005, 2006, 2007, 2008, 2009 |
7017 | 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 ## @tex |
24 ## $$ c(x) = c_1 x^n + \ldots + c_n x + c_{n+1} $$ | |
25 ## @end tex | |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
26 ## @ifnottex |
3424 | 27 ## @example |
9051
1bf0ce0930be
Grammar check TexInfo in all .m files
Rik <rdrider0-list@yahoo.com>
parents:
8920
diff
changeset
|
28 ## c(x) = c(1) * x^n + @dots{} + c(n) x + c(n+1) |
3424 | 29 ## @end example |
8517
81d6ab3ac93c
Allow documentation tobe built for other formats than tex and info
sh@sh-laptop
parents:
8286
diff
changeset
|
30 ## @end ifnottex |
3457 | 31 ## and return it as a string or write it to the screen (if |
32 ## @var{nargout} is zero). | |
5016 | 33 ## @var{x} defaults to the string @code{"s"}. |
3426 | 34 ## @seealso{polyval, polyvalm, poly, roots, conv, deconv, residue, |
10224
f6e0404421f4
point to polyint in @seealso, not polyinteg
John W. Eaton <jwe@octave.org>
parents:
9211
diff
changeset
|
35 ## filter, polyderiv, polyint} |
5642 | 36 ## @end deftypefn |
3424 | 37 |
38 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu> | |
39 ## Created: May 1995 | |
40 ## Nov 1998: Correctly handles complex coefficients | |
3426 | 41 |
3424 | 42 function y = polyout (c, x) |
43 | |
3457 | 44 if (nargin < 1) || (nargin > 2) || (nargout < 0) || (nargout > 1) |
6046 | 45 print_usage (); |
3424 | 46 endif |
47 | |
4030 | 48 if (! isvector (c)) |
8685
983ac67dc3d4
polyout.m: additional style fixes
John W. Eaton <jwe@octave.org>
parents:
8684
diff
changeset
|
49 error ("polyout: first argument must be a vector"); |
3424 | 50 endif |
3426 | 51 |
3424 | 52 if (nargin == 1) |
53 x = "s"; | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
54 elseif (! ischar (x)) |
8685
983ac67dc3d4
polyout.m: additional style fixes
John W. Eaton <jwe@octave.org>
parents:
8684
diff
changeset
|
55 error ("polyout: second argument must be a string"); |
3424 | 56 endif |
57 | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
58 n = length (c); |
3424 | 59 if(n > 0) |
60 n1 = n+1; | |
61 | |
4898 | 62 tmp = coeff (c(1)); |
3457 | 63 for ii = 2:n |
64 if (real (c(ii)) < 0) | |
65 ns = " - "; | |
66 c(ii) = -c(ii); | |
67 else | |
68 ns = " + "; | |
69 endif | |
3424 | 70 |
4898 | 71 tmp = sprintf ("%s*%s^%d%s%s", tmp, x, n1-ii, ns, coeff (c(ii))); |
3426 | 72 |
3424 | 73 endfor |
74 else | |
75 tmp = " "; | |
76 endif | |
77 | |
78 if(nargout == 0) | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
79 disp (tmp) |
3424 | 80 else |
81 y = tmp; | |
82 endif | |
83 | |
84 endfunction | |
4898 | 85 |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
86 function str = coeff (c) |
4898 | 87 if (imag (c)) |
88 if (real (c)) | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
89 str = sprintf ("(%s)", num2str (c, 5)); |
4898 | 90 else |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
91 str = num2str (c, 5); |
4898 | 92 endif |
93 else | |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
94 str = num2str (c, 5); |
4898 | 95 endif |
8684
6d15bc6c4c15
polyout.m: Replace com2str with num2str.
Thomas D. Dean <tomdean@speakeasy.org>
parents:
8517
diff
changeset
|
96 endfunction |