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

  1. function [] = sgrid(zeta,wn)
  2. %SGRID    Generate s-plane grid lines for a root locus or pole-zero map.
  3. %
  4. %    SGRID generates a grid over an existing continuous s-plane root 
  5. %    locus or pole-zero map.  Lines of constant damping ratio (zeta)
  6. %    and natural frequency (Wn) are drawn in.
  7. %    
  8. %    SGRID('new') clears the graphics screen before plotting the 
  9. %    s-plane grid so that the root locus or pole-zero map can be 
  10. %    plotted over the grid using (for example):
  11. %
  12. %        sgrid('new')
  13. %        hold on
  14. %        rlocus(num,den) or pzmap(num,den)
  15. %
  16. %    SGRID(Z,Wn) plots constant damping and frequency lines for the 
  17. %    damping ratios in the vector Z and the natural frequencies in the
  18. %    vector Wn.
  19. %
  20. %    See also: RLOCUS, ZGRID and PZMAP.
  21.  
  22. %    Clay M. Thompson
  23. %    Revised ACWG 6-21-92
  24. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  25.  
  26. error(nargchk(0,2,nargin));
  27.  
  28. status = ishold;
  29.  
  30. zx = 0:.01:1;
  31.  
  32. if nargin==0,    % Use existing axis limits
  33.     limits = axis;
  34.     axis('manual')
  35.     hold on
  36.  
  37.     % Round-up axis limits
  38.     
  39. %    wmax = 10 * 10 .^(floor(log10(max(abs(limits)))));
  40.     wmax = 10 .^(floor(log10(max(abs(limits)))));
  41.     dx = wmax/10;
  42.     wn= 0:dx:wmax;
  43.     zeta = [ 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 ];
  44.  
  45. elseif nargin==1,    % Standard scale
  46.     hold off
  47.     wn = 0:1:10;
  48.     zeta = [ 0 .1 .2 .3 .4 .5 .6 .7 .8 .9 1 ];
  49.  
  50. else,
  51.     hold on
  52.  
  53. end
  54.  
  55. if ~isempty(wn),  % Plot natural frequency lines
  56.     [w,z] = meshgrid(wn,zx);
  57.     re = - w .* z;
  58.     [mcols, nrows] = size(z);
  59.     im = w .* sqrt( ones(mcols, nrows) - z .* z );
  60. %        ix=find(im>limits(4)); im(ix)=ones(length(ix),1)*limits(4);
  61.     plot(re,im,'w:',re,-im,'w:');
  62.     hold on
  63. end
  64.  
  65. if ~isempty(zeta), % Plot damping lines
  66.     limits = axis;
  67.     [w,z] = meshgrid([0;wn(:);2*max(limits(:))]',zeta);
  68.     re = -w .* z;
  69.     [mcols, nrows] = size(z);
  70.     im = w .* sqrt( ones(mcols, nrows) - z .* z );
  71. %        ix=find(im>limits(4)); im(ix)=ones(length(ix),1)*limits(4);
  72.     plot(re',im','w:',re',-im','w:');
  73. end
  74.  
  75. if (nargin~=1)&(~status), hold off, end       % Return hold to previous status
  76.  
  77. % uncomment the following lines if you want damping ratio lines labeled.
  78.  
  79. % Now put wn labels on the curve
  80. %n = length(wn);
  81. %m = length(zeta);
  82. %for i = 1:m
  83. %  text(re(i,n),im(i,n),sprintf('%.3g',zeta(m-i+1)))
  84. %end
  85.  
  86.  
  87.  
  88.  
  89.