function varargout = simulador1(varargin)
% SIMULADOR1 M-file for simulador1.fig
%      SIMULADOR1, by itself, creates a new SIMULADOR1 or raises the existing
%      singleton*.
%
%      H = SIMULADOR1 returns the handle to a new SIMULADOR1 or the handle to
%      the existing singleton*.
%
%      SIMULADOR1('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in SIMULADOR1.M with the given input arguments.
%
%      SIMULADOR1('Property','Value',...) creates a new SIMULADOR1 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before simulador1_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to simulador1_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

% Copyright 2002-2003 The MathWorks, Inc.

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

% Last Modified by GUIDE v2.5 09-May-2007 01:22:59

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @simulador1_OpeningFcn, ...
                   'gui_OutputFcn',  @simulador1_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 simulador1 is made visible.
function simulador1_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
%%% Inicializar variables

handles.valores.masa = 1;
handles.valores.viscosidad = 1;
handles.valores.elastica = 1;
handles.Tmax=10;
handles.Ymax=1;
set(handles.text8,'String','T.Max') 
set(handles.text3,'String','Viscosidad')
handles=set_time_values(handles);
guidata(hObject,handles)

% 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 simulador1 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = simulador1_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;


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)

oscilador1(handles.valores.masa,handles.valores.viscosidad,handles.valores.elastica,handles.Tmax)

% 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)



function edit1_Callback(hObject, eventdata, handles)
% hObject    handle to edit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
masa = str2double(get(hObject, 'String'));
if isnan(masa)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
handles.valores.masa = masa;
handles=set_time_values(handles);
guidata(hObject,handles)
% Hints: get(hObject,'String') returns contents of edit1 as text
%        str2double(get(hObject,'String')) returns contents of edit1 as a double


% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
set(hObject, 'String', '1');
% hObject    handle to edit1 (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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



function edit2_Callback(hObject, eventdata, handles)
viscosidad = str2double(get(hObject, 'String'));
if isnan(viscosidad)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
handles.valores.viscosidad = viscosidad;
handles=set_time_values(handles);
guidata(hObject,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 edit2_CreateFcn(hObject, eventdata, handles)
set(hObject, 'String', '1');

% 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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end





function edit3_Callback(hObject, eventdata, handles)
elastica = str2double(get(hObject, 'String'));
if isnan(elastica)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
handles.valores.elastica = elastica;
handles=set_time_values(handles);
guidata(hObject,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 edit3_CreateFcn(hObject, eventdata, handles)
set(hObject, 'String', '1');
% 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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end

function handles=set_time_values(handles)
M=handles.valores.masa;V=handles.valores.viscosidad;K=handles.valores.elastica;
handles.valores.Vcrit =  V*V-(4*M*K);
set(handles.text5,'String',strcat('V.Critico: ',num2str(handles.valores.Vcrit)))
handles.valores.Texp =  2*M/V;
st=(2*pi)/(sqrt((K/M)-power((V/(2*M)),2)));
handles.valores.Posc = st;
r=num2str(st)
set(handles.text6,'String',strcat('T.Exp: ',num2str(handles.valores.Texp))) 
set(handles.text7,'String',strcat('Per.Osc: ',r))
set(handles.pushbutton1,'String','Simular')





function edit8_Callback(hObject, eventdata, handles)
Tmax = str2double(get(hObject, 'String'));
if isnan(Tmax)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
handles.Tmax = Tmax;
guidata(hObject,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)
set(hObject, 'String', '10');
% 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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end


%% new stuff

function edit9_Callback(hObject, eventdata, handles)
Ymax = str2double(get(hObject, 'String'));
if isnan(Ymax)
    set(hObject, 'String', 0);
    errordlg('Input must be a number','Error');
end
handles.Ymax = Ymax;
guidata(hObject,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 edit9_CreateFcn(hObject, eventdata, handles)
set(hObject, 'String', '10');
% 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
    set(hObject,'BackgroundColor','white');
else
    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end



% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
cla;
% 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)


