function [ret,x0,str,ts,xts]=memdemo(t,x,u,flag);
%MEMDEMO	is the M-file description of the SIMULINK system named MEMDEMO.
%	The block-diagram can be displayed by typing: MEMDEMO.
%
%	SYS=MEMDEMO(T,X,U,FLAG) returns depending on FLAG certain
%	system values given time point, T, current state vector, X,
%	and input vector, U.
%	FLAG is used to indicate the type of output to be returned in SYS.
%
%	Setting FLAG=1 causes MEMDEMO to return state derivatives, FLAG=2
%	discrete states, FLAG=3 system outputs and FLAG=4 next sample
%	time. For more information and other options see SFUNC.
%
%	Calling MEMDEMO with a FLAG of zero:
%	[SIZES]=MEMDEMO([],[],[],0),  returns a vector, SIZES, which
%	contains the sizes of the state vector and other parameters.
%		SIZES(1) number of states
%		SIZES(2) number of discrete states
%		SIZES(3) number of outputs
%		SIZES(4) number of inputs.
%	For the definition of other parameters in SIZES, see SFUNC.
%	See also, TRIM, LINMOD, LINSIM, EULER, RK23, RK45, ADAMS, GEAR.

% Note: This M-file is only used for saving graphical information;
%       after the model is loaded into memory an internal model
%       representation is used.

% the system will take on the name of this mfile:
sys = mfilename;
new_system(sys)
simver(1.3)
if (0 == (nargin + nargout))
     set_param(sys,'Location',[6,50,546,383])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.2')
set_param(sys,'Stop time',     '2000000')
set_param(sys,'Min step size', '0.0002')
set_param(sys,'Max step size', '20')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Note',[sys,'/',['X1''']])
set_param([sys,'/',['X1''']],...
		'position',[280,130,285,135])

add_block('built-in/Note',[sys,'/',['X2'' = X1 ']])
set_param([sys,'/',['X2'' = X1 ']],...
		'position',[334,35,339,40])

add_block('built-in/Note',[sys,'/',['X1'' = X1( 1 - X2*X2 ) - X2']])
set_param([sys,'/',['X1'' = X1( 1 - X2*X2 ) - X2']],...
		'position',[349,15,354,20])

add_block('built-in/Fcn',[sys,'/','(1-x2*x2)'])
set_param([sys,'/','(1-x2*x2)'],...
		'Expr','1 - u * u',...
		'position',[45,137,115,163])

add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'Vgain','3.000000',...
		'Hgain','20.000000',...
		'Vmax','6.000000',...
		'Hmax','40.000000',...
		'Window',[320,130,600,350],...
		'position',[455,135,480,165])

add_block('built-in/Integrator',[sys,'/','int x2'])
set_param([sys,'/','int x2'],...
		'hide name',0,...
		'Initial','0.25',...
		'position',[375,132,420,168])

add_block('built-in/Integrator',[sys,'/','int x1'])
set_param([sys,'/','int x1'],...
		'hide name',0,...
		'Initial','0.25',...
		'position',[295,132,340,168])

add_block('built-in/Note',[sys,'/','X1'])
set_param([sys,'/','X1'],...
		'position',[244,199,249,204])

add_block('built-in/Note',[sys,'/','X2'])
set_param([sys,'/','X2'],...
		'position',[240,65,245,70])

add_block('built-in/Sum',[sys,'/','Diff'])
set_param([sys,'/','Diff'],...
		'hide name',0,...
		'inputs','-+',...
		'position',[240,124,260,171])

add_block('built-in/Product',[sys,'/','prod'])
set_param([sys,'/','prod'],...
		'hide name',0,...
		'position',[145,139,165,181])

add_block('built-in/Gain',[sys,'/','-1'])
set_param([sys,'/','-1'],...
		'hide name',0,...
		'move name',0,...
		'position',[150,84,195,126])

add_block('built-in/Note',[sys,'/','or'])
set_param([sys,'/','or'],...
		'position',[235,20,240,25])

add_block('built-in/Note',[sys,'/',['X'''' + ( X*X - 1 ) X'' + X = 0']])
set_param([sys,'/',['X'''' + ( X*X - 1 ) X'' + X = 0']],...
		'position',[131,30,136,35])

add_block('built-in/Note',[sys,'/','The Van der Pol Equation'])
set_param([sys,'/','The Van der Pol Equation'],...
		'position',[124,10,129,15])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'position',[30,230,65,260])

add_block('built-in/Sum',[sys,'/','Diff1'])
set_param([sys,'/','Diff1'],...
		'hide name',0,...
		'inputs','+-',...
		'position',[195,237,215,268])

add_block('built-in/Scope',[sys,'/','dt'])
set_param([sys,'/','dt'],...
		'Vgain','1.000000',...
		'Hgain','20.000000',...
		'Vmax','2.000000',...
		'Hmax','40.000000',...
		'Window',[317,484,597,704],...
		'position',[250,240,275,270])

add_block('built-in/Note',[sys,'/',['Here the memory block is being',13,'used to help display the integration',13,'step size dt']])
set_param([sys,'/',['Here the memory block is being',13,'used to help display the integration',13,'step size dt']],...
		'position',[410,240,415,245])

add_block('built-in/Memory',[sys,'/','Memory'])
set_param([sys,'/','Memory'],...
		'position',[115,265,160,295])
add_line(sys,[425,150;450,150])
add_line(sys,[345,150;355,150;355,195;120,195;120,170;140,170])
add_line(sys,[355,150;370,150])
add_line(sys,[425,150;430,150;430,60;25,60;25,150;40,150])
add_line(sys,[130,60;130,105;145,105])
add_line(sys,[170,160;235,160])
add_line(sys,[265,150;290,150])
add_line(sys,[120,150;140,150])
add_line(sys,[200,105;215,105;215,135;235,135])
add_line(sys,[70,245;190,245])
add_line(sys,[90,245;90,280;110,280])
add_line(sys,[165,280;180,280;190,260])
add_line(sys,[220,255;245,255])

% Return any arguments.
if (nargin | nargout)
	% Must use feval here to access system in memory
	if (nargin > 3)
		if (flag == 0)
			eval(['[ret,x0,str,ts,xts]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str,ts,xts] = feval(sys);
	end
end
