%*************************************************************
%   AUTHOR: Santhanam , Balu
%   DATE : 02/05/99
%   Function Name: quad_root.m
%   SYNOPSIS: 
%   Function computes the roots of a quadratic 
%   equation given the coefficient vector
%   r_1,r_2 : roots 
%   s       : string containing damping type 
%   USAGE :  [r_1,r_2,s] = quad_root(a,b,c);
%*************************************************************  
function [r_1,r_2,s] = quad_root(a,b,c)
%*************************************************************  
%  Error checking for 
%  1) nonumeric input, null input
%  2) imaginary input, insufficient input
%  3) a < 0 | a == 0
%*************************************************************
if nargin ~= 3
   error('Insufficient information for calculating roots')
elseif isempty(a) == 1 | isempty(b) == 1 | isempty(c) == 1
   error('Null Input')
elseif isnumeric(a) == 0 | isnumeric(a) == 0 | isnumeric(c) == 0
   error('Non numeric characters in the input')
elseif imag(a)~= 0 | imag(b)~= 0 | imag(c) ~= 0
   error('Coefficients a,b, and c need to be real')
elseif a == 0 
   error('a coefficient has to be nonzero')
elseif a < 0
   fprintf('a -ve, multiplying coefficients by -1\n')
   a = -a; b = -b; c = -c;
end
%*************************************************************
%  Discriminant Calculation
D = sqrt(b^2-4*a*c);
r_1 = (1/(2*a))*(-b+D);
r_2 = (1/(2*a))*(-b-D);
%*********************************************************
%  Determining the damping case 
%*********************************************************
 if D^2 > 0; 
    s = 'Over Damped Case , Roots are Real';
 elseif D == 0;
 s = 'Critically Damped case , Roots are Equal';
 else 
   s = 'Underdamped Case , Roots are Imaginary';
end
return 



