Code covered by the BSD License  

Highlights from
Numerical Computing with Simulink, Vol. 1

image thumbnail
from Numerical Computing with Simulink, Vol. 1 by Richard Gran
This sequel to Numerical Computing with MATLAB explores the mathematics of simulation.

RootLocus2.m
%  Root Locus 2  --
%     Chapter 2 of Numerical Computing with Simulink (Vol. 1)
% Compute the root locus for the control system that controls the spring
% mass damper system with rate feedback only.  The locus illustrates
% that this feedback control has a large effect on the damping -- it
% primarily changes the damping ratio of the closed loop dynamics.
% In the root locus plot the gain changes cause the roots to move along a 
% circle until it intersects the real axis, where one of the roots goes to
% the left and one goes to the right.  Do you understand the difference 
% between the response when the eigenvalues are complex and when they are 
% real?

% The Spring Mass Damper System in the text has the following state space
% model:

M = 10; K = 20; D = 2;
A = [0 1;-K/M -D/M];

% Initialize the array ev for storing the eigenvalues.
ev =[];

for Gain = 0:0.1:3              % The Gain for the root locus
ev = [ev eig(A-[0 0;0 Gain])];  % Get ev for closed loop system
end                             % Do you understand this calculation?
%  Why is the Gain in the 2,2 position in this calculation whereas it was
%  in the 2,1, position in the RootLocus1 m-file?

plot(real(ev),imag(ev),'x')     % Plot the values in the array
axis([-2.5 2.5 -2.5 2.5])
axis('square')
xlabel('Real Part of the Eigenvalues')
ylabel('Imaginary Part of the Eigenvalues')
grid

Contact us at files@mathworks.com