function [ret,x0,str,ts,xts]=lorenzs(t,x,u,flag);
%LORENZS	is the M-file description of the SIMULINK system named LORENZS.
%	The block-diagram can be displayed by typing: LORENZS.
%
%	SYS=LORENZS(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 LORENZS 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 LORENZS with a FLAG of zero:
%	[SIZES]=LORENZS([],[],[],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',[22,71,501,472])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-23')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '999999')
set_param(sys,'Min step size', '0.00001')
set_param(sys,'Max step size', '10')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Sum',[sys,'/','y - x'])
set_param([sys,'/','y - x'],...
		'inputs','-+',...
		'position',[105,59,125,81])

add_block('built-in/Gain',[sys,'/','Sigma(y-x)'])
set_param([sys,'/','Sigma(y-x)'],...
		'Gain','10',...
		'position',[165,56,200,84])

add_block('built-in/Integrator',[sys,'/','Integrator'])
set_param([sys,'/','Integrator'],...
		'hide name',0,...
		'Initial','1',...
		'position',[245,60,275,80])

add_block('built-in/Integrator',[sys,'/','Integrator2'])
set_param([sys,'/','Integrator2'],...
		'hide name',0,...
		'Initial','1',...
		'position',[245,315,275,335])

add_block('built-in/Sum',[sys,'/','-Bz+xy'])
set_param([sys,'/','-Bz+xy'],...
		'inputs','-+',...
		'position',[165,314,185,336])

add_block('built-in/Product',[sys,'/','x * y'])
set_param([sys,'/','x * y'],...
		'position',[75,355,105,375])

add_block('built-in/Gain',[sys,'/','Beta * z'])
set_param([sys,'/','Beta * z'],...
		'Gain','2+2/3',...
		'position',[70,300,125,340])

add_block('built-in/Sum',[sys,'/','Rx-y-xz'])
set_param([sys,'/','Rx-y-xz'],...
		'inputs','--+',...
		'position',[170,173,190,207])

add_block('built-in/Integrator',[sys,'/','Integrator1'])
set_param([sys,'/','Integrator1'],...
		'hide name',0,...
		'Initial','1',...
		'position',[240,180,270,200])

add_block('built-in/Product',[sys,'/','x * z'])
set_param([sys,'/','x * z'],...
		'position',[75,180,105,200])

add_block('built-in/Gain',[sys,'/','Rho * x'])
set_param([sys,'/','Rho * x'],...
		'Gain','28',...
		'position',[70,224,105,246])

add_block('built-in/Note',[sys,'/','x '])
set_param([sys,'/','x '],...
		'position',[290,50,295,55])

add_block('built-in/Note',[sys,'/','y '])
set_param([sys,'/','y '],...
		'position',[285,170,290,175])

add_block('built-in/Note',[sys,'/','z '])
set_param([sys,'/','z '],...
		'position',[290,305,295,310])

add_block('built-in/Note',[sys,'/','xdot'])
set_param([sys,'/','xdot'],...
		'position',[215,50,220,55])

add_block('built-in/Note',[sys,'/','ydot'])
set_param([sys,'/','ydot'],...
		'position',[210,170,215,175])

add_block('built-in/Note',[sys,'/','zdot'])
set_param([sys,'/','zdot'],...
		'position',[215,305,220,310])

add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'Vgain','50.000000',...
		'Hgain','20.000000',...
		'Vmax','100.000000',...
		'Hmax','40.000000',...
		'Window',[0,0,280,220],...
		'position',[415,175,440,205])

add_block('built-in/Note',[sys,'/','Lorenz Attractor'])
set_param([sys,'/','Lorenz Attractor'],...
		'position',[190,15,195,20])


%     Subsystem  'XY Graph'.

new_system([sys,'/','XY Graph'])
set_param([sys,'/','XY Graph'],'Location',[8,52,282,245])

add_block('built-in/Inport',[sys,'/','XY Graph/y'])
set_param([sys,'/','XY Graph/y'],...
		'Port','2',...
		'position',[10,100,30,120])

add_block('built-in/Inport',[sys,'/','XY Graph/x'])
set_param([sys,'/','XY Graph/x'],...
		'position',[10,30,30,50])

add_block('built-in/Mux',[sys,'/','XY Graph/Mux'])
set_param([sys,'/','XY Graph/Mux'],...
		'inputs','2',...
		'position',[100,61,130,94])

add_block('built-in/S-Function',[sys,'/',['XY Graph/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['XY Graph/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfunxy',...
		'parameters','ax, st',...
		'position',[185,70,235,90])
add_line([sys,'/','XY Graph'],[35,110;70,110;70,85;95,85])
add_line([sys,'/','XY Graph'],[35,40;70,40;70,70;95,70])
add_line([sys,'/','XY Graph'],[135,80;180,80])
set_param([sys,'/','XY Graph'],...
		'Mask Display','plot(0,0,100,100,[12,91,91,12,12],[90,90,45,45,90],[51,57,65,75,80,79,75,67,60,54,51,48,42,34,28,27,31,42,51],[71,68,66,66,72,79,83,84,81,77,71,60,54,54,58,65,71,74,71])')
set_param([sys,'/','XY Graph'],...
		'Mask Type','XY scope.',...
		'Mask Dialogue','XY scope using MATLAB graph window.\nFirst input is used as time base.\nEnter plotting ranges.|x-min|x-max|y-min|y-max|Sample Time')
set_param([sys,'/','XY Graph'],...
		'Mask Translate','ax = [@1, @2, @3, @4];st=@5;',...
		'Mask Help','This block can be used to explore limit cycles. Look at the m-file sfunxy.m to see how it works.',...
		'Mask Entries','-30\/30\/0\/50\/.025\/')


%     Finished composite block 'XY Graph'.

set_param([sys,'/','XY Graph'],...
		'position',[415,296,445,334])
add_line(sys,[280,325;410,325])
add_line(sys,[280,70;320,70;320,45;49,45;49,65;100,65])
add_line(sys,[205,70;240,70])
add_line(sys,[130,70;160,70])
add_line(sys,[280,325;300,325;300,290;27,290;27,320;65,320])
add_line(sys,[190,325;240,325])
add_line(sys,[130,320;160,320])
add_line(sys,[110,365;145,365;145,330;160,330])
add_line(sys,[195,190;235,190])
add_line(sys,[110,235;120,235;120,200;165,200])
add_line(sys,[110,190;165,190])
add_line(sys,[275,190;295,190;295,155;120,155;120,180;165,180])
add_line(sys,[275,190;295,190;295,155;84,155;84,75;100,75])
add_line(sys,[280,70;320,70;320,45;49,45;49,185;70,185])
add_line(sys,[280,70;320,70;320,45;49,45;49,235;65,235])
add_line(sys,[280,325;300,325;300,290;27,290;27,195;70,195])
add_line(sys,[280,70;320,70;320,45;49,45;49,360;70,360])
add_line(sys,[275,190;295,190;295,155;15,155;15,370;70,370])
add_line(sys,[280,70;320,70;320,305;410,305])
add_line(sys,[275,190;410,190])

drawnow

% 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
else
	drawnow % Flash up the model and execute load callback
end
