% Fall'06 - Spring'07 16.01-16.04 MATLAB Tutorials: Linear Systems % Instructor: Violeta Ivanova, violeta@mit.edu % Faculty: Mark Drela, Stephen Hall, Wes Harris, Ian Waitz % Example 1: Linear Systems: Eigenvalues and Eigenvectors % This exercise is based on S. Hall's Signals and Systems lectures. % C1. State space linear equations: x' = Ax % If x = (v; i), create the matrix A for the following system: % dv/dt = -1/2*v - 2*i % di/dt = 1/2*v - 3*i A = [-1/2 -2; 1/2 -3] % C2. Define vector x0 for initial conditions: v(0) = 2 and i(0) = 1 x0 = [2; 1] % C3. Compute eigenvalues and eigenvectors of the matrix A % Hint: use function EIG with option 'nobalance' for non-symmetric A [eigvecs, eigvals] = eig(A, 'nobalance') % Compute a column vector lambda including the two eigenvalues: lambda = diag(eigvals) % Compute two column eigvectors eigvec1 and eigvec2: eigvec1 = eigvecs(:, 1) eigvec2 = eigvecs(:, 2) % C4. Compute v(t) and i(t) for 0 < t < 5s % Hint: the solution has exponential form - see handout for formula % Compute the coefficients' vector a from the initial conditions x0 % Hint: Use operator \ to solve equation x0 = eigenvectors * a a = eigvecs \ x0 t = [0 : 0.1 : 5]; v = a(1) * eigvec1(1) * exp(lambda(1)*t) + a(2) * eigvec2(1) * exp(lambda(2)*t); i = a(1) * eigvec1(2) * exp(lambda(1)*t) + a(2) * eigvec2(2) * exp(lambda(2)*t); % C5. Plot v(t) and i(t) vs. time t subplot (211); plot(t, v); xlabel('Time'); ylabel('Voltage'); subplot(212); plot(t, i); xlabel('Time'); ylabel('Current');