function Logist(action, param)
%This program is based on a similar program by Hartmut S. Loos.
%It is a demonstration of the logistic function, and will create
%six graphs of the same function with different x_0 values.
%The program can be run by typing 'Logist' at the matlab prompt.
%The only variables needed are alpha and delta which are provided
%by the user. 
	if nargin < 1,
		param = '';
		action = 'start';
	elseif nargin < 2,
		param = '';
	end;

	switch( action )
		case 'start'
			addGui
		
		case 'plotCB'
			myplot
		
	end;

function addGui

	%create a structure to hold global program data
	mStruct = struct('alphaT', 0, ...
			'deltaT', 0);
			

	%omit colormap for now. to add:
	%'Colormap', <Color array>, ...
	mainWindow = figure('Position', [100 200 800 600], ...
		'Tag', 'mainWindow', ...
		'Resize', 'off', ...
		'Name', 'Logist', ...
		'MenuBar', 'none', ...
		'ToolBar', 'none', ...
		'UserData', 'mStruct');

	%except input from the user
	uicontrol('Parent', mainWindow, ...
		'Position', [40 5 50 20], ...
		'Style', 'text',...
		'String', 'Alpha =', ...
		'HorizontalAlignment', 'right');

	uicontrol('Parent', mainWindow, ...
		'Position', [90 5 40 20], ...
		'Style', 'edit', ...
		'String', '3.4', ...
		'Tag', 'Alpha');

        uicontrol('Parent', mainWindow, ...
                'Position', [140 5 50 20], ...
                'Style', 'text',...
                'String', 'Delta =', ...
                'HorizontalAlignment', 'right');

        uicontrol('Parent', mainWindow, ...
                'Position', [190 5 40 20], ...
                'Style', 'edit', ...
		'String', '.8', ...
		'Tag', 'Delta');

	%Plot and clear buttons
	uicontrol('Parent', mainWindow, ...
		'Position', [310 5 60 20], ...
		'Style', 'pushbutton', ...
		'Tag', 'Plot', ...
		'String', 'Plot', ...
		'Callback', 'Logist plotCB');

%All the graph information is held in a 3-d matrix, the third
%dimension being an index for the graph.
function myplot 
	%the third dimension will allow for the storage
	%of ordered pairs of points.
	h = findobj('Tag', 'Alpha');
	alphaT = str2num(get(h, 'String'));
	h = findobj('Tag', 'Delta');
	deltaT = str2num(get(h, 'String'));

	if deltaT == 0
		errordlg('Delta = 0 is not allowed');
		return;
	end;
	
	x=zeros(6,floor(40/deltaT),2);
	for t = 1:6
	 %set the starting point for the first column
	 %to 0 through 1 at .2 intervals for the y coordinate 
         %with deltaT as the starting position for the x 
	 %coordinate
		x(t,1,2)= (t-1)*.2;
		x(t,1,1)= deltaT;
	end;	
	for t = 2:floor(40/deltaT)
		for j = 1:6 
	        %multiply the variable 't' by 'deltaT' to get the true index.
	        %perform the dgl function
	        %x(j,t,1) is the x coordinate. x(j,t,2) is the y coordinate.
		        x(j,t,1)= t * deltaT;
		        x(j,t,2)= deltaT*((alphaT - 1) * x(j, t-1,2) - (alphaT * x(j, t-1,2)^2)) +x(j, t-1,2);
		 end;
	end;	
	subplot('position', [10 80 580 320]);
	subplot(3,2,1), plot(x(1,:,1),x(1,:,2)), axis([0 40 0 1])
	xlabel('Graph 1: x_0 = 0.0')
	subplot(3,2,2), plot(x(2,:,1),x(2,:,2)), axis([0 40 0 1])
	xlabel('Graph 2: x_0 = 0.2')
	subplot(3,2,3), plot(x(3,:,1),x(3,:,2)), axis([0 40 0 1])
	xlabel('Graph 3: x_0 = 0.4')
	subplot(3,2,4), plot(x(4,:,1),x(4,:,2)), axis([0 40 0 1])
	xlabel('Graph 4: x_0 = 0.6')
	subplot(3,2,5), plot(x(5,:,1),x(5,:,2)), axis([0 40 0 1])
	xlabel('Graph 5: x_0 = 0.8')
	subplot(3,2,6), plot(x(6,:,1),x(6,:,2)), axis([0 40 0 1])
	xlabel('Graph 6: x_0 = 1.0')
