function varargout = Interface(varargin)
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Interface_OpeningFcn, ...
'gui_OutputFcn', @Interface_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
clc
clear all
function Interface_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
guidata(hObject, handles);
function varargout = Interface_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
function cmdCalcular_Callback(hObject, eventdata, handles)
try
funcion=get(handles.txtFuncion,'string');
x0=str2double(get(handles.txtX0,'string'));
porcentajeError=str2double(get(handles.txtPorcentajeError,'string'));
syms x
iteracion=0;
errorCalculado=100;
f=sym(funcion);
derivada=diff(f,x);
set(handles.tabla,'Data',{})
if derivada==0
hold off
cla
set(handles.tabla,'Data',{})
set(handles.txtRaiz,'string','Nao existe raiz neste intervalo');
else
while errorCalculado>porcentajeError
fx=subs(f,x0);
dx=subs(derivada,x0);
x1=x0-(fx/dx);
errorCalculado=abs(((x1-x0)/x1)*100);
valores = {iteracion x0 x1 errorCalculado};
temp=get(handles.tabla,'data');
valoresNuevos=[valores;temp];
set(handles.tabla,'Data',valoresNuevos)
x0=x1;
iteracion=iteracion+1;
end
respuesta=sprintf('%0.16f',x1);
set(handles.txtRaiz,'string',respuesta);
hold off
handles.axes1=ezplot(f);
grid on;
hold on;
handles.axes1=plot(x1,subs(f,respuesta),'r*');
zoom on
end
catch
msgbox('Ocorreu um erro! Verifique se introduziu os dados corretamente e de forma adequada!','Error','error')
end
function cmdLimpar_Callback(hObject, eventdata, handles)
cla
set(handles.tabla,'Data',{})
set(handles.txtFuncion,'string','');
set(handles.txtX0,'string','');
set(handles.txtPorcentajeError,'string','');
set(handles.txtRaiz,'string','');
function txtFuncion_Callback(hObject, eventdata, handles)
function txtFuncion_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtX0_Callback(hObject, eventdata, handles)
function txtX0_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtPorcentajeError_Callback(hObject, eventdata, handles)
function txtPorcentajeError_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function txtRaiz_Callback(hObject, eventdata, handles)
function txtRaiz_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function sobre_Callback(hObject, eventdata, handles)
sair
function instrucoes_Callback(hObject, eventdata, handles)
instrucoes
function sair_Callback(hObject, eventdata, handles)
close