// This GUI file is generated by guibuilder version 2.2
//////////
f=figure('figure_position',[-4,-4],'figure_size',[1024,746],'auto_resize','off','background',[33],'figure_name','Solución de Ecuaciones No Lineales - Método de Bisección');
//////////
delmenu(f.figure_id,gettext('File'))
delmenu(f.figure_id,gettext('?'))
delmenu(f.figure_id,gettext('Tools'))
toolbar(f.figure_id,'on')
handles.dummy = 0;
handles.title=uicontrol(f,'unit','normalized','BackgroundColor',[0,0.6,0.8],'Enable','on','FontAngle','normal','FontName','Verdana','FontSize',[36],'FontUnits','points','FontWeight','bold','ForegroundColor',[1,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0,0.920245398773,1,0.075664621677],'Relief','flat','SliderStep',[0.01,0.1],'String','Método de Bisección','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','title','Callback','')
handles.descrip=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.003952569170,0.828220858896,0.932806324111,0.073619631902],'Relief','flat','SliderStep',[0.01,0.1],'String','Por medio de este método, se puede encontrar una raíz en una f(x), dado el intervalo [a,b], donde a < b. La raíz debe ser comprendida dentro del intervalo dado.','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','descrip','Callback','')
handles.Requisitos=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.005270092227,0.460122699387,0.312252964427,0.325153374233],'Relief','ridge','SliderStep',[0.01,0.1],'String','UnName3','Style','frame','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','Requisitos','Callback','')
handles.t=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.773006134969,0.106719367589,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Datos Iniciales','Style','text','Value',[0],'VerticalAlignment','bottom','Visible','on','Tag','t','Callback','')
handles.t1=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.730061349693,0.118577075099,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Ingrese f(x) =','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','t1','Callback','')
handles.t2=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.680981595092,0.118577075099,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Ingrese tolerancia: ','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','t2','Callback','')
handles.t3=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.644171779141,0.118577075099,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Ingrese lím. inferior: ','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','t3','Callback','')
handles.t4=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.607361963190,0.118577075099,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Ingrese lím. superior:','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','t4','Callback','')
handles.e1=uicontrol(f,'unit','normalized','BackgroundColor',[1,1,1],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.134387351779,0.723926380368,0.155467720685,0.024539877301],'Relief','sunken','SliderStep',[0.01,0.1],'String','','Style','edit','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','e1','Callback','')
handles.e2=uicontrol(f,'unit','normalized','BackgroundColor',[1,1,1],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.134387351779,0.676891615542,0.155467720685,0.024539877301],'Relief','sunken','SliderStep',[0.01,0.1],'String','','Style','edit','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','e2','Callback','')
handles.e3=uicontrol(f,'unit','normalized','BackgroundColor',[1,1,1],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.134387351779,0.638036809816,0.155467720685,0.024539877301],'Relief','sunken','SliderStep',[0.01,0.1],'String','','Style','edit','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','e3','Callback','')
handles.e4=uicontrol(f,'unit','normalized','BackgroundColor',[1,1,1],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.134387351779,0.597137014315,0.155467720685,0.024539877301],'Relief','sunken','SliderStep',[0.01,0.1],'String','','Style','edit','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','e4','Callback','')
handles.indicador=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.015810276680,0.478527607362,0.289855072464,0.038854805726],'Relief','flat','SliderStep',[0.01,0.1],'String',' ','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','indicador','Callback','')
handles.Respuestas=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.005270092227,0.073619631902,0.312252964427,0.361963190184],'Relief','ridge','SliderStep',[0.01,0.1],'String','UnName14','Style','frame','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','Respuestas','Callback','')
handles.r=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.423312883436,0.106719367589,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Respuesta','Style','text','Value',[0],'VerticalAlignment','bottom','Visible','on','Tag','r','Callback','')
handles.r1=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.368098159509,0.106719367589,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Raíz encontrada:','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','r1','Callback','')
handles.r2=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.325153374233,0.106719367589,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','f(x) en Raíz','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','r2','Callback','')
handles.r3=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.282208588957,0.118577075099,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Nº de iteraciones:','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','r3','Callback','')
handles.r4=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.239263803681,0.146245059289,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String','Tiempo de ejecución:','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','r4','Callback','')
handles.resp1=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.173913043478,0.368098159509,0.130434782609,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String',' ','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','resp1','Callback','')
handles.resp2=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.173913043478,0.325153374233,0.130434782609,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String',' ','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','resp2','Callback','')
handles.resp3=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.173913043478,0.282208588957,0.130434782609,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String',' ','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','resp3','Callback','')
handles.resp4=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','left','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.173913043478,0.239263803681,0.130434782609,0.024539877301],'Relief','flat','SliderStep',[0.01,0.1],'String',' ','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','resp4','Callback','')
handles.error=uicontrol(f,'unit','normalized','BackgroundColor',[0.8,0.8,0.8],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.011857707510,0.094069529652,0.289855072464,0.118609406953],'Relief','flat','SliderStep',[0.01,0.1],'String',' .','Style','text','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','error','Callback','')
handles.calcular=uicontrol(f,'unit','normalized','BackgroundColor',[0.6,0.6,0.6],'Enable','on','FontAngle','normal','FontName','verdana','FontSize',[10],'FontUnits','points','FontWeight','normal','ForegroundColor',[0,0,0],'HorizontalAlignment','center','ListboxTop',[],'Max',[1],'Min',[0],'Position',[0.134387351779,0.546012269939,0.158102766798,0.042944785276],'Relief','raised','SliderStep',[0.01,0.1],'String','Calcular','Style','pushbutton','Value',[0],'VerticalAlignment','middle','Visible','on','Tag','calcular','Callback','calcular_callback(handles)')
handles.graf= newaxes();handles.graf.margins = [ 0 0 0 0];handles.graf.axes_bounds = [0.357707509881,0.226993865031,0.610671936759,0.699386503067];


//////////
// Callbacks are defined as below. Please do not delete the comments as it will be used in coming version
//////////



function calcular_callback(handles)
//Write your callback for  calcular  here
handles.graf.auto_clear = 'on';
fx = gettext(handles.e1.String);
deff('y=f(x)','y = '+fx);
format('v',15);
if  (strtod(gettext(handles.e3.String))==0) then
    if(gettext(handles.e3.String)~='0') then
    handles.indicador.String = 'Límite inferior no es un número';
    handles.indicador.BackgroundColor = [1,0,0];
    end

elseif  (strtod(gettext(handles.e4.String))==0) then
    if(gettext(handles.e4.String)~='0') then
    handles.indicador.String = 'Límite superior no es un número';
    handles.indicador.BackgroundColor = [1,0,0];
    end

else
    handles.indicador.BackgroundColor = [0.8,0.8,0.8];
    handles.indicador.String ='';
    if strtod(gettext(handles.e2.String))<=0 then
        handles.indicador.String ='Tolerancia debe ser mayor a cero';
        handles.indicador.BackgroundColor = [1,0,0];
    else
    handles.indicador.String = 'Datos ingresados correctamente';
    handles.indicador.BackgroundColor = [0,1,0];
    a = strtod(gettext(handles.e3.String));
    b = strtod(gettext(handles.e4.String));
    eps = strtod(gettext(handles.e2.String));
if (b<a) then //si se ingresan los limites al reves
    c = a;
    a = b;
    b = c;
end
//Grafico de funcion
if ~isempty(handles.graf.children) then
delete(handles.graf.children);
end

xt =linspace(a,b,1000);
y = f(xt);
plot(xt,0,'colo','red');
handles.graf.auto_clear = 'off';
plot(xt,y,'colo','blue');
xgrid;

tic();
k=ceil((log10((b-a)/eps))/log10(2));//iteraciones necesarias anticipadas
ind=1;//asume el exito del proyecto, puede cambiar despues
i=0;
//for i=1:k//cambio de for por while
while(i <=k & ind == 1)
 c=(a+b)/2;
// printf("\nAproximacion #%i: %f",i,c);  
 if f(a)*f(c) <= 0 then
  b=c;
 elseif f(c)*f(b) <= 0 then
    a=c;
 else
  t2=toc();//toma tiempo 2
  ind=-1;//fallo de metodo
 end
 i=i+1;
end
if ind == 1 then
x=c;
t2=toc();
end

if ind==-1 then //fallo de metodo
handles.error.BackgroundColor = [1,0,0];
handles.error.String ="No se encontro raiz en el intervalo dado. ";

else //metodo exitoso
handles.resp1.String = string(x);
handles.resp2.String = string(f(x));
handles.resp3.String = string(k);
handles.resp4.String = string(t2)+' seg.';
handles.error.BackgroundColor = [0,0.8,0];
handles.error.String ="Método concluido exitosamente.";

end 
end
end
endfunction


