www.gusucode.com > Matlab动力系统和时间序列分析工具箱 > Matlab动力系统和时间序列分析工具箱/lab432/common/bif_diagr_dm.m
function varargout = bif_diagr_dm(varargin) % BIF_DIAGR_DM makes bifurcation diagram % gui-mode using: % BD=bif_diagr_dm; % batch-mode using: % BD=bif_diagr_dm(Fx,init,density,trans_steps,p) % Parameters: % Fx - cell array of right-side equations (at least one equation must contain parameter 'p' as control parameter) % init - cell array of initial conditions % density - number of plotted points on diagram for each parameter value % trans_steps - number of transient steps % p - control parameter vector % % BD - cell array, where BD{1} - control parameter, BD{2} - diagram data % % Example: % BD=bif_diagr_dm({'p*x1*(1-x1-x2)' 'p*x1*x2'},{'0.1' '0.1'},'500','100','3.4:0.001:3.6') % Last Modified by GUIDE v2.5 22-Sep-2005 13:27:23 % last modified 8.12.05 % Begin initialization code - DO NOT EDIT gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @bif_diagr_dm_OpeningFcn, ... 'gui_OutputFcn', @bif_diagr_dm_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 bif_diagr_dm is made visible. function bif_diagr_dm_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to bif_diagr_dm (see VARARGIN) % Choose default command line output for bif_diagr_dm handles.output = hObject; % Update handles structure guidata(hObject, handles); handles.auto=0; try N=length(varargin{1}); x={}; for i=1:N x{i}=['x' num2str(i)]; end set(handles.x,'string',x); set(handles.f,'string',varargin{1}); set(handles.init,'string',varargin{2}); set(handles.edit_length,'string',varargin{3}); set(handles.e_tr_steps,'string',varargin{4}); set(handles.edit_p,'string',varargin{5}); catch end if length(varargin)==5 % batch mode OK handles.auto=1; end guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = bif_diagr_dm_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure global bd_dm if handles.auto ok_Callback(handles.ok, [], handles); if nargout varargout{1} =bd_dm; end close(handles.figure); else if nargout uiwait; if nargout varargout{1} =bd_dm; end end end % --- Executes on button press in ok. function ok_Callback(hObject, eventdata, handles) % hObject handle to ok (see GCBO) % handles structure with handles and user data (see GUIDATA) global bd_dm bd_dm=[]; x=get(handles.x,'string'); L=str2num(get(handles.edit_length,'string')); init=get(handles.init,'string'); f=get(handles.f,'string'); p=eval(get(handles.edit_p,'string')); Dim=length(f); for i=1:Dim Init0(i)=str2double(init{i}); end if isempty(x) msgbox('No data for map'); return end s = which('bif_diagr_dm'); [pathstr,name,ext,versn] = fileparts(s); fid = fopen([pathstr '/tmp_map.m'],'w'); fprintf(fid,'function Y=tmp_map(X,p); \n'); fprintf(fid,'Y=zeros(1,%s); \n',num2str(length(x))); for i=1:Dim fprintf(fid,'%s=X(%i); \n',x{i},i); end for i=1:Dim fprintf(fid,'Y(%s)=%s; \n',num2str(i),f{i}); end fclose(fid); clear fid clear tmp_map %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% BD=zeros(L,length(p)); tr=str2num(get(handles.e_tr_steps,'string')); %#ok<ST2NM> for i=1:length(p) Init=Init0; for j=1:tr Init=tmp_map(Init,p(i)); end if ~isfinite(Init(1)) BD(:,i)=Init(1).*ones(L,1); continue end for j=1:L Init=tmp_map(Init,p(i)); BD(j,i)=Init(1); end end figure('numbertitle','off','name','Bifurcation diagram'); set(gcf,'color',[1 1 1]); plot(p,BD,'.k','markersize',1); grid on xlim([p(1) p(end)]); xlabel('p'); ylabel('x1*'); bd_dm{1}=p; bd_dm{2}=BD; clear tmp_map % --- Executes on button press in cancel. function cancel_Callback(hObject, eventdata, handles) % hObject handle to cancel (see GCBO) % handles structure with handles and user data (see GUIDATA) close(handles.figure); % --- Executes during object creation, after setting all properties. function edit_length_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_length (see GCBO) % handles empty - handles not created until after all CreateFcns called if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function edit_length_Callback(hObject, eventdata, handles) % hObject handle to edit_length (see GCBO) % handles structure with handles and user data (see GUIDATA) % --- Executes on button press in load. function load_Callback(hObject, eventdata, handles) % hObject handle to load (see GCBO) % handles structure with handles and user data (see GUIDATA) [file,path] = uigetfile2('*.mat','Load Map'); if file~=0 try S=load([path file]); set([handles.x handles.f handles.init],'value',1); set(handles.x,'string',S.map.x); set(handles.f,'string',S.map.f); set(handles.init,'string',S.map.init); set(handles.edit_info,'string',S.map.info); set(handles.e_tr_steps,'string',S.map.tr_steps); set(handles.edit_length,'string',S.map.length); set(handles.edit_p,'string',S.map.parameter); catch errordlg('Wrong file format or some fields missed','File error'); end end % --- Executes on button press in save. function save_Callback(hObject, eventdata, handles) % hObject handle to save (see GCBO) % handles structure with handles and user data (see GUIDATA) [file,path] = uiputfile('*.mat','Save Map As'); if file~=0 map.x=get(handles.x,'string'); map.f=get(handles.f,'string'); tmp=map.x; for i=1:length(tmp) tmp{i}='0'; end map.ignv=tmp; map.innv=tmp; map.agnv=tmp; map.annv=tmp; map.init=get(handles.init,'string'); map.info=get(handles.edit_info,'string'); map.tr_steps=get(handles.tr_steps,'string'); map.length=get(handles.edit_length,'string'); map.parameter=get(handles.edit_p,'string'); save([path file],'map'); end % --- Executes during object creation, after setting all properties. function edit_info_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_info (see GCBO) % handles empty - handles not created until after all CreateFcns called if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end function edit_info_Callback(hObject, eventdata, handles) % hObject handle to edit_info (see GCBO) % handles structure with handles and user data (see GUIDATA) % --- Executes during object creation, after setting all properties. function x_CreateFcn(hObject, eventdata, handles) % hObject handle to x (see GCBO) % handles empty - handles not created until after all CreateFcns called if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on selection change in x. function x_Callback(hObject, eventdata, handles) % hObject handle to x (see GCBO) % handles structure with handles and user data (see GUIDATA) set([handles.x handles.f handles.init],'value',get(hObject,'Value')); % --- Executes during object creation, after setting all properties. function f_CreateFcn(hObject, eventdata, handles) % hObject handle to f (see GCBO) % handles empty - handles not created until after all CreateFcns called if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes during object creation, after setting all properties. function init_CreateFcn(hObject, eventdata, handles) % hObject handle to init (see GCBO) % handles empty - handles not created until after all CreateFcns called if ispc set(hObject,'BackgroundColor','white'); else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor')); end % --- Executes on button press in add. function add_Callback(hObject, eventdata, handles) % hObject handle to add (see GCBO) % handles structure with handles and user data (see GUIDATA) N=length(get(handles.x,'string')); x={}; for i=1:N x{i}=['x' num2str(i)]; end set(handles.x,'string',x); prompt = {['Enter equation x' num2str(N+1) '(n+1)=...'],... 'Enter initial condition:'}; dlg_title = 'Add new equation'; num_lines= 1; def = {'','0.5'}; answer = inputdlg(prompt,dlg_title,num_lines,def); if ~isempty(answer) x=get(handles.x,'string'); f=get(handles.f,'string'); init=get(handles.init,'string'); x{N+1}=['x' num2str(N+1)]; f{N+1}=answer{1}; init{N+1}=answer{2}; set([handles.x, handles.f, handles.init],'value',N+1); set(handles.x,'string',x); set(handles.f,'string',f); set(handles.init,'string',init); end % --- Executes on button press in modify. function modify_Callback(hObject, eventdata, handles) % hObject handle to modify (see GCBO) % handles structure with handles and user data (see GUIDATA) x=get(handles.x,'string'); f=get(handles.f,'string'); init=get(handles.init,'string'); selection=get(handles.x,'value'); if isempty(x) x{1}='x1'; f{1}=''; init{1}='0.7'; end prompt = {['Enter equation ' x{selection} '(n+1)=...'],... 'Enter initial condition:'}; dlg_title = 'Modify equation'; num_lines= 1; def = {f{selection},init{selection}}; answer = inputdlg(prompt,dlg_title,num_lines,def); if ~isempty(answer) f{selection}=answer{1}; init{selection}=answer{2}; set(handles.x,'string',x); set(handles.f,'string',f); set(handles.init,'string',init); end % --- Executes on button press in delete. function delete_Callback(hObject, eventdata, handles) % hObject handle to delete (see GCBO) % handles structure with handles and user data (see GUIDATA) x=get(handles.x,'string'); f=get(handles.f,'string'); init=get(handles.init,'string'); selection=get(handles.x,'value'); if isempty(x) return end n_f={}; n_init={}; n_x={}; k=1; for i=1:length(x) if i~=selection n_f{k}=f{i}; n_init{k}=init{i}; n_x{k}=x{i}; k=k+1; end end set([handles.x, handles.f, handles.init],'value',max([1 selection-1])); set(handles.x,'string',n_x); set(handles.f,'string',n_f); set(handles.init,'string',n_init); % --- Executes during object creation, after setting all properties. function e_tr_steps_CreateFcn(hObject, eventdata, handles) % hObject handle to e_tr_steps (see GCBO) % 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 e_tr_steps_Callback(hObject, eventdata, handles) % hObject handle to e_tr_steps (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of e_tr_steps as text % str2double(get(hObject,'String')) returns contents of e_tr_steps as a double % --- Executes during object creation, after setting all properties. function edit_p_CreateFcn(hObject, eventdata, handles) % hObject handle to edit_p (see GCBO) % 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 edit_p_Callback(hObject, eventdata, handles) % hObject handle to edit_p (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit_p as text % str2double(get(hObject,'String')) returns contents of edit_p as a double