home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / octa21eb.zip / octave / SCRIPTS.ZIP / scripts.fat / control / zpout.m < prev   
Text File  |  1999-04-29  |  3KB  |  112 lines

  1. # Copyright (C) 1996 A. Scottedward Hodel 
  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. # Octave is distributed in the hope that it will be useful, but WITHOUT 
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
  11. # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
  12. # for more details.
  13. # You should have received a copy of the GNU General Public License 
  14. # along with Octave; see the file COPYING.  If not, write to the Free 
  15. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  16.  
  17. function zpout(zer,pol,k,x)
  18. #
  19. # usage: zpout(zer,pol,k,[,x])
  20. #  
  21. # print formatted zero-pole form
  22. # to the screen
  23. # x defaults to the string "s"
  24. #
  25. #  SEE ALSO: polyval, polyvalm, poly, roots, conv, deconv, residue, 
  26. #    filter, polyderv, polyintg, polyout
  27.  
  28. # Written by A. Scottedward Hodel (scotte@eng.auburn.edu) June 1995)
  29.  
  30.   save_val = implicit_str_to_num_ok;
  31.   save_empty = empty_list_elements_ok;
  32.   empty_list_elements_ok = 1;
  33.  
  34.   implicit_str_to_num_ok = 1;
  35.  
  36.   if (nargin < 3 ) | (nargin > 4) | (nargout != 0 )
  37.     usage("zpout(zer,pol,k[,x])");
  38.   endif
  39.  
  40.   if( !(is_vec(zer) | isempty(zer)) | !(is_vec(pol) | isempty(pol)) )
  41.     error("zer, pol must be vectors or empty");
  42.   endif
  43.  
  44.   if(!is_scal(k))
  45.     error("zpout: argument k must be a scalar.")
  46.   endif
  47.  
  48.   if (nargin == 3)
  49.     x = 's';
  50.   elseif( ! isstr(x) )
  51.     error("zpout: third argument must be a string");
  52.   endif
  53.  
  54.   numstring = num2str(k);
  55.  
  56.   if(length(zer))
  57.     # find roots at z,s = 0
  58.     nzr = sum(zer == 0);
  59.     if(nzr)
  60.       if(nzr > 1)
  61.         numstring = [numstring,sprintf(" %s^%d",x,nzr)];
  62.       else
  63.         numstring = [numstring,sprintf(" %s",x)];
  64.       endif
  65.     endif
  66.     zer = sortcom(-zer);
  67.     for ii=1:length(zer)
  68.       if(zer(ii) != 0)
  69.         numstring = [numstring,sprintf(" (%s %s)",x,com2str(zer(ii),1) ) ];
  70.       endif
  71.     endfor
  72.   endif
  73.  
  74.   if(length(pol))
  75.     # find roots at z,s = 0
  76.     nzr = sum(pol == 0);
  77.     if(nzr)
  78.       if(nzr > 1)
  79.         denomstring = [sprintf("%s^%d",x,nzr)];
  80.       else
  81.         denomstring = [sprintf("%s",x)];
  82.       endif
  83.     else
  84.       denomstring = " ";
  85.     endif
  86.     pol = sortcom(-pol);
  87.     for ii=1:length(pol)
  88.       if(pol(ii) != 0)
  89.         denomstring = [denomstring,sprintf(" (%s %s)",x,com2str(pol(ii),1))];
  90.       endif
  91.     endfor
  92.   endif
  93.  
  94.   len = max(length(numstring),length(denomstring));
  95.   if(len > 0)
  96.     y = strrep(blanks(len)," ","-");
  97.     disp(numstring)
  98.     if(length(denomstring))
  99.       disp(y)
  100.       disp(denomstring)
  101.     endif
  102.   else
  103.     error('zpout: empty transfer function')
  104.   end
  105.  
  106.   implicit_str_to_num_ok = save_val;
  107.   empty_list_elements_ok = save_empty;
  108.  
  109. endfunction
  110.