disp(' ')
disp(' free_ode42.m ')
disp(' ver 1.0  February 23, 2005 ')
disp(' by Tom Irvine  Email: tomirvine@aol.com ')
disp(' ')
disp(' This program calculates the free vibration of a  ')
disp(' single-degree-of-freedom system using the ode45 method. ')
disp(' ')
disp(' The ode45 method is a numerical method.')
disp(' ')
%
clear omegan;
clear omegad;
clear fn;
clear damp;
clear N;
clear t;
clear x;
clear w;
%
disp(' select units')
iunits=input(' 1=English  2=metric ');
%
if(iunits==1)
    disp(' ')
    v0 = input(' input initial velocity (in/sec) ');
    disp(' ')
    d0 = input(' input initial displacement (in) ');
else
    disp(' ')
    v0 = input(' input initial velocity (m/sec) ');
    disp(' ')
    d0 = input(' input initial displacement (m) ');    
end
%
disp(' ')
fn=input(' Enter the natural frequency (Hz)  ');
%
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
%
omegan=2.*pi*fn;
omegad=omegan*sqrt(1.-damp^2);
%
%   State Space Solution
%
period=1/fn;
dt=period/64;
sr=1/dt;
dur=12*period;
N=dur/dt;
%
t=linspace(0,dur,N);
t=t';
%
w(1)=d0;
w(2)=v0;
%
clear b;
clear c;
%
b=-omegan^2;
c=-2.*damp*omegan;
%
[t,w] = ode45(@free_function,t,w,[],[],b,c);
%
disp(' ');
disp(' plot displacement?');
k=input(' 1=yes  2=no ');
if(k==1)
figure(1);
    plot(t,w(:,1));
    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(1);
    plot(t,w(:,2));
    if(iunits==1)
        ylabel('Velocity (in/sec)');
    else
        ylabel('Velocity (m/sec)');
    end
    xlabel('Time (sec)');
end