⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lorenzgui.m

📁 lorenzmodel混沌系统演示程序
💻 M
📖 第 1 页 / 共 2 页
字号:
function varargout = lorenzGUI(varargin)
% 
%   This GUI animates the solution of the system of three differential 
%   equations known as the "Lorenz Model". For a detailed discussion of
%   this model see [1].
%
%   The equations are given as,
%
%            dy1/dx = -sigma*y1 + sigma*y2,
%            dy2/dx = -y1*y3 + r*y1 - y2,
%            dy3/dx = y1*y2 - b*y3,
%
%   where sigma, r, and b are positive constants.
%
%   The GUI also allows to view the effects of small disturbances of the
%   initial conditions on the solution path.
%
%   The solver ODE45 is used to integrate the model equations.
%
%   Reference:
%     [1] E. Hairer, S. Norsett, G. Wanner: Solving Ordinary
%         Differential Equations I, Springer, Berlin, 2000.

% Author     : Mirza Faisal Baig
% Version    : 1.0
% Date       : April, 2, 2004
%
% Updated to version 1.1 on April, 23, 2004
%
% Variable/Button definitions within GUIDE:
%
% Grid             : Menu Option. Swicth grid ON and OFF
% yo               : Text box. User defined inital conditions.
% dyo              : Text Box. User defined disturbance in the initialconditions
% T (Start)        : Text box. User defined start time.
% T (End)          : Text box. User defined final/end time.
% b                : Text box. User defined value of b.
% sigma            : Text box. User defined value of sigma.
% r                : Text box. User defined value of r.
% Actual (yo) Blue : Check Box. To view the solution path for the actual
%                               defined conditions (Blue color).
% Change (dyo) Red : Check Box. To view the solution path of the
%                               introduced disturbance (Red color). 
% Animated 2D (1)  : Radio Buttons. 2D animation with y1 vs y2.
% Animated 2D (2)  : Radio Buttons. 2D animation with y1 vs y3.
% Animated 3D      : Radio Buttons. 3D animation.
% RUN/STOP         : Push Button. To run/plot or stop animation
% INFO             : Push Button. To display help
% CLOSE            : Push Button. To close the application

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @lorenzGUI_OpeningFcn, ...
                   'gui_OutputFcn',  @lorenzGUI_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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


%--------------------------------------------------------------------------
function lorenzGUI_OpeningFcn(hObject, eventdata, handles, varargin)

handles.output = hObject;
movegui(hObject,'onscreen')              % To display application onscreen
movegui(hObject,'center')                % To display application in the center of screen
set(handles.gridopt,'checked','on')      % To check the grid option
set(handles.animate2d_disp2,'Value',0)
set(handles.y13dlabel,'Visible','Off')
set(handles.y23dlabel,'Visible','Off')
set(handles.y2label,'String','y2','Visible','On','Position',[0.255 0.606 0.032 0.034])
xlimits = [-25  25];  
ylimits = [-30  30];
zlimits = [-1   50];
ytime_limits = [-25 25];
xtime_limits = [1 40];
set(handles.display_plot,'XLim',xlimits,'YLim',ylimits,'ZLim',zlimits);
set(handles.time_plot,'XLim',xtime_limits,'YLim',ytime_limits);
handles.line_plot = [];
handles.line_plotd = [];
handles.line_time_plot = [];
handles.line_time_plotd = [];
guidata(hObject, handles);
%--------------------------------------------------------------------------
function varargout = lorenzGUI_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.output;
%--------------------------------------------------------------------------
function run_wave_Callback(hObject, eventdata, handles)

t0 = str2num(get(handles.t0,'String'));       % Get start time
tfinal = str2num(get(handles.tf,'String'));   % Get end time
b = str2num(get(handles.b,'String'));         % Get value of b
r = str2num(get(handles.r,'String'));         % Get value of r
sigma = str2num(get(handles.sigma,'String')); % Get value of sigma
y0 = str2num(get(handles.y0,'String'));       % Get initial solution
dy0 = str2num(get(handles.dyo,'String'));     % Get the change in the initial solution
dy = y0 - dy0;

C = sqrt(b*(r-1)).*[1 -1];
Cp2 = r-1;
y = y0(:);
y2 = dy(:);
i = 1;
set(handles.animate2d_disp1,'Enable','Off')
set(handles.animate2d_disp2,'Enable','Off')
set(handles.animate3d_disp,'Enable','Off')
set(handles.actual_yo,'Enable','Off')
set(handles.change_dyo,'Enable','Off')
 
if strcmp(get(handles.run_wave,'String'),'RUN/PLOT')
    set(handles.run_wave,'String','STOP');
    cla;
    set(handles.display_plot,'HandleVisibility','On')
    set(handles.time_plot,'HandleVisibility','Off')
    cla; % clear figure
    set(gca,'UserData',1)

    pause(0.01)
    options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-4]);
    [t1,Y] = ode45(@lorenzequation,[t0 tfinal],y0,options,b,r,sigma);
    [t2,DY] = ode45(@lorenzequation,[t0 tfinal],dy,options,b,r,sigma);
    ball_plot = line('XData',y(1),'YData',y(2),'ZData',y(3), ...
            'Color','Blue','Marker','.','Markersize',25,'Erase','Xor');
    line_plot = line('XData',[],'YData',[],'YData',[],'Color','Blue','LineStyle','-','Erase','None');
    ball_plotd = line('XData',dy(1),'YData',dy(2),'ZData',dy(3), ...
            'Color','Red','Marker','.','Markersize',25,'Erase','Xor');
    line_plotd = line('XData',[],'YData',[],'YData',[],'Color','Red','LineStyle','-','Erase','None');
    
    
    set(handles.display_plot,'Drawmode','Fast','Visible','On','NextPlot','Add')
    set(handles.display_plot,'HandleVisibility','Off')
    set(handles.time_plot,'HandleVisibility','On')
    ball_time_plot = line('XData',t0,'YData',y(1),...
            'Color','Blue','Marker','.','MarkerSize',25,'Erase','Xor');
    line_time_plot = line('XData',[],'YData',[],'Color','Blue','LineStyle','-','Erase','None');
    ball_time_plotd = line('XData',t0,'YData',dy(1),...
            'Color','Red','Marker','.','MarkerSize',25,'Erase','Xor');
    line_time_plotd = line('XData',[],'YData',[],'Color','Red','LineStyle','-','Erase','None');
    
    
    set(handles.time_plot,'Drawmode','Fast','Visible','On','NextPlot','Add')
    xlimits = [t0 tfinal];
    ylimits = [ceil(min(min(Y(:,1)),min(DY(:,1))))-5 ceil(max(max(Y(:,1)),max(DY(:,1))))+5];
    set(handles.time_plot,'XLim',xlimits,'YLim',ylimits,'Box','ON');
    set(handles.display_plot,'HandleVisibility','On')
    set(handles.time_plot,'HandleVisibility','Off')
    if get(handles.animate2d_disp1,'Value') == 1
        Yt = [Y(:,1)];
        DYt = [DY(:,1)];
        plot_view = [0,90];
        set(handles.display_plot,'View',plot_view);
        xlimits = [ceil(min(min(Y(:,1)),min(DY(:,1))))-5 ceil(max(max(Y(:,1)),max(DY(:,1))))+5];
        ylimits = [ceil(min(min(Y(:,2)),min(DY(:,2))))-5 ceil(max(max(Y(:,2)),max(DY(:,2))))+5];
        zlimits = [ceil(min(min(Y(:,3)),min(DY(:,3))))-5 ceil(max(max(Y(:,3)),max(DY(:,3))))+5];
        set(handles.display_plot,'XLim',xlimits,'YLim',ylimits,'ZLim',zlimits,'Box','ON');
        c_mark1 = line('Xdata',[C(1)],'Ydata',[C(1)],'Marker','.','MarkerSize',25,'Color','Green');
        c_mark2 = line('Xdata',[C(2)],'Ydata',[C(2)],'Marker','.','MarkerSize',25,'Color','Green');
        c_line = line('xdata',[C(1) C(2)],'ydata',[C(1) C(2)],'LineStyle',':','Linewidth',2,'Color','Green');
    elseif get(handles.animate2d_disp2,'Value') == 1
        plot_view = [0,90];
        set(handles.display_plot,'View',plot_view);  
        Y = [Y(:,1) Y(:,3) Y(:,2)];
        DY = [DY(:,1) DY(:,3) DY(:,2)];
        Yt = [Y(:,1)];
        DYt = [DY(:,1)];
        xlimits = [ceil(min(min(Y(:,1)),min(DY(:,1))))-5 ceil(max(max(Y(:,1)),max(DY(:,1))))+5];
        ylimits = [ceil(min(min(Y(:,2)),min(DY(:,2))))-5 ceil(max(max(Y(:,2)),max(DY(:,2))))+5];
        zlimits = [ceil(min(min(Y(:,3)),min(DY(:,3))))-5 ceil(max(max(Y(:,3)),max(DY(:,3))))+5];
        set(handles.display_plot,'XLim',xlimits,'YLim',ylimits,'ZLim',zlimits,'Box','ON');
        c_mark1 = line('XData',[C(1)],'YData',[Cp2],'Marker','.','MarkerSize',25,'Color','Green');
        c_mark2 = line('XData',[C(2)],'YData',[Cp2],'Marker','.','MarkerSize',25,'Color','Green');
        c_line = line('XData',[C(1) C(2)],'YData',[Cp2 Cp2],'LineStyle',':','Linewidth',2,'Color','Green');
    elseif get(handles.animate3d_disp,'Value') == 1
        Yt = [Y(:,1)];
        DYt = [DY(:,1)];
        plot_view = [-37.5,30];
        set(handles.display_plot,'View',plot_view);
        xlimits = [ceil(min(min(Y(:,1)),min(DY(:,1))))-5 ceil(max(max(Y(:,1)),max(DY(:,1))))+5];
        ylimits = [ceil(min(min(Y(:,2)),min(DY(:,2))))-5 ceil(max(max(Y(:,2)),max(DY(:,2))))+5];
        zlimits = [ceil(min(min(Y(:,3)),min(DY(:,3))))-5 ceil(max(max(Y(:,3)),max(DY(:,3))))+5];
        set(handles.display_plot,'XLim',xlimits,'YLim',ylimits,'ZLim',zlimits,'Box','OFF');
    end
    set(gca,'UserData',1)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -