Control Tutorials for MATLAB and Simulink (2024)

Below is the function lnyquist.m. This function is a modified version of MATLAB's nyquist command, and has the same attributes as the original, with a few improvements. The function lnyquist.m plots

(log2(1+abs(G(jw))),angle(G(jw))

in polar coordinates by taking the log of the magnitude, the magnitude scale is compressed and the overall shape of the Nyquist plot is easier to see on the screen. We use log base 2 and add one to the magnitude so as to preserve the key attributes of the -1 point for the Nyquist plot.

The lnyquist function also takes poles on the imaginary axis into account when creating the Nyquist plot, and plots around them.

Copy the following text into a file lnyquist.m. Put the file in the same directory as the MATLAB software, or in a directory which is contained in MATLAB's search path.

 function [reout,imt,w] = lnyquist(a,b,c,d,iu,w) %LNYQUIST Nyquist frequency response for continuous-time linear systems. % % This Version of the NYQUIST Command takes into account poles at the % jw-axis and loops around them when creating the frequency vector in order % to produce the appropriate Nyquist Diagram (The NYQUIST command does % not do this and therefore produces an incorrect plot when we have poles in the % jw axis). % % NOTE: This version of LNYQUIST does not account for pole-zero % cancellation. Therefore, the user must simplify the transfer function before using % this command. % % LNYQUIST(A,B,C,D,IU) produces a Nyquist plot from the single input % IU to all the outputs of the system: % . -1 % x = Ax + Bu G(s) = C(sI-A) B + D % y = Cx + Du RE(w) = real(G(jw)), IM(w) = imag(G(jw)) % % The frequency range and number of points are chosen automatically. % % LNYQUIST(NUM,DEN) produces the Nyquist plot for the polynomial % transfer function G(s) = NUM(s)/DEN(s) where NUM and DEN contain % the polynomial coefficients in descending powers of s. % % LNYQUIST(A,B,C,D,IU,W) or LNYQUIST(NUM,DEN,W) uses the user-supplied % freq. vector W which must contain the frequencies, in radians/sec, % at which the Nyquist response is to be evaluated. When invoked % with left hand arguments, % [RE,IM,W] = LNYQUIST(A,B,C,D,...) % [RE,IM,W] = LNYQUIST(NUM,DEN,...) % returns the frequency vector W and matrices RE and IM with as many % columns as outputs and length(W) rows. No plot is drawn on the % screen. % See also: LOGSPACE,MARGIN,BODE, and NICHOLS. % % J.N. Little 10-11-85 % Revised ACWG 8-15-89, CMT 7-9-90, ACWG 2-12-91, 6-21-92, % AFP 2-23-93 % WCM 8-30-97 % ******************************************************************** Modifications made to the nyquist - takes into account poles on jw axis. then goes around these to make up frequency vector % % if nargin==0, eval('exresp(''nyquist'')'), return, end --- Determine which syntax is being used --- nargin1 = nargin; nargout1 = nargout; if (nargin1==1),% System form without frequency vector [num,den]=tfdata(a,'v'); z = roots(num); p = roots(den); zp = [z;p]; wpos = zp(find(abs(zp)>0)); if(min(abs(p)) == 0) wstart = max(eps, 0.03*min([1;wpos])); else wstart = max(eps, 0.03*min(abs(zp))); end wstop = max([1000;30*wpos]); w = logspace(log10(wstart),log10(wstop),max(51,10*max(size(zp))+1)); %w = freqint2(num,den,30); [ny,nn] = size(num); nu = 1; %error('Wrong number of input arguments.'); elseif (nargin1==2), if(isa(a,'ss')|isa(a,'tf')|isa(a,'zpk')) % System with frequency vector [num,den]=tfdata(a,'v'); w = b; else% Transfer function form without frequency vector num = a; den = b; z = roots(num); p = roots(den); zp = [z;p]; wpos = zp(find(abs(zp)>0)); if(min(abs(p)) == 0) wstart = max(eps, 0.03*min([1;wpos])); else wstart = max(eps, 0.03*min(abs(zp))); end wstop = max([1000;30*wpos]); w = logspace(log10(wstart),log10(wstop),max(51,10*max(size(zp))+1)); %w = freqint2(num,den,30); end [ny,nn] = size(num); nu = 1; elseif (nargin1==3), % Transfer function form with frequency vector num = a; den = b; w = c; [ny,nn] = size(num); nu = 1; elseif (nargin1==4), % State space system, w/o iu or frequency vector error(abcdchk(a,b,c,d)); [num,den] = ss2tf(a,b,c,d); [z,p,k]= ss2zp(a,b,c,d); [num,den] = zp2tf(z,p,k); zp = [z;p]; wpos = zp(find(abs(zp)>0)); if(min(abs(p)) == 0) wstart = max(eps, 0.03*min([1;wpos])); else wstart = max(eps, 0.03*min(abs(zp))); end wstop = max([1000;30*wpos]); w = logspace(log10(wstart),log10(wstop),max(51,10*max(size(zp))+1)); %w = freqint2(a,b,c,d,30); nargin1 = 2;%[iu,nargin,re,im]=mulresp('nyquist',a,b,c,d,w,nargout1,0); %if ~iu, if nargout, reout = re; end, return, end [ny,nu] = size(d); elseif (nargin1==5), % State space system, with iu but w/o freq. vector error(abcdchk(a,b,c,d)); z = tzero(a,b,c,d); p = eig(a); zp = [z;p]; wpos = zp(find(abs(zp)>0)); if(min(abs(p)) == 0) wstart = max(eps, 0.03*min([1;wpos])); else wstart = max(eps, 0.03*min(abs(zp))); end wstop = max([1000;30*wpos]); w = logspace(log10(wstart),log10(wstop),max(51,10*max(size(zp))+1)); %w = freqint2(a,b,c,d,30); [ny,nu] = size(d); else error(abcdchk(a,b,c,d)); [ny,nu] = size(d); end if nu*ny==0, im=[]; w=[]; if nargout~=0, reout=[]; end, return, end ********************************************************************* depart from the regular nyquist program here now we have a frequency vector, a numerator and denominator now we create code to go around all poles and zeroes here. if (nargin1==5) | (nargin1 ==4) | (nargin1 == 6) [num,den]=ss2tf(a,b,c,d); end tol = 1e-6; %defined tolerance for finding imaginary poles z = roots(num); p = roots(den); ***** If all of the poles are at the origin, just move them a tad to the left*** if norm(p) == 0 if(isempty(z)) tad = 1e-1; else tad = min([1e-1; 0.1*abs(z)]); end length_p = length(p); p = -tad*ones(length_p,1); den = den(1,1)*[1 tad]; for ii = 2:length_p den = conv(den,[1 tad]); end zp = [z;p]; wpos = zp(find(abs(zp)>0)); if(min(abs(p)) == 0) wstart = max(eps, 0.03*min([1;wpos])); else wstart = max(eps, 0.03*min(abs(zp))); end wstop = max([1000;30*wpos]); w = logspace(log10(wstart),log10(wstop),max(51,10*max(size(zp))+1)); %w = freqint2(num,den,30); end zp = [z;p]; % combine the zeros and poles of the system nzp = length(zp); % number of zeros and poles ones_zp=ones(nzp,1); %Ipo = find((abs(real(p))<1e-6) & (imag(p)>=0)) %index poles with zero real part + non-neg imag part Ipo = find((abs(real(p)) < tol) & (imag(p)>=0)); %index poles with zero real part + non-neg imag part if ~isempty(Ipo) % **** only if we have such poles do we do the following:************************* po = p(Ipo); % poles with 0 real part and non-negative imag part check for distinct poles [y,ipo] = sort(imag(po)); % sort imaginary parts po = po(ipo); dpo = diff(po); idpo = find(abs(dpo)>tol); idpo = [1;idpo+1]; % indexes of the distinct poles po = po(idpo); % only distinct poles are used nIpo = length(idpo); % # of such poles originflag = find(imag(po)==0); % locate origin pole s = []; % s is our frequency response vector %w = sqrt(-1)*w; % create a jwo vector to evaluate all frequencies with for ii=1:nIpo % for all Ipo poles [nrows,ncolumns]=size(w); if nrows == 1 w = w.'; % if w is a row, make it a column end; if nIpo == 1 r(ii) = .1; else % check distances to other poles and zeroes pdiff = zp-po(ii)*ones_zp; % find the differences between % poles you are checking and other poles and zeros ipdiff = find(abs(pdiff)>tol); % ipdiff is all nonzero differences r(ii)=0.2*min(abs(pdiff(ipdiff))); % take half this difference r(ii)=min(r(ii),0.1); % take the minimum of this diff.and .1 end; t = linspace(-pi/2,pi/2,25); if (ii == originflag) t = linspace(0,pi/2,25); end; % gives us a vector of points around each Ipo s1 = po(ii)+r(ii)*(cos(t)+sqrt(-1)*sin(t)); % detour here s1 = s1.'; % make sure it is a column % Now here I reconstitute s - complex frequency - and % evaluate again. bottomvalue = po(ii)-sqrt(-1)*r(ii); % take magnitude of imag part if (ii == originflag) % if this is an origin point bottomvalue = 0; end; topvalue = po(ii)+sqrt(-1)*r(ii); % the top value where detour stops nbegin = find(imag(w) < imag(bottomvalue)); % nnbegin = length(nbegin); % find all the points less than encirclement if (nnbegin == 0)& (ii ~= originflag) % around jw root sbegin = 0 else sbegin = w(nbegin); end; nend = find(imag(w) > imag(topvalue)); % find all points greater than nnend = length(nend); % encirclement around jw root if (nnend == 0) send = 0 else send = w(nend); end w = [sbegin; s1; send]; % reconstituted half of jw axis end else w = sqrt(-1)*w; end %end % this ends the loop for imaginary axis poles ************************************************************* back to the regular nyquist program here Compute frequency response if (nargin1==1)|(nargin1==2)|(nargin1==3) gt = freqresp(num,den,w); else gt = freqresp(a,b,c,d,iu,w); end *********************************************************** nw = length(gt); mag = abs(gt); % scaling factor added ang = angle(gt); mag = log2(mag+1); % scale by log2(mag) throughout for n = 1:nw h(n,1) = mag(n,1)*(cos(ang(n,1))+sqrt(-1)*sin(ang(n,1))); end; % recalculate G(jw) with scaling factor gt = h; *********************************************************** ret=real(gt); imt=imag(gt); If no left hand arguments then plot graph. if nargout==0, status = ishold; plot(ret,imt,'r-',ret,-imt,'g--') plot(real(w),imag(w)) modifications added here %******************************************* % set(gca, 'YLimMode', 'auto') limits = axis; % Set axis hold on because next plot command may rescale set(gca, 'YLimMode', 'auto') set(gca, 'XLimMode', 'manual') hold on % Make arrows for k=1:size(gt,2), g = gt(:,k); re = ret(:,k); im = imt(:,k); sx = limits(2) - limits(1); [sy,sample]=max(abs(2*im)); arrow=[-1;0;-1] + 0.75*sqrt(-1)*[1;0;-1]; sample=sample+(sample==1); reim=diag(g(sample,:)); d=diag(g(sample+1,:)-g(sample-1,:)); % Rotate arrow taking into account scaling factors sx and sy d = real(d)*sy + sqrt(-1)*imag(d)*sx; rot=d./abs(d); % Use this when arrow is not horizontal arrow = ones(3,1)*rot'.*arrow; scalex = (max(real(arrow)) - min(real(arrow)))*sx/50; scaley = (max(imag(arrow)) - min(imag(arrow)))*sy/50; arrow = real(arrow)*scalex + sqrt(-1)*imag(arrow)*scaley; xy =ones(3,1)*reim' + arrow; xy2=ones(3,1)*reim' - arrow; [m,n]=size(g); hold on plot(real(xy),-imag(xy),'r-',real(xy2),imag(xy2),'g-') end xlabel('Real Axis'), ylabel('Imag Axis') limits = axis; % Make cross at s = -1 + j0, i.e the -1 point if limits(2) >= -1.5 & limits(1) <= -0.5 % Only plot if -1 point is not far out. line1 = (limits(2)-limits(1))/50; line2 = (limits(4)-limits(3))/50; plot([-1+line1, -1-line1], [0,0], 'w-', [-1, -1], [line2, -line2], 'w-') end % Axis plot([limits(1:2);0,0]',[0,0;limits(3:4)]','w:'); plot(-1,0,'+k'); if ~status, hold off, end % Return hold to previous status return % Suppress output end %reout = ret; % plot(real(p),imag(p),'x',real(z),imag(z),'o'); 


Published with MATLAB® 9.2

Control Tutorials for MATLAB and Simulink (2024)

FAQs

How do I find answers in MATLAB? ›

To view all of your solutions, go to a Problem page and click View my solutions. You can view your solutions in a list or in the Solution Map. If using the list view, you can review the display by selecting a Sort by option.

How difficult is MATLAB to learn? ›

MATLAB® is not hard to learn if you go for any professional course. It is ideal for engineering graduates and IT professionals willing to develop MATLAB® skills in their related fields.

Can I learn MATLAB on my own? ›

Get Started with Introductory Videos

See common applications and workflows, and discover new product capabilities. Get started with MATLAB by walking through an example. This video shows you the basics, and it gives you an idea of what working in MATLAB is like.

What is the control model in Simulink? ›

Simulink® Control Design™ lets you design and analyze control systems modeled in Simulink. You can automatically tune arbitrary SISO and MIMO control architectures, including PID controllers.

How long does it take to learn MATLAB? ›

If you're a novice programmer, you can expect it to take a little longer than if you were a more seasoned programmer. Someone who can afford to devote all their time to MATLAB can finish learning the language in two weeks. If you have a lot of other responsibilities, however, it will take you longer to complete.

How do you get a long answer in MATLAB? ›

To format the way numbers display, do one of the following:
  1. On the Home tab, in the Environment section, click Preferences. Select MATLAB > Command Window, and then choose a Numeric format option.
  2. Use the format function, for example: format short format short e format long.

Which is harder Python or MATLAB? ›

Learning curve: Python is significantly simpler than Matlab and doesn't require as much background knowledge. Matlab is structured in a very logical and comprehensible way but is aimed at users with a deep knowledge of math.

Is MATLAB enough for a job? ›

Conclusion. The industry has some familiar buzz that learning MATLAB will not be a good opportunity for a better career. But this is not fully true. Yes, it is an acceptable reason that salary or company structure will never be able to touch available popular jobs on other programming technologies.

What should I learn first MATLAB or Python? ›

The OOP in MATLAB is more advanced and complex, which to some can be more confusing. That being said, MATLAB is generally a more advanced language while Python is more of a beginner's language. Therefore, just because MATLAB may be more complex and confusing at first, with practice, it will become easier to grasp.

What is Simulink used for? ›

Simulink is the platform for Model-Based Design that supports system-level design, simulation, automatic code generation, and continuous test and verification of embedded systems. Key capabilities include: A graphical editor for modeling all components of a system.

Is MATLAB real coding? ›

MATLAB is a high-level programming language designed for engineers and scientists that expresses matrix and array mathematics directly.

How to understand Simulink model? ›

In Simulink, systems are drawn on screen as block diagrams. Many elements of block diagrams are available, such as transfer functions, summing junctions, etc., as well as virtual input and output devices such as function generators and oscilloscopes.

How to run Simulink model? ›

When you want to simulate the model using the current values for all model configuration parameter values, block parameter values, variable values, and so on, use the most basic syntax, specifying only the name of the model as an input argument. out = sim("ModelName"); This syntax returns a single Simulink.

How do you stop a Simulink model? ›

Stop Simulation (Simulink Reference) The Stop Simulation block stops the simulation when the input is nonzero. The simulation completes the current time step before terminating. If the block input is a vector, any nonzero vector element causes the simulation to stop.

How do I find Solver in MATLAB? ›

Open the model vdp . To allow the software to select the solver to use for the model, specify the Type parameter as Fixed-step or Variable-step , and set the Solver parameter to auto . For this example, configure the software to select a variable-step solver for the model.

How to check results in MATLAB? ›

View Results in Command Window

The Summary Report link provides access to the Model Advisor Command-Line Summary report. You can review additional results in the Command Window by calling the DisplayResults parameter when you run the Model Advisor.

How do you find the step response in MATLAB? ›

[ y , tOut ] = step( sys , tFinal ) computes the step response from t = 0 to the end time t = tFinal . [ y , tOut ] = step( sys , t ) returns the step response of a dynamic system model sys at the times specified in the vector t .

How do I find something in MATLAB code? ›

Search Using Find Dialog Box

The Find dialog box opens. The search begins at the current cursor position. MATLAB finds the text you specified and highlights it. MATLAB beeps when a search for Find Next reaches the end of the Command Window, or when a search for Find Previous reaches the top of the Command Window.

References

Top Articles
Scholarship Winner Spotlight: Chloë Divers - Going Merry
Mandel: What college sports' pay-for-play era will mean — and won't mean
Bad Moms 123Movies
ARK Survival Ascended Floating Turret Tower Build Guide
Fiat 600e: Dolce Vita auf elektrisch
Target Dummies 101 - The Dummy Research/Tutorial Thread
Corinne Massiah Bikini
Luxiconic Nails
Rickrolling Link Generator
Endicott Final Exam Schedule Fall 2023
Ascension St. Vincent's Lung Institute - Riverside
Lkq Pull-A-Part
Duralast Battery H6-Dl Group Size 48 680 Cca
La Qua Brothers Funeral Home
Red Dead Redemption 2 Legendary Fish Locations Guide (“A Fisher of Fish”)
Chubbs Canton Il
โลโก้โภชนาการที่ดีที่สุด: สัญลักษณ์แห่งความเป็นเลิศ
Twitchxx.com
Hannaford Weekly Flyer Manchester Nh
T33N Leaks 5 17
12 Week Glute Program to Transform Your Booty with Free PDF - The Fitness Phantom
Take Me To The Closest Chase Bank
Gary Keesee Kingdom Principles Pdf
Camwhor*s Bypass 2022
Craigslist Swm
Emojiology: 🤡 Clown Face
25+ Twitter Header Templates & Design Tips - Venngage
Ella Phipps Haughton
Milwaukee Zoo Ebt Discount
Mgmresorts.okta.com Login Page
Worldfree4U In
Wym Urban Dictionary
Hawkview Retreat Pa Cost
20 Fantastic Things To Do In Nacogdoches, The Oldest Town In Texas
Demetrius Meach Nicole Zavala
Planet Zoo Obstructed
Publix – Supermarkt mit ökologischem Gewissen und exzellentem Service
Utexas Baseball Schedule 2023
Alaska State Troopers Dispatch
Horseheads Schooltool
House Party 2023 Showtimes Near Mjr Chesterfield
Inland Empire Heavy Equipment For Sale By Owner
Blackboard Bristol
Mission Impossible 7 Showtimes Near Regal Bridgeport Village
Pressconnects Obituaries Recent
Sirius Satellite Radio Sports Schedule
Whats On Metv Now
Appsanywhere Mst
How Much Does Costco Gas Cost Today? Snapshot of Prices Across the U.S. | CostContessa
Locate Td Bank Near Me
Cetaphil Samples For Providers
Babyrainbow Private
Latest Posts
Article information

Author: Fr. Dewey Fisher

Last Updated:

Views: 6720

Rating: 4.1 / 5 (42 voted)

Reviews: 81% of readers found this page helpful

Author information

Name: Fr. Dewey Fisher

Birthday: 1993-03-26

Address: 917 Hyun Views, Rogahnmouth, KY 91013-8827

Phone: +5938540192553

Job: Administration Developer

Hobby: Embroidery, Horseback riding, Juggling, Urban exploration, Skiing, Cycling, Handball

Introduction: My name is Fr. Dewey Fisher, I am a powerful, open, faithful, combative, spotless, faithful, fair person who loves writing and wants to share my knowledge and understanding with you.