disp(' ');
disp(' spring_surge.m  ver 1.1  April 10, 2013 ');
disp(' ');
disp(' By Tom Irvine  Email: tom@vibrationdata.com ');
disp(' ');
%
clear nroot;
%
disp(' Select unit:  1=English  2=metric ');
iu=input(' ');
%
disp(' Select type:  ')
disp(' 1=Free-Free  ')
disp(' 2=Fixed-Free  ')
disp(' 3=Fixed-Fixed  ')
disp(' 4=Fixed-Mass  ')
disp(' 5=Free-mass  ')
%
atype=input(' ');
%
if(iu==1)
     k=input(' Enter stiffness (lbf/in) ');
    ml=input(' Enter spring mass (lbm)  ');
%    
else
     k=input(' Enter stiffness (N/mm)  ');
     k=k*1000;
    ml=input(' Enter spring mass (kg) ');    
end
%
if(atype==1)
    nroot(1)=pi;
end
%
if(atype==2)
    nroot(1)=pi/2;
end
%
if(atype==3)
    nroot(1)=pi;
end
if(atype==4)
%
    if(iu==1)
        M=input(' Enter end mass (lbm) ');
    else
        M=input(' Enter end mass (kg)  ');        
    end
    a=M/ml; 
    for j=1:8
        x=10^(j-4);
        for i=1:100
            fx=cot(x)-a*x;
%
            fxp=sin(x);
            fxp=fxp^2;
            fxp=-1/fxp;
            fxp=fxp-a;
%    
            x=x-(fx/fxp);
        end
        nroot(j)=x;
    end
%
end
if(atype==5)
    if(iu==1)
        M=input(' Enter end mass (lbm) ');
    else
        M=input(' Enter end mass (kg)  ');        
    end
    a=M/ml;
    for j=1:8
        x=10^(j-4);
        for i=1:100
            fx=tan(x)+a*x;
%
            fxp=cos(x);
            fxp=fxp^2;
            fxp=1/fxp;
            fxp=fxp+a;
%    
            x=x-(fx/fxp);
        end
        nroot(j)=x;
    end    
end
%
nroot=sort(nroot);
%
for j=1:length(nroot)
    if(nroot(j)>1.0e-10)
        out5 = sprintf('\n root=%g ',nroot(j));
        disp(out5);
        lambda=nroot(j);
        break;
    end
end
%
if(iu==1)
    fn=(lambda/(2*pi))*sqrt(386*k/ml);
else
    fn=(lambda/(2*pi))*sqrt(k/ml);    
end
out5 = sprintf('\n fn=%g Hz',fn);
disp(out5);
%