% IAP 2007 Introduction to MATLAB: Calculus, Linear Algebra, Differential Equations
% Instructor: Violeta Ivanova, violeta@mit.edu

% Example 2: Linear Systems, Convolution: RC Circuit
% This exercise is based on Prof. Stephen Hall's Signals and Systems lectures 
% for 16.01-16.04 Unified Engineering.

% NOTE: consult this session's handout for illustrations (slides 27-29).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% A. ANALYTICAL SOLUTION

% A1. Define a time interval 0<t<4 at a step dt = 0.01s:



% A2. Compute the number of elements, nt, of the time vector t:


% A3. Compute the impulse response gt as g(t) = e^(-1.5t)


% A4. Compute the input ut as u(t) = e^-t 


% A5. Compute the response yt using an analytical solution y(t) = 2e^(-t)-2e^(-1.5t)


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% B. SOLUTION USING CONVOLUTION

% B1. Compute the response y using the built-in MATLAB function CONV
% Note: the response must be scaled for the time interval t and step dt




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% C. PLOTTING

% C1. Plot the input ut and impulse response gt vs. time t on the same plot:






% C2. Plot on the same plot and compare the response computed analytically, yt, 
% and the response computed numerically with function CONV, y:



                              