Back to index

texmacs  1.0.7.15
polyout.m
Go to the documentation of this file.
00001 ## Copyright (C) 1995, 1998 Auburn University.  All rights reserved.
00002 ##
00003 ## This file is part of Octave.
00004 ##
00005 ## Octave is free software; you can redistribute it and/or modify it
00006 ## under the terms of the GNU General Public License as published by the
00007 ## Free Software Foundation; either version 2, or (at your option) any
00008 ## later version.
00009 ##
00010 ## Octave is distributed in the hope that it will be useful, but WITHOUT
00011 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00013 ## for more details.
00014 ##
00015 ## You should have received a copy of the GNU General Public License
00016 ## along with Octave; see the file COPYING.  If not, write to the Free
00017 ## Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA.
00018 
00019 ## -*- texinfo -*-
00020 ## @deftypefn {Function File} polyout (@var{c}, @var{x})
00021 ## Write formatted polynomial
00022 ## @example
00023 ##    c(x) = c(1) * x^n + ... + c(n) x + c(n+1)
00024 ## @end example
00025 ##  and return it as a string or write it to the screen (if
00026 ##  @var{nargout} is zero).
00027 ##  @var{x} defaults to the string @code{"s"}
00028 ## @end deftypefn
00029 ## @seealso{polyval, polyvalm, poly, roots, conv, deconv, residue,
00030 ## filter, polyderiv, and polyinteg}
00031 
00032 ## Author: A. S. Hodel <a.s.hodel@eng.auburn.edu>
00033 ## Created: May 1995
00034 ## Nov 1998: Correctly handles complex coefficients
00035 ## Sep 2002: Added LaTeX output support for TeXmacs M. Graffam <mikegraffam@yahoo.com>
00036 
00037 function y = polyout (c, x)
00038 
00039   if (nargin < 1) || (nargin > 2) || (nargout < 0) || (nargout > 1)
00040     usage("polyout (c, x)");
00041   endif
00042 
00043   if (! is_vector (c))
00044     error("polyout: first argument must be a vector");
00045   endif
00046 
00047   if (nargin == 1)
00048     x = "s";
00049   elseif (! isstr(x))
00050     error("polyout: second argument must be a string");
00051   endif
00052 
00053   n = length(c);
00054   if(n > 0)
00055     n1 = n+1;
00056 
00057     if (imag (c(1)))
00058       tmp = com2str(c(1))
00059     else
00060       tmp = num2str(c(1));
00061     endif
00062 
00063     if (length(getenv("TEXMACS_PATH")) > 0)
00064        mul=" \\cdot ";
00065     else
00066        mul="*";
00067     endif
00068 
00069     for ii = 2:n
00070       if (real (c(ii)) < 0)
00071        ns = " - ";
00072        c(ii) = -c(ii);
00073       else
00074         ns = " + ";
00075       endif
00076 
00077       if (imag (c(ii)))
00078        nstr = sprintf ("(%s)", com2str (c(ii)));
00079       else
00080         nstr = num2str (c(ii));
00081       endif
00082 
00083       tmp = sprintf ("%s%s%s^%d%s%s", tmp, mul, x, n1-ii, ns, nstr);
00084 
00085     endfor
00086   else
00087     tmp = " ";
00088   endif
00089 
00090   if (length(getenv("TEXMACS_PATH")) > 0)
00091     tmp=[sprintf("%clatex:$",2), tmp, sprintf("$%c",5)];
00092   endif
00093 
00094   if(nargout == 0)
00095     disp(tmp)
00096   else
00097     y = tmp;
00098   endif
00099 
00100 endfunction