home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l455 / 2.ddi / MUTOOLS1.DI$ / VROOTS.M < prev    next >
Encoding:
Text File  |  1993-03-11  |  1.4 KB  |  53 lines

  1. % function out = vroots(mat)
  2. %
  3. %   If MAT is a VARYING matrix, with either
  4. %   1 row or 1 column, then OUT is a VARYING matrix
  5. %   of the roots of the polynomial represented
  6. %   by the vector. VROOTS works with identically to
  7. %   the MATLAB function ROOTS, however it works
  8. %   with VARYING matrices also.
  9. %
  10. %   See also: DET, POLY, ROOTS, VDET, and VPOLY.
  11.  
  12. function out = vroots(mat)
  13.   if nargin == 0
  14.     disp('usage: out = vroots(mat)')
  15.     return
  16.   end
  17.   [mtype,mrows,mcols,mnum] = minfo(mat);
  18.   if mrows ~= 1 & mcols ~= 1
  19.     error(['input to VROOTS should be a vector']);
  20.     return
  21.   end
  22.   if mrows == 1 & mcols == 1
  23.     out = [];
  24.     return
  25.   end
  26.   if mtype == 'cons'
  27.     out = roots(mat);
  28.   elseif mtype == 'vary'
  29.     indv = mat(1:mnum,mcols+1);
  30.     npts = mnum;
  31.     nrout = max([mrows mcols]) - 1;;
  32.     ncout = 1;
  33.     out = zeros(npts*nrout,ncout);
  34.     fone = (npts+1)*mrows;
  35.     pone = 1:mrows:fone;
  36.     ponem1 = pone(2:npts+1) - 1;
  37.     fout = (npts+1)*nrout;
  38.     pout = 1:nrout:fout;
  39.     poutm1 = pout(2:npts+1) - 1;
  40.     for i=1:npts
  41.       out(pout(i):poutm1(i),1:ncout) = ...
  42.          roots(mat(pone(i):ponem1(i),1:mcols));
  43.     end
  44.     out = vpck(out,indv);
  45.   elseif mtype == 'syst'
  46.     error('VROOTS is undefined for SYSTEM matrices')
  47.     return
  48.   else
  49.     out = [];
  50.   end
  51. %
  52. % Copyright MUSYN INC 1991,  All Rights Reserved
  53.