function varargout = gradSyS(varargin) % Моделирование градиентных динамических систем gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, ... 'gui_Singleton', gui_Singleton, ... 'gui_OpeningFcn', @gradSyS_OpeningFcn, ... 'gui_OutputFcn', @gradSyS_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 gradSyS is made visible. function gradSyS_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn. % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to gradSyS (see VARARGIN) % Choose default command line output for gradSyS handles.output = hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes gradSyS wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout = gradSyS_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Get default command line output from handles structure varargout{1} = handles.output; % Связь события CloseRequestFcn с подфункцией Close set(handles.output, 'CloseRequestFcn',{@Close,handles}); set(handles.axes1, 'Fontsize', 9); function Close(hObject,eventdata,handles)% Подфункция обработки события CloseRequestFcn окна приложения % Вывод модального диалогового окна с подтверждением закрытия q=questdlg('Закрыть приложение?','!!Информация!!','Да','Нет','Да'); % Проверка выбора пользователя if strcmp(q,'Да') % Пользователь подтвердил закрытие приложения, % удаляем окно приложения delete(handles.output); end % --- Executes on button press in btnPlot. function btnPlot_Callback(hObject, eventdata, handles) global FNAME;%имя функции FNAME=get(handles.EdtF,'string'); global GNAME; %имя функции градиента GNAME=get(handles.EdtG,'string') ; ParStr = ['x0=', get(handles.EdtV,'String'), ';'];%начальный вектор % Выполнение строки, запись начального приближения в вектор х0 eval(ParStr); [r,c] = size(x0); if (r==1), x0 = x0'; end; %начальный и конечный момент моделирования ParStr = ['t0=', get(handles.EdtB,'String'), ';']; % Выполнение строки, запись начального приближения в вектор t0 eval(ParStr); %решение дифференциального уравнения методом Рунге-Кутты options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4]); [t,x] = ode45('gpatch', t0,x0,options); xmin = str2double(get(handles.edit6,'String')); xmax = str2double(get(handles.edit7,'String')); ymin = str2double(get(handles.edit8,'String')); ymax = str2double(get(handles.edit9,'String')); steps = 20; xlist = [xmin : (xmax-xmin)/steps : xmax ]; ylist = [ymin : (ymax-ymin)/steps : ymax ]; [xx,yy] = meshgrid(xlist,ylist); zz = zeros(steps+1,steps+1); dx = zz; dy = zz; for p = 1:steps+1, for q = 1:steps+1 zz(p,q) = feval(FNAME,[xx(p,q);yy(p,q)]); g = feval(GNAME,[xx(p,q);yy(p,q)]); dx(p,q) = g(1); dy(p,q) = g(2); end;end; zmin = min(min(zz)); zmin = min(zmin,0); zmax = max(max(zz)); zmax = max(zmax,0); n = length(t); z = zeros(n,1); for k=1:n; z(k) = feval(FNAME,x(k,:)'); end; if get(handles.cbInd,'Value') figure; end; mesh(xx,yy,zz);%каркасная поверхность функции f(x) hold on; extra = 0; plot3(x(:,1),x(:,2),z + extra,'b');%траектория системы plot(x(:,1),x(:,2),'m'); % траектория системы, спроектированная на поверхность f(x) quiver(-dx,-dy,'k');%векторное поле, определяемое градиентом contour(xx,yy,zz,'-c');%контурные линии, на которых f=const axis([xmin,xmax,ymin,ymax,zmin,zmax]); title('Градиентные системы') legend('каркасная поверхность функции f(x)', 'траектория системы',... 'проекция на поверхность f(x)','векторное поле, определяемое градиентом',... 'контурные линии, на которых f=const','Location','SouthOutside'); grid on; hold off; % Кнопка Очистить должна стать доступной set(handles.btnClear, 'Enable', 'on'); function EdtV_Callback(hObject, eventdata, handles) % hObject handle to EdtV (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of EdtV as text % str2double(get(hObject,'String')) returns contents of EdtV as a double % --- Executes during object creation, after setting all properties. function EdtV_CreateFcn(hObject, eventdata, handles) % hObject handle to EdtV (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function EdtB_Callback(hObject, eventdata, handles) % hObject handle to edit17 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit17 as text % str2double(get(hObject,'String')) returns contents of edit17 as a double % --- Executes during object creation, after setting all properties. function EdtB_CreateFcn(hObject, eventdata, handles) % hObject handle to edit17 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function EdtE_Callback(hObject, eventdata, handles) % hObject handle to EdtE (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of EdtE as text % str2double(get(hObject,'String')) returns contents of EdtE as a double % --- Executes during object creation, after setting all properties. function EdtE_CreateFcn(hObject, eventdata, handles) % hObject handle to EdtE (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in pushbutton2. function pushbutton2_Callback(hObject, eventdata, handles) % hObject handle to pushbutton2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) function EdtG_Callback(hObject, eventdata, handles) % hObject handle to EdtG (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of EdtG as text % str2double(get(hObject,'String')) returns contents of EdtG as a double % --- Executes during object creation, after setting all properties. function EdtG_CreateFcn(hObject, eventdata, handles) % hObject handle to EdtG (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function EdtF_Callback(hObject, eventdata, handles) % hObject handle to EdtF (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of EdtF as text % str2double(get(hObject,'String')) returns contents of EdtF as a double % --- Executes during object creation, after setting all properties. function EdtF_CreateFcn(hObject, eventdata, handles) % hObject handle to EdtF (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in btnF. function btnF_Callback(hObject, eventdata, handles) % hObject handle to btnF (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global FNAME; FNAME='fegg'; [flname, pname] = uigetfile('*.*','Выбор имени функции'); % получение имени и пути к файлу % Проверка, был ли открыт файл if flname ~= 0 % Отбрасывание расширения FNAME = strrep(flname,'.m',''); end set(handles.EdtF,'string',FNAME); % --- Executes on button press in btnG. function btnG_Callback(hObject, eventdata, handles) % hObject handle to btnG (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global GNAME; GNAME='gegg'; [flname, pname] = uigetfile('*.*','Выбор имени градиента'); % получение имени и пути к файлу % Проверка, был ли открыт файл if flname ~= 0 % Отбрасывание расширения GNAME = strrep(flname,'.m',''); end set(handles.EdtG,'string',GNAME); % --- Executes on button press in btnClear. function btnClear_Callback(hObject, eventdata, handles) % hObject handle to btnClear (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) cla ;% очистка осей % Кнопка Очистить должна стать недоступной после очистки осей set(hObject, 'Enable', 'off'); % Кнопка Построить должна стать доступной set(handles.btnPlot, 'Enable', 'on'); function edit6_Callback(hObject, eventdata, handles) % hObject handle to edit6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit6 as text % str2double(get(hObject,'String')) returns contents of edit6 as a double % --- Executes during object creation, after setting all properties. function edit6_CreateFcn(hObject, eventdata, handles) % hObject handle to edit6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit7_Callback(hObject, eventdata, handles) % hObject handle to edit7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit7 as text % str2double(get(hObject,'String')) returns contents of edit7 as a double % --- Executes during object creation, after setting all properties. function edit7_CreateFcn(hObject, eventdata, handles) % hObject handle to edit7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit8_Callback(hObject, eventdata, handles) % hObject handle to edit8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit8 as text % str2double(get(hObject,'String')) returns contents of edit8 as a double % --- Executes during object creation, after setting all properties. function edit8_CreateFcn(hObject, eventdata, handles) % hObject handle to edit8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end function edit9_Callback(hObject, eventdata, handles) % hObject handle to edit9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of edit9 as text % str2double(get(hObject,'String')) returns contents of edit9 as a double % --- Executes during object creation, after setting all properties. function edit9_CreateFcn(hObject, eventdata, handles) % hObject handle to edit9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % 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 && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % --- Executes on button press in cbInd. function cbInd_Callback(hObject, eventdata, handles) % hObject handle to cbInd (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of cbInd