disp(' ')
disp(' impulse_force.m ')
disp(' ver 1.0  September 21, 2011 ')
disp(' by Tom Irvine  Email: tomirvine@aol.com ')
disp(' ')
disp(' This program calculates the vibration of a  ')
disp(' single-degree-of-freedom system subjected to ')
disp(' an impulse force. ')
disp(' ')
%
clear omegan;
clear omegad;
clear fn;
clear damp;
clear N;
clear t;
clear x;
clear v;
clear Imp;
%
disp(' select units')
iunits=input(' 1=English  2=metric ');
%
%
disp(' ');
if(iunits==1)
   disp(' Enter total impulse (lbf sec) ');
else
   disp(' Enter total impulse (N sec) ');   
end
Imp=input(' ');
%    
if(iunits==1)
    disp(' ')
    v0 = input(' input initial velocity (in/sec) ');
    disp(' ')
    d0 = input(' input initial displacement (in) ');
    disp(' ')
    mass=input(' input mass (lbm) ');
    mass=mass/386;
else
    disp(' ')
    v0 = input(' input initial velocity (m/sec) ');
    disp(' ')
    d0 = input(' input initial displacement (m) '); 
    disp(' ')
    mass=input(' input mass (kg) ');    
end
%
disp(' ')
fn=input(' Enter the natural frequency (Hz)  ');
%
omegan=2.*pi*fn;
stiff=mass*omegan^2;
%
if(iunits==1)
    out1=sprintf('         stiffness =%8.4g lbf/in \n',stiff);
    out2=sprintf(' static deflection =%8.4g in \n',1/stiff);
else
    out1=sprintf('         stiffness =%8.4g  N/m \n',stiff);
    out2=sprintf(' static deflection =%8.4g m \n',1/stiff);   
end
disp(out1);
disp(out2);
%
disp(' ')
idamp=input(' Enter damping format:  1= damping ratio   2= Q  ');	
%
disp(' ')
if(idamp==1)
    damp=input(' Enter damping ratio (typically 0.05) ');
else
    Q=input(' Enter the amplification factor (typically Q=10) ');
    damp=1./(2.*Q);
end
%
omegad=omegan*sqrt(1.-damp^2);
%
%   State Space Solution
%
period=1/fn;
dt=period/64;
sr=1/dt;
dur=15*period;
N=dur/dt;
%
t=linspace(0,dur,N);
t=t';
%
domegan=damp*omegan;
t1=-domegan*t;
t2=omegad*t;
%
x=zeros(N,1);
v=zeros(N,1);
%
    clear c;
    c1=(v0+domegan*d0)/omegad;
    c2=(Imp/m)/omegad;
    d=domegan/omegad;
%
    x=exp(t1).*( d0*cos(t2) + (c1+c2)*sin(t2));
    v=-domegan*x + omegad*exp(t1).*( -d0*sin(t2) + (c1+c2)*cos(t2));
%
disp(' ');
disp(' plot displacement?');
k=input(' 1=yes  2=no ');
if(k==1)
figure(1);
    plot(t,x);
    grid on;
    if(iunits==1)
        ylabel('Displacement (in)');
    else
        ylabel('Displacement (m)');
    end
    xlabel('Time (sec)');
end
%
disp(' ');
disp(' plot velocity?');
k=input(' 1=yes  2=no ');
if(k==1)
    figure(2);
    plot(t,v);
    grid on;   
    if(iunits==1)
        ylabel('Velocity (in/sec)');
    else
        ylabel('Velocity (m/sec)');
    end
    xlabel('Time (sec)');
end
%
disp(' ');
disp(' plot acceleration?');
k=input(' 1=yes  2=no ');
if(k==1)
    figure(3);
    clear a;
    a= (1/mass)-(2.*domegan)*v -(omegan^2)*x;
    if(iunits==1)
        a=a/386.;
    end     
    plot(t,a);
    grid on;  
    if(iunits==1)
        ylabel('Accel (G)');
    else
        ylabel('Accel (m/sec^2)');
    end
    xlabel('Time (sec)');
end
%
disp(' ');
disp(' plot phase portraits?');
k=input(' 1=yes  2=no ');
if(k==1)
    figure(4);
    plot(x,v);
    grid on;
    if(iunits==1)
        ylabel('Velocity (in/sec)');
        xlabel('Displacement (in)');       
    else
        ylabel('Velocity (m/sec)');
        xlabel('Displacement (m)');        
    end
%
    figure(5);
    plot(x,a);
    grid on;    
    if(iunits==1)
        ylabel('Accel (G)');
        xlabel('Displacement (in)');       
    else
        ylabel('Accel (m/sec^2)');
        xlabel('Displacement (m)');        
    end
%
end