function phaseplane(command_str) % PHASED % if nargin == 0 command_str = 'initialize'; end global h_box h_grid h_xdata h_yprimedata h_status h_n h_clear if strcmp(command_str,'initialize') % Make sure that the GUI has not been initialized % in another existing figure. h_figs = get(0,'children'); fig_exists = 0; for fig = h_figs' fig_exists = strcmp(get(fig,'name'),'Phase Plane Trajectories'); if fig_exists figure(fig); % Bring figure to front of screen return; % No need to reinitialize, exit function end end h_fig = figure('name','Phase Plane Trajectories'); axes('position',[.2 .3 .6 .6],'box','on') % Create the two frames. uicontrol(h_fig,... 'Position',[ 0 0 1 0.25 ],... 'Style','frame',... 'BackgroundColor', [.702, .702, .702],... 'Units','normalized'); % Create the Edit boxes for the x data % and data box for number of trajectories plotted h_xdata = uicontrol(h_fig,... 'CallBack','phaseplane(''Plot Function'');',... 'Position',[ 0.25 0.15 0.15 0.06 ],... 'String','-5:1:5',... 'Style','edit',... 'Units','normalized'); h_n = uicontrol(h_fig,... 'CallBack','phaseplane(''Plot Trajectory'');',... 'Position',[ 0.7 0.15 0.25 0.06 ],... 'String','0|5|10|15|20', ... 'Style','listbox',... 'Units','normalized',... 'Value',[1]); h_clear = uicontrol(h_fig,... 'CallBack','phaseplane(''Clear Axis'');',... 'Position',[ 0.7 0.08 0.25 0.06 ],... 'String','Clear', ... 'Style','pushbutton',... 'Units','normalized'); % Create a static text object that will be used % to display messages to the user. %h_status = uicontrol(h_fig,... % 'Position',[ 0.1 0.06 0.8 0.05 ],... % 'String','Status Window',... % 'Style','text',... % 'Units','normalized'); % Create the "x = " and "y(x)=" static text objects uicontrol(h_fig,... 'Position',[ 0.1 0.15 0.12 0.06 ],... 'String','x =',... 'Style','text',... 'Units','normalized'); uicontrol(h_fig,... 'Position',[ 0.5 0.15 0.12 0.06 ],... 'String','number of trajectories = ',... 'Style','text',... 'Units','normalized'); % Initialize the plot with the initial x and y data phaseplane('Plot Function'); % Callback for x,y,yprime edit boxes elseif strcmp(command_str,'Plot Function') err_ind = 0; eval(['x = ' get(h_xdata,'string') ';'],'err_ind=1;'); y=x; if err_ind == 0 dx=x(2)-x(1); dy=dx; nx=length(x); ny=length(y); l=.5*dx; for i=1:nx for j=1:ny v=[x(i);y(j)]; m=g(0,v); m1=m(1); m2=m(2); % len=1/sqrt(m1^2+m2^2); if (m1~=0) s=m2/m1; else s=10^5; end xstar=x(i)-l/sqrt(1+s^2); ystar=y(j)+s*(xstar-x(i)); u=[x(i), xstar]; v=[y(j),ystar]; plot(u,v) hold on end end axis([x(1), x(end), y(1), y(end)]); hold off; end % Callback for trajectory plot % elseif strcmp(command_str,'Plot Trajectory') err_ind = 0; no_traj = get(h_n,'value'); % eval(['n = ' get(h_n,'string') ';'],'err_ind=1;'); hold on for i=1:5*(no_traj-1) [y10,y20]=ginput(1); [T,Y]=ode45('g',[0,10],[y10,y20]); plot(Y(:,1),Y(:,2),'r') hold on [T,Y]=ode45('g',[0, -10],[y10,y20]); plot(Y(:,1),Y(:,2),'m') i=i+1; end hold off elseif strcmp(command_str,'Clear Axis') cla; phaseplane('Plot Function'); end %end % END command_str checks