Code covered by the BSD License  

Highlights from
GUI Single Degree of Freedom Vibration Calculator

image thumbnail

GUI Single Degree of Freedom Vibration Calculator

by

 

18 Sep 2011 (Updated )

It is a useful tool to study SDOF vibration.

SDOF_vibration_calculator2(varargin)
function varargout = SDOF_vibration_calculator2(varargin)
% SDOF_VIBRATION_CALCULATOR2 M-file for SDOF_vibration_calculator2.fig
%      SDOF_VIBRATION_CALCULATOR2, by itself, creates a new SDOF_VIBRATION_CALCULATOR2 or raises the existing
%      singleton*.
%
%      H = SDOF_VIBRATION_CALCULATOR2 returns the handle to a new SDOF_VIBRATION_CALCULATOR2 or the handle to
%      the existing singleton*.
%
%      SDOF_VIBRATION_CALCULATOR2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SDOF_VIBRATION_CALCULATOR2.M with the given input arguments.
%
%      SDOF_VIBRATION_CALCULATOR2('Property','Value',...) creates a new SDOF_VIBRATION_CALCULATOR2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before SDOF_vibration_calculator2_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to SDOF_vibration_calculator2_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help SDOF_vibration_calculator2

% Last Modified by GUIDE v2.5 24-Sep-2011 13:17:01

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @SDOF_vibration_calculator2_OpeningFcn, ...
                   'gui_OutputFcn',  @SDOF_vibration_calculator2_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before SDOF_vibration_calculator2 is made visible.
function SDOF_vibration_calculator2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to SDOF_vibration_calculator2 (see VARARGIN)
global Cn
global Cm
global Fmanu
global CS

global t
global x0
global v0
global zeta
global wn
global f0
global wdr
global XT XTX
global n
n = 1; XTX = zeros(size(t));


set(handles.radiobutton1,'value',1); Cm = 1;
set(handles.edit8,'string','0');
set(handles.edit8,'enable','off');

set(handles.radiobutton16,'value',1); Cn = 1;
set(handles.edit2,'string','0');
set(handles.edit2,'enable','off');
set(handles.edit3,'string','0');
set(handles.edit3,'enable','off');
set(handles.uipanel6,'visible','off');
set(handles.popupmenu2,'enable','off');

% Choose default command line output for SDOF_vibration_calculator2
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

clc

set(handles.text9,'String','z :','FontName','symbol');

% UIWAIT makes SDOF_vibration_calculator2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = SDOF_vibration_calculator2_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;



function edit2_Callback(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit2 as text
%        str2double(get(hObject,'String')) returns contents of edit2 as a double


% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit3_Callback(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit3 as text
%        str2double(get(hObject,'String')) returns contents of edit3 as a double


% --- Executes during object creation, after setting all properties.
function edit3_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit10_Callback(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit10 as text
%        str2double(get(hObject,'String')) returns contents of edit10 as a double


% --- Executes during object creation, after setting all properties.
function edit10_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

clc
% Plot button
global Cn
global Cm
global Fmanu
global CS

global t0
global tf
global t
global x0
global v0
global zeta
global wn
global f0
global wdr
global XT XTX
global n



t0  = str2num(get(handles.edit4,'string'));
tf  = str2num(get(handles.edit5,'string'));
x0  = str2num(get(handles.edit6,'string'));
v0  = str2num(get(handles.edit7,'string')); 
zeta   = str2num(get(handles.edit8,'string')); z = zeta;
wn  = str2num(get(handles.edit9,'string'));
f0  = str2num(get(handles.edit2,'string'));
wdr = str2num(get(handles.edit3,'string'));

t = t0:0.001:tf;
C = [1 2 3 4; 5 6 7 8];
% Cn,Cm
Num = C(Cn,Cm);
switch Num
    case 1      % undamp + free
                wd = wn*sqrt(1-z^2);
                X     = f0/sqrt((wn^2 - wdr^2)^2 + (2*z*wn*wdr)^2);
                Theta = atan(2*z*wn*wdr/(wn^2 - wdr^2));
                Phi = atan((wd*(x0 - X*cos(Theta)))/(v0 + (x0 - X*cos(Theta))*z*wn - wdr*X*sin(Theta)));
                A     = (x0 - X*cos(Theta))/sin(Phi);
                XT = A*exp(-z*wn*t).*sin(wd*t + Phi) + X*cos(wdr*t - Theta);
                set(handles.edit10, 'string',['x(t) = ',sprintf('%4.3f',A),'sin(',...
                    sprintf('%4.3f',wn),'t + ',sprintf('%4.3f',Phi),')']);
       
        
    case 2      % Critical damp + free
                a1 = x0;
                a2 = v0 + wn*x0;
                XT = (a1 + (a2)*t).*exp(-wn*t);
                A = a1;
                Phi = a2;
                X=0;
                Theta=0;
                set(handles.edit10, 'string',['x(t) = (',sprintf('%4.3f',a1),' + ',...
                    sprintf('%4.3f',a2),'t)exp(-',sprintf('%4.3f',wn),'t)']);
            
    case 3      % Under damp + free
                if z >= 1
                    warndlg('This is not underdamp system because the damping ratio is larger than 1. Please insert the value correctly.');
                    XT = 0*t;                    
                else
                wd = wn*sqrt(1-z^2);
                X     = f0/sqrt((wn^2 - wdr^2)^2 + (2*z*wn*wdr)^2);
                Theta = atan(2*z*wn*wdr/(wn^2 - wdr^2));
                Phi = atan((wd*(x0 - X*cos(Theta)))/(v0 + (x0 - X*cos(Theta))*z*wn - wdr*X*sin(Theta)));
                A     = (x0 - X*cos(Theta))/sin(Phi);
                XT = A*exp(-z*wn*t).*sin(wd*t + Phi) + X*cos(wdr*t - Theta);
                set(handles.edit10, 'string',['x(t) = (',sprintf('%4.3f',A),...
                    'exp(',sprintf('%4.3f',-z*wn),'t) sin(',sprintf('%4.3f',wd),...
                    't + ',sprintf('%4.3f',Phi),')']);
                end
        
    case 4      % Over damp + free
                if z <= 1
                    warndlg('This is not underdamp system because the damping ratio is less than 1. Please insert the value correctly.');
                    XT = 0*t; 
                else
                a1 = (-v0 + (-z + sqrt(z^2 -1)*wn*x0))/(2*wn*sqrt(z^2 -1));
                a2 = (v0 + (z + sqrt(z^2 -1)*wn*x0))/((2*wn*sqrt(z^2 -1)));
                XT = exp(-z*wn*t).*(a1*exp(-wn*sqrt(z^2 -1)*t) + a2*exp(wn*sqrt(z^2 -1)*t));            
                A = a1;
                Phi = a2;
                 X=0;
                Theta=0;
                set(handles.edit10, 'string',['x(t) = exp(',sprintf('%4.3f',-z*wn),'t) (',...
                    sprintf('%4.3f',a1),'exp(',sprintf('%4.3f',-wn*sqrt(z^2 -1)),'t) + ',...
                    sprintf('%4.3f',a2),'exp(',sprintf('%4.3f',wn*sqrt(z^2 -1)),'t))']);
                end
                
    %%%%%%%%%%%%%%  Froce response   %%%%%%%%%%%%%%%%%%
                
    case 5      % Undamp + force
        Fmanu;
         switch Fmanu 
             case 1     % Harmonic 
                        switch CS
                            case 0  % None
                            case 1  % cos and sin                                
                            case 2  % cos
                                if wdr == wn
                                    wdr = str2num(get(handles.edit9,'string')); set(handles.edit3,'string',num2str(wdr));
                                    XT = (v0/wdr)*sin(wdr*t) + x0*cos(wdr*t) + (f0/(2*wdr))*t.*sin(wdr*t);
                                    set(handles.edit10, 'string',['x(t) = ',sprintf('%4.3f',v0/wdr),'sin(',sprintf('%4.3f',wdr)...
                                        't) + ',sprintf('%4.3f',x0),'cos(',sprintf('%4.3f',wdr),'t) + ',sprintf('%4.3f',f0/(2*wdr)),' t sin(',sprintf('%4.3f',wdr),'t)']) 
                                else
                                    XT = (v0/wn)*sin(wn*t) + (x0 - f0/(wn^2 - wdr^2))*cos(wn*t) + ...
                                        f0/(wn^2 - wdr^2)*cos(wdr*t);
                                    set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',v0/wn),'sin(',...
                                        sprintf('%4.3f',wn),'t) + (',sprintf('%4.3f',x0 - f0/(wn^2 - wdr^2)),...
                                        'cos(',sprintf('%4.3f',wn),'t) + ',sprintf('%4.3f',f0/(wn^2 - wdr^2)),'cos(',...
                                        sprintf('%4.3f',wdr),'t)']);
                                end
                                    
                            case 3  % sin
                                if wdr == wn
                                   wdr = str2num(get(handles.edit9,'string')); set(handles.edit3,'string',num2str(wdr));
                                    XT = (v0/wdr + f0/2/wdr^2)*sin(wdr*t) + x0*cos(wdr*t) - (f0/(2*wdr))*t.*cos(wdr*t);
                                    set(handles.edit10, 'string',['x(t) = ',sprintf('%4.3f',v0/wdr + f0/2/wdr^2),'sin(',sprintf('%4.3f',wdr)...
                                        't) + ',sprintf('%4.3f',x0),'cos(',sprintf('%4.3f',wdr),'t) - ',sprintf('%4.3f',f0/(2*wdr)),' t cos(',sprintf('%4.3f',wdr),'t)']);
                                else
                                    XT = (x0)*cos(wn*t) + (v0/wn - (wdr/wn)*f0/(wn^2 - wdr^2))*sin(wn*t) + ...
                                        f0/(wn^2 - wdr^2)*sin(wdr*t);
                                    set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',x0),'cos(',...
                                        sprintf('%4.3f',wn),'t) + (',sprintf('%4.3f',v0/wn - (wdr/wn)*f0/(wn^2 - wdr^2)),...
                                        'sin(',sprintf('%4.3f',wn),'t) + ',sprintf('%4.3f',f0/(wn^2 - wdr^2)),'sin(',...
                                        sprintf('%4.3f',wdr),'t)']);
                                end
                        end
             case 2     % Resonance only sine term available.
                
                        switch CS
                            case 0   % none
                            case 1   % Cos and Sin
                            case 2   % cos
                                      
                                     wdr = str2num(get(handles.edit9,'string')); set(handles.edit3,'string',num2str(wdr));
                                     XT = (v0/wdr)*sin(wdr*t) + x0*cos(wdr*t) + (f0/(2*wdr))*t.*sin(wdr*t);
                                     set(handles.edit10, 'string',['x(t) = ',sprintf('%4.3f',v0/wdr),'sin(',sprintf('%4.3f',wdr)...
                                        't) + ',sprintf('%4.3f',x0),'cos(',sprintf('%4.3f',wdr),'t) + ',sprintf('%4.3f',f0/(2*wdr)),' t sin(',sprintf('%4.3f',wdr),'t)'])
                            case 3   % sin
                                    
                                     wdr = str2num(get(handles.edit9,'string')); set(handles.edit3,'string',num2str(wdr));
                                     XT = (v0/wdr + f0/2/wdr^2)*sin(wdr*t) + x0*cos(wdr*t) - (f0/(2*wdr))*t.*cos(wdr*t);
                                     set(handles.edit10, 'string',['x(t) = ',sprintf('%4.3f',(v0/wdr + f0/2/wdr^2)),'sin(',sprintf('%4.3f',wdr)...
                                        't) + ',sprintf('%4.3f',x0),'cos(',sprintf('%4.3f',wdr),'t) - ',sprintf('%4.3f',f0/(2*wdr)),' t cos(',sprintf('%4.3f',wdr),'t)']);
                        end
                        
             case 3    % Base Excitation
                        if wdr == wn
                            warndlg(['The driving frequency is not the same to the natural frequency.   They must not be the same in this system   Please inset the value correctly.'])
                            XT = 0*t;
                        else
                         wd     = wn*sqrt(1-z^2);
                         Y      = f0;
                         Theta1 = atan(2*z*wn*wdr/(wn^2 - wdr^2));
                         Theta2 = atan(wn/(2*z*wdr));
                         CCC    = wn*Y*sqrt((wn^2 + (2*z*wdr)^2)/((wn^2 - wdr^2)^2 + (2*z*wn*wdr)^2));
                         Phi    = (wd*(x0 -CCC*cos(Theta1 + Theta2)))/(v0 + z*wn*(x0 - CCC*cos(Theta1 + Theta2)) - wdr*CCC*sin(Theta1 + Theta2));
                         A      = (x0 - CCC*cos(Theta1 + Theta2))/(sin(Phi));
                         XT     = A*exp(-z*wn*t).*sin(wd*t + Phi) + CCC * cos(wdr*t -(Theta1 + Theta2));
                         
                         set(handles.edit10,'string',['x(t) = ', sprintf('%4.3f',A),' sin(',sprintf('%4.3f',wd),'t + ',...
                            sprintf('%4.3f',Phi),') + ',sprintf('%4.3f',CCC),'cos(',sprintf('%4.3f',wdr),...
                            't - ',sprintf('%4.3f',Theta1 + Theta2),')']);
                        end
             case 4    % Impulse
                        wd = wn*sqrt(1-z^2);
                        vv0 = f0/wdr;
                        Phi   = atan((wd*x0 )/(v0 + z*wn*x0 ));
                        A     = sqrt(((v0 + z*wn*x0)^2 +(x0*wd)^2)/(wd^2)); 
                        XT    = A*exp(-z*wn*t).*sin(wd*t + Phi) + (vv0/wd)*exp(-z*wn*t).*sin(wd*t);
                        if x0 == 0 || v0 == 0
                            set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',vv0/wd),...
                                'sin(',sprintf('%4.3f',wn),'t)']);
                        else
                            set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',A),...
                                'sin(',sprintf('%4.3f',wn),'t + ',sprintf('%4.3f',Phi),...
                                ') + ',sprintf('%4.3f',vv0/wd),'sin(',sprintf('%4.3f',wn),'t)']);
                        end
             case 5    % Unit Function
                 wd    = wn*sqrt(1 - z^2);
                        F0    = f0;     
                        k     = wdr;
                        Theta = atan(z/(sqrt(1 - z^2)));
                        XT    = F0/k - (F0/(k*sqrt(1-z^2)))*exp(-z*wn*t).*cos(wd*t - Theta);
                        Xmax  = 2*F0/k;     
                        Tp    = pi/wd;      
                        Ts    = 3.5/z/wn;
                        
                        set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',F0/k),...
                            ' - ',sprintf('%4.3f',F0/(k*sqrt(1-z^2))),'cos(',sprintf('%4.3f',wn),...
                            't)']);
         end
                
          
         
    case 6      % Critical damp + force
                warndlg('This function is no ready yet. Please wait for a while')
                
                
    case 7      % Underdamp + force
        switch Fmanu
            case 1      % harmonic
                    if CS == 3
                        wd    = wn*sqrt(1-z^2);
                        T     = f0/sqrt((wn^2 - wdr^2)^2 + (2*z*wn*wdr)^2);
                        X     = f0/((wn^2 - wdr^2)^2 + (2*z*wn*wdr)^2);
                        Theta = atan(2*z*wn*wdr/(wn^2 - wdr^2));
                        Phi   = atan((wd*(x0 + X*cos(Theta)))/(v0 + (x0 + X*cos(Theta))*z*wn + wdr*X*sin(Theta)));
                        A     = (x0 + X*cos(Theta))/sin(Phi);
                        XT    = A*exp(-z*wn*t).*sin(wd*t + Phi) + T*sin(wdr*t + Theta);
                        set(handles.edit10, 'string',['x(t) = ',sprintf('%4.3f',A),'exp(',...
                            sprintf('%4.3f',-z*wn),'t) sin(', sprintf('%4.3f',wd),'t + ',...
                            sprintf('%4.3f',Phi),') + ',sprintf('%4.3f',T),'sin(',sprintf('%4.3f',wdr),...
                            't + ',sprintf('%4.3f',Theta),')']);
                    else
                        wd = wn*sqrt(1-z^2);
                        X     = f0/sqrt((wn^2 - wdr^2)^2 + (2*z*wn*wdr)^2);
                        Theta = atan(2*z*wn*wdr/(wn^2 - wdr^2));
                        Phi = atan((wd*(x0 - X*cos(Theta)))/(v0 + (x0 - X*cos(Theta))*z*wn - wdr*X*sin(Theta)));
                        A     = (x0 - X*cos(Theta))/sin(Phi);
                        XT = A*exp(-z*wn*t).*sin(wd*t + Phi) + X*cos(wdr*t - Theta);
                        set(handles.edit10, 'string',['x(t) = ',sprintf('%4.3f',A),'exp(',...
                            sprintf('%4.3f',-z*wn),'t) sin(', sprintf('%4.3f',wd),'t + ',...
                            sprintf('%4.3f',Phi),') + ',sprintf('%4.3f',X),'cos(',sprintf('%4.3f',wdr),...
                            't - ',sprintf('%4.3f',Theta),')']);
                    end
            case 2      % resonance         
                
            case 3      % Base excitation
                         wd     = wn*sqrt(1-z^2);
                         Y      = f0;
                         Theta1 = atan(2*z*wn*wdr/(wn^2 - wdr^2));
                         Theta2 = atan(wn/(2*z*wdr));
                         CCC    = wn*Y*sqrt((wn^2 + (2*z*wdr)^2)/((wn^2 - wdr^2)^2 + (2*z*wn*wdr)^2));
                         Phi    = (wd*(x0 -CCC*cos(Theta1 + Theta2)))/(v0 + z*wn*(x0 - CCC*cos(Theta1 + Theta2)) - wdr*CCC*sin(Theta1 + Theta2));
                         A      = (x0 - CCC*cos(Theta1 + Theta2))/(sin(Phi));
                         XT     = A*exp(-z*wn*t).*sin(wd*t + Phi) + CCC * cos(wdr*t -(Theta1 + Theta2));
                         
                         set(handles.edit10,'string',['x(t) = ', sprintf('%4.3f',A),'exp(',...
                            sprintf('%4.3f',-z*wn),'t) sin(',sprintf('%4.3f',wd),'t + ',...
                            sprintf('%4.3f',Phi),') + ',sprintf('%4.3f',CCC),'cos(',sprintf('%4.3f',wdr),...
                            't - ',sprintf('%4.3f',Theta1 + Theta2),')']);

            case 4      % Impuse
                        wd    = wn*sqrt(1-z^2);
                        vv0   = f0/wdr;
                        Phi   = atan((wd*x0 )/(v0 + z*wn*x0 ));
                        A     = sqrt(((v0 + z*wn*x0)^2 +(x0*wd)^2)/(wd^2)); 
                        XT    = A*exp(-z*wn*t).*sin(wd*t + Phi) + (vv0/wd)*exp(-z*wn*t).*sin(wd*t);
                        if x0 == 0 || v0 == 0
                            set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',vv0/wd),'exp(',...
                                sprintf('%4.3f',-z*wn),'t) sin(',sprintf('%4.3f',wd),'t)']);
                        else
                            set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',A),'exp(',...
                            sprintf('%4.3f',-z*wn),'t) sin(', sprintf('%4.3f',wd),'t + ',...
                            sprintf('%4.3f',Phi),') + ',sprintf('%4.3f',vv0/wd),'exp(',...
                                sprintf('%4.3f',-z*wn),'t) sin(',sprintf('%4.3f',wd),'t)']);
                        end
            case 5      % Unit Function
                        wd    = wn*sqrt(1 - z^2);
                        F0    = f0;     
                        k     = wdr;
                        Theta = atan(z/(sqrt(1 - z^2)));
                        XT    = F0/k - (F0/(k*sqrt(1-z^2)))*exp(-z*wn*t).*cos(wd*t - Theta);
                        Xmax  = 2*F0/k;     
                        Tp    = pi/wd;      
                        Ts    = 3.5/z/wn;
                        
                        set(handles.edit10,'string',['x(t) = ',sprintf('%4.3f',F0/k),...
                            ' - ',sprintf('%4.3f',F0/(k*sqrt(1-z^2))),'exp(',...
                            sprintf('%4.3f',-z*wn),'t) cos(',sprintf('%4.3f',wd),...
                            't - ',sprintf('%4.3f',Theta),')']);
                
        end
    case 8      % Over damp + force
                warndlg('This function is no ready yet. Please wait for a while')
end


XTX(n,:)= XT;
plot(handles.axes1,t,XTX), xlabel(handles.axes1,'Time, t'), ylabel(handles.axes1,'Displacement of x(t)')
legend(handles.axes1,n)
n = 1+n;



% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global Cm Cn n t XTX
% Reset button
set(handles.radiobutton1,'value',1); Cm = 1;
set(handles.edit8,'string','0');
set(handles.edit8,'enable','off');

set(handles.radiobutton16,'value',1); Cn = 1;
set(handles.edit2,'string','0');
set(handles.edit2,'enable','off');
set(handles.edit3,'string','0');
set(handles.edit3,'enable','off');
set(handles.edit4,'string','0');
set(handles.edit5,'string','40');
set(handles.uipanel6,'visible','off');
set(handles.popupmenu2,'enable','off');

set(handles.edit6,'string','0');
set(handles.edit7,'string','0');
set(handles.edit9,'string','0');
set(handles.edit10,'string','Reset everything');

n=1;
XTX = zeros(size(t));
cla(handles.axes1,'reset'); 





function edit4_Callback(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit4 as text
%        str2double(get(hObject,'String')) returns contents of edit4 as a double


% --- Executes during object creation, after setting all properties.
function edit4_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit4 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit5_Callback(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit5 as text
%        str2double(get(hObject,'String')) returns contents of edit5 as a double


% --- Executes during object creation, after setting all properties.
function edit5_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit5 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit6_Callback(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit6 as text
%        str2double(get(hObject,'String')) returns contents of edit6 as a double


% --- Executes during object creation, after setting all properties.
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit6 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit7_Callback(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit7 as text
%        str2double(get(hObject,'String')) returns contents of edit7 as a double


% --- Executes during object creation, after setting all properties.
function edit7_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit7 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit8_Callback(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit8 as text
%        str2double(get(hObject,'String')) returns contents of edit8 as a double


% --- Executes during object creation, after setting all properties.
function edit8_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit8 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end



function edit9_Callback(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit9 as text
%        str2double(get(hObject,'String')) returns contents of edit9 as a double


% --- Executes during object creation, after setting all properties.
function edit9_CreateFcn(hObject, eventdata, handles)
% hObject    handle to edit9 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu1


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end





% --- Executes on button press in radiobutton11.
function radiobutton11_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton11 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton11


% --- Executes on button press in radiobutton12.
function radiobutton12_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton12 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of radiobutton12


% --- Executes when selected object is changed in uipanel11.
function uipanel11_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel11 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
global zeta
global Cm


switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'radiobutton1'  % undamped
        % Code for when radiobutton1 is selected.
        set(handles.edit8,'string','0');
        set(handles.edit8,'enable','off');
        set(handles.edit10, 'string','Undamped system');
        Cm = 1;

    case 'radiobutton2' % critical damped
        % Code for when radiobutton2 is selected.
        set(handles.edit8,'string','1');
        set(handles.edit8,'enable','off');
        set(handles.edit10, 'string','Critical damped system');
        Cm = 2;
        
        
    case 'radiobutton3' % underdamped
        % Code for when togglebutton1 is selected.
        set(handles.edit8,'enable','on');
        set(handles.edit8,'string','0.01');
        set(handles.edit10, 'string','Underdamped system');
        Cm = 3;
        
    otherwise              % Over damp
        % Code for when there is no match.
        set(handles.edit8,'enable','on');
        set(handles.edit8,'string','2');
        set(handles.edit10, 'string','Over damped system');
        Cm = 4;
end


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cell array
%        contents{get(hObject,'Value')} returns selected item from popupmenu2
global wdr
global wn
global Fmanu CS
wn = str2num(get(handles.edit9,'string'));

val = get(hObject,'Value');
switch val
    
    case 1    % Harmonic
        set(handles.edit10, 'string','Harmonic');
        set(handles.edit3, 'string','0');
        set(handles.edit3, 'enable','on');
        set(handles.text3,'string','f0 :');
        
        set(handles.radiobutton6, 'visible','off');
        set(handles.radiobutton7, 'visible','off');
        set(handles.radiobutton8, 'visible','on');
        set(handles.radiobutton8, 'value',1);CS=2;
        set(handles.radiobutton9, 'visible','on');
        
        set(handles.radiobutton1,'enable','on');
        set(handles.radiobutton2,'enable','off');
        set(handles.radiobutton3,'enable','on');
        set(handles.radiobutton19,'enable','off');
        
        set(handles.text4,'string','w :');
        set(handles.text3,'string','f0 :');
        set(handles.edit6,'enable','on');
        set(handles.edit7,'enable','on');
        
        Fmanu = 1;
    case 2   % Resonance
        wdr = wn;
        set(handles.edit3, 'string',num2str(wn));
        set(handles.edit3, 'enable','off');
        set(handles.edit10, 'string','Resonance');
        set(handles.text3,'string','f0 :');
        
        set(handles.radiobutton6, 'visible','off');
        set(handles.radiobutton7, 'visible','off');
        set(handles.radiobutton8, 'visible','on');
        set(handles.radiobutton9, 'visible','on');
        set(handles.radiobutton8, 'value',1);CS = 2;
        set(handles.radiobutton1, 'value',1);
        
        set(handles.edit8,'string','0');
        set(handles.edit8,'enable','off');
        set(handles.edit10, 'string','Resonance');
        
        set(handles.radiobutton1,'enable','on');
        set(handles.radiobutton2,'enable','off');
        set(handles.radiobutton3,'enable','off');
        set(handles.radiobutton19,'enable','off');
        
        set(handles.text4,'string','w :');
        set(handles.text3,'string','f0 :');
        set(handles.edit6,'enable','on');
        set(handles.edit7,'enable','on');
        
        Cm = 1;
        
        Fmanu = 2;
    case 3   % Base Excitation
        set(handles.edit10, 'string','Base Excitation');
        set(handles.edit3, 'string','0');
        set(handles.edit3, 'enable','on');
        set(handles.text3,'string','f0 :');
        
        set(handles.radiobutton6, 'visible','off');
        set(handles.radiobutton7, 'visible','on');
        set(handles.radiobutton7, 'value',1);
        set(handles.radiobutton8, 'visible','off');
        set(handles.radiobutton9, 'visible','off');
        
        set(handles.radiobutton1,'enable','on');
        set(handles.radiobutton2,'enable','off');
        set(handles.radiobutton3,'enable','on');
        set(handles.radiobutton19,'enable','off');
        
        set(handles.text4,'string','wb :');
        set(handles.text3,'string','Y :');
        set(handles.edit6,'enable','on');
        set(handles.edit7,'enable','on');
        
        Fmanu = 3;
    case 4   % Impulse
        set(handles.edit10, 'string','Impulse');
        set(handles.edit3, 'string','1');
        set(handles.edit3, 'enable','on');
        set(handles.text4,'string','m :');
        set(handles.text3,'string','F^ :');
        
        set(handles.radiobutton6, 'visible','on');
        set(handles.radiobutton6, 'value',1);
        set(handles.radiobutton7, 'visible','off');
        set(handles.radiobutton8, 'visible','off');
        set(handles.radiobutton9, 'visible','off');
        
        set(handles.radiobutton1,'enable','on');
        set(handles.radiobutton2,'enable','off');
        set(handles.radiobutton3,'enable','on');
        set(handles.radiobutton19,'enable','off');
        
        set(handles.edit6,'enable','on');
        set(handles.edit7,'enable','on');
        
        Fmanu = 4;
    case 5  % Step Function
        set(handles.edit10, 'string','Step Function')
        set(handles.edit3, 'string','0');
        set(handles.edit3, 'enable','on');
        set(handles.text3,'string','F0 :');
        
        
        set(handles.radiobutton6, 'visible','on');
        set(handles.radiobutton6, 'value',1);
        set(handles.radiobutton7, 'visible','off');
        set(handles.radiobutton8, 'visible','off');
        set(handles.radiobutton9, 'visible','off');
        
        set(handles.radiobutton1,'enable','on');
        set(handles.radiobutton2,'enable','off');
        set(handles.radiobutton3,'enable','on');
        set(handles.radiobutton19,'enable','off');
        
        set(handles.text4,'string','k :');
        set(handles.text3,'string','F0 :');
        set(handles.edit6,'string','0');
        set(handles.edit6,'enable','off');
        set(handles.edit7,'string','0');
        set(handles.edit7,'enable','off');
        
        
        Fmanu = 5;
end
% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes when selected object is changed in uipanel12.
function uipanel12_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel12 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)
global Cn
global Fmanu
global CS

switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'radiobutton16'   % Free response
        % Code for when radiobutton1 is selected.
        set(handles.edit2,'string','0');
        set(handles.edit2,'enable','off');
        set(handles.edit3,'string','0');
        set(handles.edit3,'enable','off');
        set(handles.uipanel6,'visible','off');
        set(handles.popupmenu2,'enable','off');
        
        set(handles.radiobutton1,'enable','on');
        set(handles.radiobutton2,'enable','on');
        set(handles.radiobutton3,'enable','on');
        set(handles.radiobutton19,'enable','on');
        Cn = 1;
        
    case 'radiobutton17'    % Force response
        % Code for when radiobutton2 is selected.
        set(handles.edit2,'string','0'); set(handles.edit2,'enable','on');
        set(handles.edit3,'string','0'); set(handles.edit3,'enable','on');
        set(handles.uipanel6,'visible','on');
        set(handles.popupmenu2,'enable','on');
        set(handles.popupmenu2,'value',1);
        
        set(handles.edit10, 'string','Harmonic');
        set(handles.edit3, 'string','0');
        set(handles.edit3, 'enable','on');
        set(handles.text3,'string','f0 :');
        
        % cos and sin term
        set(handles.radiobutton6, 'visible','off');
        set(handles.radiobutton7, 'visible','off');
        set(handles.radiobutton8, 'visible','on');
        set(handles.radiobutton8, 'value',1); CS = 2;
        set(handles.radiobutton9, 'visible','on');
        
        %damp box
        val = get(handles.radiobutton3,'Value');
        set(handles.radiobutton1,'enable','on');
            if val == 1
                set(handles.radiobutton3,'enable','on');
                 Fmanu = 1;
            else
                set(handles.radiobutton1,'value',1);  
                set(handles.edit8, 'string','0');
                set(handles.edit8, 'enable','off');   
                 Fmanu = 1;
            end
        set(handles.radiobutton2,'enable','off');
        set(handles.radiobutton3,'enable','on');
        set(handles.radiobutton19,'enable','off');
        
        
       
        Cn = 2;
        
    otherwise
end


% --- Executes when selected object is changed in uipanel6.
function uipanel6_SelectionChangeFcn(hObject, eventdata, handles)
% hObject    handle to the selected object in uipanel6 
% eventdata  structure with the following fields (see UIBUTTONGROUP)
%	EventName: string 'SelectionChanged' (read only)
%	OldValue: handle of the previously selected object or empty if none was selected
%	NewValue: handle of the currently selected object
% handles    structure with handles and user data (see GUIDATA)

global CS

switch get(eventdata.NewValue,'Tag') % Get Tag of selected object.
    case 'radiobutton6'     % None
        CS = 0;
    case 'radiobutton7'     % Cos and Sin
        CS = 1;
    case 'radiobutton8'     % Cos
        CS = 2;
    case 'radiobutton9'     % Sin
        CS = 3;
end


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over edit10.
function edit10_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --- Executes during object deletion, before destroying properties.
function edit10_DeleteFcn(hObject, eventdata, handles)
% hObject    handle to edit10 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

Contact us