From fad5aea3201432365cc482a692bed56ed57f8971 Mon Sep 17 00:00:00 2001 From: Jinge Wang <45804710+HLP9135@users.noreply.github.com> Date: Fri, 26 Jul 2019 02:55:42 -0700 Subject: [PATCH] Update RLocusGui.m now compatible with zpk type input. --- RLocusGui.m | 57 +++++++++++++++++++++++++++++------------------------ 1 file changed, 31 insertions(+), 26 deletions(-) diff --git a/RLocusGui.m b/RLocusGui.m index 9cb55db..3046795 100644 --- a/RLocusGui.m +++ b/RLocusGui.m @@ -97,13 +97,18 @@ function RLocusGui_OpeningFcn(hObject, ~, handles, varargin) Sys=tf(1,[1 5 4 0]); else if ( (nargin~=1) || (~isa(varargin{1},'tf')) ), - disp(' '); - disp('Root Locus Plotter - proper usage is ''RLocusGui(Sys)'',') - disp(' where ''Sys'' is a transfer function object.'); - disp(' '); disp(' '); - close(handles.RLocusGuiFig); - close(hWait); - return + if (isa(varargin{1},'zpk')), + [n,d]=tfdata(varargin{1}); + varargin{1}=tf(n,d); + else + disp(' '); + disp('Root Locus Plotter - proper usage is ''RLocusGui(Sys)'',') + disp(' where ''Sys'' is a transfer function object.'); + disp(' '); disp(' '); + close(handles.RLocusGuiFig); + close(hWait); + return + end end Sys=varargin{1}; % Get system [n,d,tfOK]=testTF(Sys); % Check it @@ -588,7 +593,7 @@ function cbInteract_Callback(hObject, eventdata, handles) if isreal(z(i)), s=sprintf('%s %5.2g, ',s,z(i)); else - s=sprintf('%s %5.2g±%5.2gj, ',s,real(z(i)),imag(z(i))); + s=sprintf('%s %5.2g±%5.2gj, ',s,real(z(i)),imag(z(i))); i=i+1; end i=i+1; @@ -1017,8 +1022,8 @@ function pbMakeWeb_Callback(~, ~, handles) sigma=real(sump-sumz)/q; %Intersect on real axis. theta=180/q; %Angle of asymptotes -s{end+1}='Angle of asymptotes at odd multiples of ±180°/q '; -eStr=['(i.e., ' sprintf(' ±%g°,',(1:2:q)*180/q)]; +s{end+1}='Angle of asymptotes at odd multiples of ±180°/q '; +eStr=['(i.e., ' sprintf(' ±%g°,',(1:2:q)*180/q)]; s{end}=[s{end} eStr(1:(end-1)) ').']; %Strip off last comma. s{end+1}=' '; s{end+1}=ListString('There exists ', p, ' pole',','); @@ -1034,7 +1039,7 @@ function pbMakeWeb_Callback(~, ~, handles) s{end}=[s{end} ' (highlighted by five pointed star).']; if q==1, - s{end+1}='Since q=1, there is a single asymptote at ±180°'; + s{end+1}='Since q=1, there is a single asymptote at ±180°'; s{end+1}='(on negative real axis), so intersect of this asymptote'; s{end+1}='on the axis s not important (but it is shown anyway).'; end @@ -1204,7 +1209,7 @@ function pbMakeWeb_Callback(~, ~, handles) '- (zero at ' num2str(z(i)) ') ).']; end fs=['Theta_z' num2str(i)... - '=angle((%s) - (%s)) = angle(%s) = %s°']; + '=angle((%s) - (%s)) = angle(%s) = %s°']; s{end+1}=sprintf(fs,num2str(cP),num2str(z(i)),... num2str(cP-z(i)),num2str(theta*180/pi)); end @@ -1227,7 +1232,7 @@ function pbMakeWeb_Callback(~, ~, handles) firstLine=0; end fs=['Theta_p' num2str(i)... - '=angle((%s) - (%s)) = angle(%s) = %s°']; + '=angle((%s) - (%s)) = angle(%s) = %s°']; s{end+1}=sprintf(fs,num2str(cP),num2str(p(i)),... num2str(cP-p(i)),num2str(theta*180/pi)); end @@ -1244,17 +1249,17 @@ function pbMakeWeb_Callback(~, ~, handles) end s{end+1}='Angle of Departure is equal to:'; -s{end+1}='Theta_depart = 180° + sum(angle to zeros) - '; +s{end+1}='Theta_depart = 180° + sum(angle to zeros) - '; s{end}=[s{end} 'sum(angle to poles).']; -s{end+1}=['Theta_depart = 180° + ' num2str(sum_zeros*180/pi)... +s{end+1}=['Theta_depart = 180° + ' num2str(sum_zeros*180/pi)... '-' num2str(sum_poles*180/pi) '.']; -s{end+1}=sprintf('Theta_depart = %5.3g°.',theta_D1*180/pi); +s{end+1}=sprintf('Theta_depart = %5.3g°.',theta_D1*180/pi); if theta_D1 ~= theta_D, - s{end+1}=sprintf('This is equivalent to %5.3g°.',theta_D*180/pi); + s{end+1}=sprintf('This is equivalent to %5.3g°.',theta_D*180/pi); end s{end+1}=' '; s{end+1}='This angle is shown in gray.'; -s{end+1}='It may be hard to see if it is near zero°.'; +s{end+1}='It may be hard to see if it is near zero°.'; %Draw angle of departure with a larger (grey) arc. r=2*r; @@ -1306,7 +1311,7 @@ function pbMakeWeb_Callback(~, ~, handles) '=angle( (Arriving zero) - (zero at ' num2str(p(i)) ') ).']; end fs=['Theta_z' num2str(i)... - '=angle((%s) - (%s)) = angle(%s) = %s°']; + '=angle((%s) - (%s)) = angle(%s) = %s°']; s{end+1}=sprintf(fs,num2str(cZ),num2str(z(i)),... num2str(cZ-z(i)),num2str(theta*180/pi)); end @@ -1323,7 +1328,7 @@ function pbMakeWeb_Callback(~, ~, handles) '(pole at ' num2str(p(i)) ') ).']; end fs=['Theta_p' num2str(i)... - '=angle((%s) - (%s)) = angle(%s) = %s°']; + '=angle((%s) - (%s)) = angle(%s) = %s°']; s{end+1}=sprintf(fs,num2str(cZ),num2str(p(i)),... num2str(cZ-p(i)),num2str(theta*180/pi)); end @@ -1339,17 +1344,17 @@ function pbMakeWeb_Callback(~, ~, handles) end s{end+1}='Angle of arrival is equal to:'; -s{end+1}='Theta_arrive = 180° - sum(angle to zeros) + '; +s{end+1}='Theta_arrive = 180° - sum(angle to zeros) + '; s{end}=[s{end} 'sum(angle to poles).']; -s{end+1}=['Theta_arrive = 180° - ' num2str(sum_zeros*180/pi)... +s{end+1}=['Theta_arrive = 180° - ' num2str(sum_zeros*180/pi)... '+' num2str(sum_poles*180/pi) '.']; -s{end+1}=sprintf('Theta_arrive = %5.3g°.',theta_D1*180/pi); +s{end+1}=sprintf('Theta_arrive = %5.3g°.',theta_D1*180/pi); if theta_D1 ~= theta_D, - s{end+1}=sprintf('This is equivalent to %5.3g°.',theta_D*180/pi); + s{end+1}=sprintf('This is equivalent to %5.3g°.',theta_D*180/pi); end s{end+1}=' '; s{end+1}='This angle is shown in gray.'; -s{end+1}='It may be hard to see if it is near 0°.'; +s{end+1}='It may be hard to see if it is near 0°.'; r=2*r; DrawArc(cZ+r*exp(j*theta_D),cZ,[0.8 0.8 0.8],theta_D,r,'\theta_{arrive}'); @@ -1414,7 +1419,7 @@ function pbMakeWeb_Callback(~, ~, handles) if wcross(i)==0, s{end}=[s{end} ' 0,']; else - s{end}=[s{end} sprintf(' ±%5.3gj,',wcross(i))]; + s{end}=[s{end} sprintf(' ±%5.3gj,',wcross(i))]; end end if n>1,