function BISECT_adm(action) global scale NewXLim NewYLim X switch action case 'l_x' h=findobj(gcbf,'Tag','l_x'); x=get(h,'String'); x=eval(x); h=findobj(gcbf,'Tag','my_fcn'); f=get(h,'String'); f=eval(f); set(findobj(gcbf,'Tag','f(l_x)'),'String',num2str(f)) if gcbo==findobj(gcbf,'Tag','l_x') X={}; X{1,1}='left x'; X{1,2}='right x'; h=findobj(gcbf,'Tag','r_x'); if ~isempty(get(h,'String')) rx=eval(get(h,'String')); h=findobj(gcbf,'Tag','curr_int'); set(h,'XData',[x rx]) end end case 'm_x' YLim=get(gca,'YLim'); dy=diff(YLim); h=findobj(gcbf,'Tag','m_x'); x=get(h,'String'); x=eval(x); h=findobj(gcbf,'Tag','my_fcn'); f=get(h,'String'); f=eval(f); set(findobj(gcbf,'Tag','f(m_x)'),'String',num2str(f)) if gcbo==findobj(gcbf,'Tag','m_x') X={}; X{1,1}='left x'; X{1,2}='right x'; end h=findobj(gcbf,'Tag','cut'); set(h,'Visible','off') pause(1) set(h,'XData',[x x],'YData',[-1 1]*dy/50,'Visible','on') case 'r_x' h=findobj(gcbf,'Tag','r_x'); x=get(h,'String'); x=eval(x); h=findobj(gcbf,'Tag','my_fcn'); f=get(h,'String'); f=eval(f); set(findobj(gcbf,'Tag','f(r_x)'),'String',num2str(f)) if gcbo==findobj(gcbf,'Tag','r_x') X={}; X{1,1}='left x'; X{1,2}='right x'; h=findobj(gcbf,'Tag','l_x'); if ~isempty(get(h,'String')) lx=eval(get(h,'String')); h=findobj(gcbf,'Tag','curr_int'); set(h,'XData',[lx x]) end end case 'update' hl=findobj(gcbf,'Tag','l_x'); hr=findobj(gcbf,'Tag','r_x'); l_x=eval(get(hl,'String')); r_x=eval(get(hr,'String')); % h=findobj(gcbf,'Tag','curr_int'); % set(h,'XData',[l_x r_x]) % drawnow X{size(X,1)+1,1}=num2str(l_x,'%1.8f') X{size(X,1) ,2}=num2str(r_x,'%1.8f') case 'left' hm=findobj(gcbf,'Tag','m_x'); m_x=get(hm,'String'); hr=findobj(gcbf,'Tag','r_x'); r_x=get(hr,'String'); set(hr,'String',m_x) hl=findobj(gcbf,'Tag','l_x'); l_x=get(hl,'String'); if size(X,1)==1 X{2,1}=l_x; X{2,2}=r_x; end h=findobj(gcbf,'Tag','curr_int'); set(h,'XData',[eval(l_x) eval(m_x)]) drawnow new_m_x=(eval(m_x)+eval(l_x))/2; set(hm,'String',num2str(new_m_x,'%1.8f')) BISECT_adm('r_x') BISECT_adm('m_x') BISECT_adm('update') case 'right' hm=findobj(gcbf,'Tag','m_x'); m_x=get(hm,'String'); hl=findobj(gcbf,'Tag','l_x'); l_x=get(hl,'String'); set(hl,'String',m_x) hr=findobj(gcbf,'Tag','r_x'); r_x=get(hr,'String'); if size(X,1)==1 X{2,1}=l_x; X{2,2}=r_x; end h=findobj(gcbf,'Tag','curr_int'); set(h,'XData',[eval(m_x) eval(r_x)]) drawnow new_m_x=(eval(m_x)+eval(r_x))/2; set(hm,'String',num2str(new_m_x,'%1.8f')) BISECT_adm('l_x') BISECT_adm('m_x') BISECT_adm('update') case 'nits' h=findobj(gcbf,'Tag','nits'); nits=get(h,'String'); nits=eval(nits); for i=1:nits hm=findobj(gcbf,'Tag','f(m_x)'); hl=findobj(gcbf,'Tag','f(l_x)'); hr=findobj(gcbf,'Tag','f(r_x)'); fm=eval(get(hm,'String')); fl=eval(get(hl,'String')); fr=eval(get(hr,'String')); if fm*fl<0 disp('left') BISECT_adm('left') elseif fm*fr<0 disp('right') BISECT_adm('right') end end case 'tol' h=findobj(gcbf,'Tag','tol'); tol=get(h,'String'); tol=eval(tol); dx=1; while dx>tol hm=findobj(gcbf,'Tag','f(m_x)'); hl=findobj(gcbf,'Tag','f(l_x)'); hr=findobj(gcbf,'Tag','f(r_x)'); fm=eval(get(hm,'String')); fl=eval(get(hl,'String')); fr=eval(get(hr,'String')); if fm*fl<0 disp('left') BISECT_adm('left') elseif fm*fr<0 disp('right') BISECT_adm('right') end hl=findobj(gcbf,'Tag','l_x'); hr=findobj(gcbf,'Tag','r_x'); l_x=eval(get(hl,'String')); r_x=eval(get(hr,'String')); dx=r_x-l_x; end case 'zoom in' scale=.5; set(gcf,'WindowButtonDownFcn','BISECT_adm(''zoom'')') case 'zoom out' scale=2; set(gcf,'WindowButtonDownFcn','BISECT_adm(''zoom'')') case 'zoom' cp=get(gca,'CurrentPoint'); cp=cp(1,1:2); XLim=get(gca,'XLim'); YLim=get(gca,'YLim'); dX=scale*diff(XLim); dY=scale*diff(YLim); NewXLim=[cp(1)-dX/2 cp(1)+dX/2]; NewYLim=[cp(2)-dY/2 cp(2)+dY/2]; set(gca,'XLim',NewXLim,'YLim',NewYLim) h=findobj(gcbf,'Tag','cut'); set(h,'YData',[-1 1]*dY/50); px=get(get(gca,'xlabel'),'position'); px(1:2)=[sum(NewXLim)/2 NewYLim(1)-.1*diff(NewYLim)]; set(get(gca,'xlabel'),'position',px) py=get(get(gca,'ylabel'),'position'); py(1:2)=[NewXLim(1)-.1*diff(NewXLim) sum(NewYLim)/2]; set(get(gca,'ylabel'),'position',py) pt=get(get(gca,'title'),'position'); pt(1:2)=[sum(NewXLim)/2 NewYLim(2)+.05*diff(NewYLim)]; set(get(gca,'title'),'position',pt) BISECT_adm('plot_fcn') case 'choose_fcn' value=get(findobj(gcbf,'Tag','f_gallery'),'Value'); string=get(findobj(gcbf,'Tag','f_gallery'),'String'); f=string{value}; set(findobj(gcbf,'Tag','my_fcn'),'String',f) BISECT_adm('plot_fcn') case 'plot_fcn' delete(findobj(gcbf,'Tag','f_graph')) title('') f=get(findobj(gcbf,'Tag','my_fcn'),'String'); if isempty(f) disp('no graph to plot') else f=get(findobj(gcbf,'Tag','my_fcn'),'String'); XLim=get(gca,'XLim'); YLim=get(gca,'YLim'); dX=diff(XLim); x=XLim(1):dX/100:XLim(2); y=eval(f); line(x,eval(f),'Color','r','Tag','f_graph') title(['y = ' f]) axis([x(1) x(length(x)) min(y)-.5 max(y)+.5]); set(findobj('Tag','x_axis'),'XData',XLim) set(findobj('tag','y_axis'),'Ydata',YLim) set(gca,'XLim',XLim,'YLim',YLim) end end