Pengunjung

Senin, 01 Juli 2013

Membuat GUI untuk sistem persamaan Differensial menggunakan metode RK 4

Sprott mempunyai beberapa bentuk fungsi sederhana tiga dimensi sistem dinamis yang menunjukkan chaos. Beberapa persamaan  jerk ditemukan memiliki fungsi nonlinier sederhana yang harus memungkinkan implementasi elektronik. Hasil Tampilan GUI untuk sistem Jerk bisa dilihat dibawah ini:


 Persamaan jerk telah dipilih  oleh Spott sebagai berikut:

Dimana Persamaan  ini memiliki sistem non-linear  dalam bentuk modulus variable dinamik. Persamaan perilaku chaos ini (untuk a=0.6 dan b = 1) telah diverifikasi oleh Sprott dan Linz  dengan menerapkan kondisi awal 0. Solusi numerik yang diperoleh dapat berupa diagram fasa dan diagram time series. Dengan menganalisis diagram fasa dan time series dari sistem, dapat diamati lintasan dari sistem tersebut yang kemudian dapat diklasifikasikan jenis geraknya. 

Untuk membuat GUI, pada tulisan sebelumnya sudah saya jelaskan. maka disini saya hanya memberi gambaran secara garis besar saja. GUI untuk tampilan sirkuit Jerk sebagai berikut:


Pada tampilan GUI diatas, y0 adalah kondisi awal sistem, T (start)= waktu awal, T (end)= waktu akhir, a,b dan c adalah parameter sistem. displayplot untuk menampilkan diagram fase dan timeplot untuk menampilkan time series.  Setelah membuat GUI seperti diatas, maka masukan source code kedalam matlab sebagai berikut:

 function varargout = lorenzGUI(varargin)

% 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)
    while get(gca,'Userdata')==1
        if t1(i) >= tfinal
            set(gca,'Userdata',-1);
            set(handles.run_wave,'String','RUN/PLOT');
            break
        end
      
        if get(handles.actual_yo,'Value')==0
            set(line_plot,'Visible','Off')
            set(line_time_plot,'Visible','Off')
        elseif get(handles.actual_yo,'Value')==1
            set(line_plot,'Visible','On')
            set(line_time_plot,'Visible','On')
         end
        if get(handles.change_dyo,'Value')==0
            set(line_plotd,'Visible','Off')
            set(line_time_plotd,'Visible','Off')
        elseif get(handles.change_dyo,'Value')==1
            set(line_plotd,'Visible','On')
            set(line_time_plotd,'Visible','On')
        end
        set(ball_plot,'XData',Y(i,1),'YData',Y(i,2),'ZData',Y(i,3))
        set(ball_plotd,'XData',DY(i,1),'YData',DY(i,2),'ZData',DY(i,3))
        set(ball_time_plot,'XData',t1(i),'YData',Yt(i))
        set(ball_time_plotd,'XData',t2(i),'YData',DYt(i))
        set(line_plot,'XData',Y(1:i,1),'YData',Y(1:i,2),'ZData',Y(1:i,3))
        set(line_plotd,'XData',DY(1:i,1),'YData',DY(1:i,2),'ZData',DY(1:i,3))
        set(line_time_plot,'XData',t1(1:i),'YData',Yt(1:i))
        set(line_time_plotd,'XData',t2(1:i),'YData',DYt(1:i))
        handles.line_plot = line_plot;
        handles.line_plotd = line_plotd;
        handles.line_time_plot = line_time_plot;
        handles.line_time_plotd = line_time_plotd;
        guidata(hObject, handles);
        drawnow;
        pause(0.01)
        i = i + 1;
    end
    set(line_plot,'Erase','Background')
    set(line_plotd,'Erase','Background')
    set(line_time_plot,'Erase','Background')
    set(line_time_plotd,'Erase','Background')
   
else
    set(gca,'Userdata',-1);
    set(handles.run_wave,'String','RUN/PLOT');
end
set(handles.display_plot,'HandleVisibility','Off')
set(handles.time_plot,'HandleVisibility','On')
set(handles.animate2d_disp1,'Enable','On')
set(handles.animate2d_disp2,'Enable','On')
set(handles.animate3d_disp,'Enable','On')
set(handles.actual_yo,'Enable','On')
set(handles.change_dyo,'Enable','On')

%--------------------------------------------------------------------------
function animate2d_disp1_Callback(hObject, eventdata, handles)
cla;
set(handles.time_plot,'HandleVisibility','Off')
set(handles.display_plot,'HandleVisibility','On')
cla;
plot_view = [0,90];
set(handles.display_plot,'View',plot_view,'Box','On');
set(handles.y1label,'Visible','On')
set(handles.y2label,'String','y2','Visible','On','Position',[0.255 0.606 0.032 0.034])
set(handles.y13dlabel,'Visible','Off')
set(handles.y23dlabel,'Visible','Off')
set(handles.animate3d_disp,'Value',0)
set(handles.animate2d_disp2,'Value',0)

%--------------------------------------------------------------------------
function animate2d_disp2_Callback(hObject, eventdata, handles)
cla;
set(handles.time_plot,'HandleVisibility','Off')
set(handles.display_plot,'HandleVisibility','On')
cla;
plot_view = [0,90];
set(handles.display_plot,'View',plot_view,'Box','On');
set(handles.y1label,'Visible','On')
set(handles.y2label,'String','y3','Visible','On','Position',[0.255 0.606 0.032 0.034])
set(handles.y13dlabel,'Visible','Off')
set(handles.y23dlabel,'Visible','Off')
set(handles.animate3d_disp,'Value',0)
set(handles.animate2d_disp1,'Value',0)

%--------------------------------------------------------------------------
function animate3d_disp_Callback(hObject, eventdata, handles)
cla;
set(handles.time_plot,'HandleVisibility','Off')
set(handles.display_plot,'HandleVisibility','On')
cla;
plot_view = [-37.5,30];
set(handles.display_plot,'View',plot_view,'Box','OFF');
set(handles.y1label,'Visible','Off')
set(handles.y2label,'String','y3','Position',[0.245 0.6 0.032 0.034])
set(handles.y13dlabel,'Visible','On')
set(handles.y23dlabel,'Visible','On')
set(handles.animate2d_disp1,'Value',0)
set(handles.animate2d_disp2,'Value',0)

%--------------------------------------------------------------------------
function info_Callback(hObject, eventdata, handles)
helpwin('lorenzGUI.m')

%--------------------------------------------------------------------------
function close_button_Callback(hObject, eventdata, handles)
close(gcbf) % to close GUI

%--------------------------------------------------------------------------
function b_CreateFcn(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function b_Callback(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function sigma_CreateFcn(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function sigma_Callback(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function r_CreateFcn(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function r_Callback(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function t0_CreateFcn(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function t0_Callback(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function tf_CreateFcn(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function tf_Callback(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function y0_CreateFcn(hObject, eventdata, handles)

%--------------------------------------------------------------------------
function y0_Callback(hObject, eventdata, handles)

% --------------------------------------------------------------------
function Gridmenu_Callback(hObject, eventdata, handles)

% --------------------------------------------------------------------
function grid_onoff_Callback(hObject, eventdata, handles)
if strcmp(get(handles.gridopt,'checked'),'on')
    set(handles.gridopt,'checked','off')           % To uncheck the grid option
    set(handles.display_plot,'XGrid','Off','YGrid','Off','ZGrid','Off') % Make the grid invisible
    set(handles.time_plot,'XGrid','Off','YGrid','Off') % Make the grid invisible
else
    set(handles.gridopt,'checked','on')            % To check the grid option
    set(handles.display_plot,'XGrid','On','YGrid','On','ZGrid','On')   % Make the grid visible
    set(handles.time_plot,'XGrid','On','YGrid','On') % Make the grid invisible
end

% --------------------------------------------------------------------
% Funtion to solve the equations
function dy = lorenzequation(t,y,b,r,s)
dy = zeros(3,1);
dy(1) =y(2);
dy(2) =r*y(3);
dy(3) = abs(y(1))-1-b*y(2)-s*y(3);

% --- Executes during object creation, after setting all properties.
function dyo_CreateFcn(hObject, eventdata, handles)

function dyo_Callback(hObject, eventdata, handles)

% --- Executes on button press in actual_yo.
function actual_yo_Callback(hObject, eventdata, handles)
if get(handles.actual_yo,'Value')==0
    set(handles.line_plot,'Visible','Off')
    set(handles.line_time_plot,'Visible','Off')
elseif get(handles.actual_yo,'Value')==1
    set(handles.line_plot,'Visible','On')
    set(handles.line_time_plot,'Visible','On')
end

% --- Executes on button press in change_dyo.
function change_dyo_Callback(hObject, eventdata, handles)
if get(handles.change_dyo,'Value')==0
    set(handles.line_plotd,'Visible','Off')
    set(handles.line_time_plotd,'Visible','Off')
  
elseif get(handles.change_dyo,'Value')==1
    set(handles.line_plotd,'Visible','On')
    set(handles.line_time_plotd,'Visible','On')
end


0 komentar:

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan