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

  1. function [] = zgrid(zeta,wn,s)
  2. %ZGRID    Generate z-plane grid lines for a root locus or pole-zero map.
  3. %
  4. %    ZGRID generates a grid over an existing discrete z-plane root 
  5. %    locus or pole-zero map.  Lines of constant damping factor (zeta)
  6. %    and natural frequency (Wn) are drawn in within the unit Z-plane 
  7. %    circle.
  8. %
  9. %    ZGRID('new') clears the graphics screen before plotting the 
  10. %    z-plane grid and sets the HOLD ON so that the root locus or pole-
  11. %    zero map can be plotted over the grid using (for example):
  12. %
  13. %        zgrid('new')
  14. %        rlocus(num,den) or pzmap(num,den)
  15. %
  16. %    ZGRID(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.  ZGRID(Z,Wn,'new') clears the screen first.
  19. %
  20. %    See also: RLOCUS, SGRID, and PZMAP.
  21.  
  22. %    Marc Ullman   May 27, 1987
  23. %    Revised JNL 7-10-87, CMT 7-13-90, ACWG 6-21-92
  24. %    Copyright (c) 1986-93 by the MathWorks, Inc.
  25.  
  26. error(nargchk(0,3,nargin));
  27.  
  28. status = ishold;
  29.  
  30. if nargin==0,    % Plot on existing graph
  31.     zeta = 0:.1:.9;
  32.     wn = 0:pi/10:pi;
  33.     axis(axis)
  34.     hold on
  35.  
  36. elseif nargin==1, % Clear screen then plot standard grid
  37.     zeta = 0:.1:.9;
  38.     wn = 0:pi/10:pi;
  39.     hold off
  40.  
  41. elseif nargin==2, % Use zeta and wn specified
  42.     hold on
  43.  
  44. elseif nargin==3, % Clear screen and use zeta and wn specified
  45.     hold off
  46.  
  47. end
  48.  
  49. % Plot Unit circle
  50. t=0:.1:6.3;
  51. plot(sin(t),cos(t),'w-')
  52. hold on
  53.  
  54. % Plot damping lines
  55. if ~isempty(zeta),
  56.     m = tan(asin(zeta));
  57.     zz = exp((0:pi/20:pi)'*(-m + sqrt(-1)*ones(1,length(m))));
  58.     plot(real(zz),imag(zz),'w:',real(zz),-imag(zz),'w:');
  59.     hold on
  60. end
  61.  
  62. % Plot natural frequency lines
  63. if ~isempty(wn),
  64.     e_itheta = exp(sqrt(-1)*(pi/2:pi/20:pi)');
  65.     e_r = exp(wn);
  66.     zw = (ones(length(e_itheta), 1)*e_r).^(e_itheta*ones(1,length(e_r)));
  67.     plot(real(zw),imag(zw),'w:',real(zw),-imag(zw),'w:');
  68. end
  69.  
  70. % Return hold to previous status
  71. if ((nargin==0)|(nargin==2))&(~status), hold off, end
  72.  
  73.