www.gusucode.com > Matlab动力系统和时间序列分析工具箱 > Matlab动力系统和时间序列分析工具箱/lab432/common/map_solver.m
function varargout = map_solver(varargin) % MAP_SOLVER provides a graphical user interface to iterate noisy map % GUI-mode using: % data=map_solver; % no-GUI using: % data=map_solver(f,ignv,iwnv,agnv,awnv,init,length,trans); % Parameters: % f - cell array of right-side equations % ignv, iwnv - cell arrays with multiplicative Gaussian and multiplicative white noise variances. % agnv, awnv - cell arrays with additive Gaussian and additive white noise variances. % init - cell array of initial conditions % length - solution length % trans - number of transient steps (preliminary solution length) % % data - solution array % Examples: % data=map_solver({'3.42*x1*(1-x1-x2)' '3.42*x1*x2'},{'0' '0'},{'0' '0'},{'0' '0'},{'0' '0'},{'0.1' '0.1'},'5000','100') % data=map_solver({'2.6*x1-3.6*x1^3'},{'0'},{'0'},{'0'},{'0'},{'0.1'},'500','100'); % Other help in pdf-file % author: Max Logunov, lab432@mail.ru, comments welcome % This program is a part of Lab432 software for nonlinear analysis of time % series (freely available by request) % Last Modified by GUIDE v2.5 03-Jan-2005 16:17:30 % 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', @map_solver_OpeningFcn, ... 'gui_OutputFcn', @map_solver_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 map_solver is made visible. function map_solver_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 map_solver (see VARARGIN) % Choose default command line output for map_solver 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.ignv,'string',varargin{2}); set(handles.innv,'string',varargin{3}); set(handles.agnv,'string',varargin{4}); set(handles.annv,'string',varargin{5}); set(handles.init,'string',varargin{6}); set(handles.edit_length,'string',varargin{7}); set(handles.trans,'string',varargin{8}); catch end if length(varargin)==8 % batch mode OK handles.auto=1; end guidata(hObject, handles); % --- Outputs from this function are returned to the command line. function varargout = map_solver_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 dmgDATA if nargout if handles.auto ok_Callback(handles.ok, [], handles); varargout{1} =dmgDATA; else uiwait; varargout{1} =dmgDATA; end else warning('Require output argument then call map_solver'); end try close(handles.figure); catch 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 dmgDATA dmgDATA=[]; x=get(handles.x,'string'); TransSt=str2num(get(handles.trans,'string')); L=str2num(get(handles.edit_length,'string')); if ~isempty(TransSt) L=L+TransSt; end init=get(handles.init,'string'); f=get(handles.f,'string'); if isempty(x) msgbox('No data for map'); return end s = which('map_solver'); [pathstr,name,ext,versn] = fileparts(s); fid = fopen([pathstr '/tmp_map.m'],'w'); fprintf(fid,'function Y=tmp_map(X); \n'); fprintf(fid,'Y=zeros(1,%s); \n',num2str(length(x))); for i=1:length(x) fprintf(fid,'%s=X(%i); \n',x{i},i); end for i=1:length(x) fprintf(fid,'Y(%s)=%s; \n',num2str(i),f{i}); end fclose(fid); clear fid ignv=get(handles.ignv,'string'); innv=get(handles.innv,'string'); data=randn(L,length(x)); noise=rand(L,length(x)); for i=1:length(x) data(:,i)=data(:,i)*str2num(ignv{i})^0.5; noise(:,i)=(noise(:,i)-mean(noise(:,i)))/(var(noise(:,i)))^.5*str2num(innv{i})^0.5; end data=data+noise; clear noise; for i=1:length(x) data(1,i)=data(1,i)+str2num(init{i}); end for i=2:L data(i,:)=data(i,:)+tmp_map(data(i-1,:)); end clear tmp_map if ~isempty(TransSt) data=data(TransSt+1:end,:); end agnv=get(handles.agnv,'string'); annv=get(handles.annv,'string'); g_n=randn(size(data)); n_n=rand(size(data)); for i=1:length(x) g_n(:,i)=g_n(:,i)*str2num(agnv{i})^0.5; n_n(:,i)=(n_n(:,i)-mean(n_n(:,i)))/(var(n_n(:,i)))^.5*str2num(annv{i})^0.5; end data=data+g_n+n_n; dmgDATA=data; uiresume; % --- 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.innv handles.ignv handles.annv handles.agnv handles.init],'value',1); set(handles.x,'string',S.map.x); set(handles.f,'string',S.map.f); set(handles.innv,'string',S.map.innv); set(handles.ignv,'string',S.map.ignv); set(handles.agnv,'string',S.map.agnv); set(handles.annv,'string',S.map.annv); set(handles.init,'string',S.map.init); set(handles.edit_info,'string',S.map.info); set(handles.trans,'string',S.map.tr_steps); set(handles.edit_length,'string',S.map.length); catch errordlg('Wrong file format','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'); map.ignv=get(handles.ignv,'string'); map.innv=get(handles.innv,'string'); map.agnv=get(handles.agnv,'string'); map.annv=get(handles.annv,'string'); map.init=get(handles.init,'string'); map.info=get(handles.edit_info,'string'); map.tr_steps=get(handles.trans,'string'); map.length=get(handles.edit_length,'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.ignv handles.agnv handles.annv handles.init handles.innv],'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 ignv_CreateFcn(hObject, eventdata, handles) % hObject handle to ignv (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 innv_CreateFcn(hObject, eventdata, handles) % hObject handle to innv (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 agnv_CreateFcn(hObject, eventdata, handles) % hObject handle to agnv (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 annv_CreateFcn(hObject, eventdata, handles) % hObject handle to annv (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 internal Gaussian noise variance:',... 'Enter internal white noise variance:',... 'Enter additive Gaussian noise variance:',... 'Enter additve white noise variance:',... 'Enter initial condition:'}; dlg_title = 'Add new equation'; num_lines= 1; def = {'','0','0','0','0','0.5'}; answer = inputdlg(prompt,dlg_title,num_lines,def); if ~isempty(answer) x=get(handles.x,'string'); f=get(handles.f,'string'); ignv=get(handles.ignv,'string'); innv=get(handles.innv,'string'); agnv=get(handles.agnv,'string'); annv=get(handles.annv,'string'); init=get(handles.init,'string'); x{N+1}=['x' num2str(N+1)]; f{N+1}=answer{1}; ignv{N+1}=answer{2}; innv{N+1}=answer{3}; agnv{N+1}=answer{4}; annv{N+1}=answer{5}; init{N+1}=answer{6}; set([handles.x, handles.f, handles.innv, handles.ignv, handles.agnv, handles.annv, handles.init],'value',N+1); set(handles.x,'string',x); set(handles.f,'string',f); set(handles.innv,'string',innv); set(handles.ignv,'string',ignv); set(handles.agnv,'string',agnv); set(handles.annv,'string',annv); 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'); ignv=get(handles.ignv,'string'); innv=get(handles.innv,'string'); agnv=get(handles.agnv,'string'); annv=get(handles.annv,'string'); init=get(handles.init,'string'); selection=get(handles.x,'value'); if isempty(x) x{1}='x1'; f{1}=''; ignv{1}='0'; innv{1}='0'; agnv{1}='0'; annv{1}='0'; init{1}='0.7'; end prompt = {['Enter equation ' x{selection} '(n+1)=...'],... 'Enter internal Gaussian noise variance:',... 'Enter internal white noise variance:',... 'Enter additive Gaussian noise variance:',... 'Enter additve white noise variance:',... 'Enter initial condition:'}; dlg_title = 'Modify equation'; num_lines= 1; def = {f{selection},ignv{selection},innv{selection},agnv{selection},annv{selection},init{selection}}; answer = inputdlg(prompt,dlg_title,num_lines,def); if ~isempty(answer) f{selection}=answer{1}; ignv{selection}=answer{2}; innv{selection}=answer{3}; agnv{selection}=answer{4}; annv{selection}=answer{5}; init{selection}=answer{6}; set(handles.x,'string',x); set(handles.f,'string',f); set(handles.innv,'string',innv); set(handles.ignv,'string',ignv); set(handles.agnv,'string',agnv); set(handles.annv,'string',annv); 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'); ignv=get(handles.ignv,'string'); innv=get(handles.innv,'string'); agnv=get(handles.agnv,'string'); annv=get(handles.annv,'string'); init=get(handles.init,'string'); selection=get(handles.x,'value'); if isempty(x) return end n_f={}; n_ignv={}; n_innv={}; n_agnv={};n_annv={}; n_init={}; n_x={}; k=1; for i=1:length(x) if i~=selection n_f{k}=f{i}; n_ignv{k}=ignv{i}; n_innv{k}=innv{i}; n_agnv{k}=agnv{i}; n_annv{k}=annv{i}; n_init{k}=init{i}; n_x{k}=x{i}; k=k+1; end end set([handles.x, handles.f, handles.innv, handles.ignv, handles.agnv, handles.annv, handles.init],'value',max([1 selection-1])); set(handles.x,'string',n_x); set(handles.f,'string',n_f); set(handles.innv,'string',n_innv); set(handles.ignv,'string',n_ignv); set(handles.agnv,'string',n_agnv); set(handles.annv,'string',n_annv); set(handles.init,'string',n_init); % --- Executes during object creation, after setting all properties. function trans_CreateFcn(hObject, eventdata, handles) % hObject handle to trans (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 trans_Callback(hObject, eventdata, handles) % hObject handle to trans (see GCBO) % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of trans as text % str2double(get(hObject,'String')) returns contents of trans as a double