function V = rlcstep(R,L,C,T) 

% function V = rlcstep(R,L,C,T) 		
%
%  
% RLCSTEP 	Function RLCSTEP returns the step response of a parallel RLC 
%		circuit for the given input parameters.  Input variables R, L,
%		and C denote the values of the circuit components: resistor (in
%		Ohms), inductor (in Henrys), and capacitor (in Farads), 
%		respectively.  Output variable V is a row vector representing
%		the step response v(t) from t = [0,T].
%
%		This function first checks whether the system poles (natural 
%		frequencies) are real & distinct, complex conjugates, or real
%		& equal.  Depending on which of these cases is true for the 
%		given component values, the correct "analytical" solution is
%		applied (consult the Lesson 5 supplementary handout).  At the 
%		end of this example, we will solve the same problem much more 
%		quickly, without relying on our analytical solution, by using 
%		some of MATLAB's more sophisticated functions.

t = linspace(0,T,201);		%define the time vector

dis = (R*C)^(-2) - 4/(L*C);	%calculate the "discriminant" for the poles

p1 = -1/(2*R*C) + sqrt(dis)/2;	%compute the values for the two poles
p2 = -1/(2*R*C) - sqrt(dis)/2;	

if dis > 0		%Case (i): poles are real, distinct
  K1 = 1/((p1-p2)*C);	
  V = K1*(exp(p1*t) - exp(p2*t));

elseif dis < 0		%Case (ii): poles are complex conjugates
  K1 = 1/((p1-p2)*C);
  V = -2*imag(K1)*exp(real(p1)*t) .* sin(imag(p1)*t);

else			%Case (iii): poles are real, equal
  V = (1/C)*t .* exp(p1*t);

end
