function [ret,x0,str,ts,xts]=example9(t,x,u,flag);
%EXAMPLE9	is the M-file description of the SIMULINK system named EXAMPLE9.
%	The block-diagram can be displayed by typing: EXAMPLE9.
%
%	SYS=EXAMPLE9(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 EXAMPLE9 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 EXAMPLE9 with a FLAG of zero:
%	[SIZES]=EXAMPLE9([],[],[],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
%		SIZES(5) number of roots (currently unsupported)
%		SIZES(6) direct feedthrough flag
%		SIZES(7) number of sample times
%
%	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',[4,58,728,615])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '10000')
set_param(sys,'Min step size', '0.01')
set_param(sys,'Max step size', '10')
set_param(sys,'Relative error','1e-2')
set_param(sys,'Return vars',   '')
set_param(sys,'AssignWideVectorLines','on');


%     Subsystem  'Disturbance'.

new_system([sys,'/','Disturbance'])
set_param([sys,'/','Disturbance'],'Location',[20,78,620,383])

add_block('built-in/Sum',[sys,'/','Disturbance/Sum4'])
set_param([sys,'/','Disturbance/Sum4'],...
		'position',[295,170,315,190])

add_block('built-in/Product',[sys,'/','Disturbance/Product'])
set_param([sys,'/','Disturbance/Product'],...
		'position',[395,125,420,145])

add_block('built-in/Outport',[sys,'/','Disturbance/d'])
set_param([sys,'/','Disturbance/d'],...
		'position',[465,122,490,148])

add_block('built-in/Signal Generator',[sys,'/','Disturbance/Signal Gen.1'])
set_param([sys,'/','Disturbance/Signal Gen.1'],...
		'Peak','0.500000',...
		'Peak Range','5.000000',...
		'Freq','0.002000',...
		'Freq Range','10.000000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[140,158,185,192])

add_block('built-in/Constant',[sys,'/','Disturbance/Constant2'])
set_param([sys,'/','Disturbance/Constant2'],...
		'Value','0.5',...
		'position',[245,200,265,220])

add_block('built-in/Inport',[sys,'/','Disturbance/r'])
set_param([sys,'/','Disturbance/r'],...
		'position',[15,31,40,59])

add_block('built-in/Gain',[sys,'/','Disturbance/Gain1'])
set_param([sys,'/','Disturbance/Gain1'],...
		'Gain','3',...
		'position',[70,29,100,61])

add_block('built-in/Sum',[sys,'/','Disturbance/Sum1'])
set_param([sys,'/','Disturbance/Sum1'],...
		'position',[150,67,180,103])

add_block('built-in/Gain',[sys,'/','Disturbance/Gain2'])
set_param([sys,'/','Disturbance/Gain2'],...
		'Gain','-1',...
		'position',[210,67,245,103])

add_block('built-in/Saturation',[sys,'/','Disturbance/Saturation'])
set_param([sys,'/','Disturbance/Saturation'],...
		'position',[275,67,315,103])

add_block('built-in/Gain',[sys,'/','Disturbance/Gain'])
set_param([sys,'/','Disturbance/Gain'],...
		'Gain','2',...
		'position',[70,115,100,145])

add_block('built-in/Inport',[sys,'/','Disturbance/y'])
set_param([sys,'/','Disturbance/y'],...
		'Port','2',...
		'position',[15,117,40,143])

add_block('built-in/Note',[sys,'/',['Disturbance/To eliminate the bursting, change',13,'the Gain from 2 to -1']])
set_param([sys,'/',['Disturbance/To eliminate the bursting, change',13,'the Gain from 2 to -1']],...
		'position',[125,240,130,245])
add_line([sys,'/','Disturbance'],[190,175;290,175])
add_line([sys,'/','Disturbance'],[425,135;460,135])
add_line([sys,'/','Disturbance'],[45,130;65,130])
add_line([sys,'/','Disturbance'],[45,45;65,45])
add_line([sys,'/','Disturbance'],[250,85;270,85])
add_line([sys,'/','Disturbance'],[185,85;205,85])
add_line([sys,'/','Disturbance'],[320,85;360,85;360,130;390,130])
add_line([sys,'/','Disturbance'],[320,180;360,180;360,140;390,140])
add_line([sys,'/','Disturbance'],[270,210;280,210;290,185])
add_line([sys,'/','Disturbance'],[105,130;125,130;125,95;145,95])
add_line([sys,'/','Disturbance'],[105,45;125,45;125,75;145,75])
set_param([sys,'/','Disturbance'],...
		'Mask Display','Disturbance')


%     Finished composite block 'Disturbance'.

set_param([sys,'/','Disturbance'],...
		'orientation',1,...
		'Drop Shadow',4,...
		'position',[62,105,153,160])


%     Subsystem  'Text'.

new_system([sys,'/','Text'])
set_param([sys,'/','Text'],'Location',[154,122,536,455])

add_block('built-in/Note',[sys,'/',['Text/This program demonstrates the bursting phenomena',13,'in adaptive control system. See Example 9.4.1 for ',13,'details of analysis. ']])
set_param([sys,'/',['Text/This program demonstrates the bursting phenomena',13,'in adaptive control system. See Example 9.4.1 for ',13,'details of analysis. ']],...
		'position',[190,35,195,40])

add_block('built-in/Note',[sys,'/',['Text/By changing the Gain in the Disturbance block, you',13,'can turn on//off the bursting in the tracking error.',13,'Gain=2 leads to bursting (correspnding to',13,'theta_bar1=0), Gain=-1 results in a non-bursting',13,'response (corresponding to theta_bar=-3)']])
set_param([sys,'/',['Text/By changing the Gain in the Disturbance block, you',13,'can turn on//off the bursting in the tracking error.',13,'Gain=2 leads to bursting (correspnding to',13,'theta_bar1=0), Gain=-1 results in a non-bursting',13,'response (corresponding to theta_bar=-3)']],...
		'position',[190,115,195,120])
set_param([sys,'/','Text'],...
		'Mask Display','Double click here\nfor help to run\nthe simulation')


%     Finished composite block 'Text'.

set_param([sys,'/','Text'],...
		'Drop Shadow',4,...
		'position',[410,380,545,461])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'orientation',1,...
		'position',[545,70,565,90])

add_block('built-in/To Workspace',[sys,'/','To Workspace'])
set_param([sys,'/','To Workspace'],...
		'mat-name','error',...
		'buffer','10000',...
		'position',[640,115,695,145])

add_block('built-in/Mux',[sys,'/','Mux1'])
set_param([sys,'/','Mux1'],...
		'inputs','2',...
		'position',[570,104,600,151])

add_block('built-in/Scope',[sys,'/','Tracking Error'])
set_param([sys,'/','Tracking Error'],...
		'Vgain','1.000000',...
		'Hgain','5000.000000',...
		'Vmax','2.000000',...


		'Hmax','10000.000000',...
		'Window',[704,136,984,356],...
		'position',[495,60,530,100])

add_block('built-in/Mux',[sys,'/','Mux2'])
set_param([sys,'/','Mux2'],...
		'inputs','2',...
		'position',[440,195,470,230])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'inputs','-+',...
		'position',[405,122,435,158])


%     Subsystem  'Adaptive Law'.

new_system([sys,'/','Adaptive Law'])
set_param([sys,'/','Adaptive Law'],'Location',[71,83,590,256])

add_block('built-in/Inport',[sys,'/','Adaptive Law/epsilon'])
set_param([sys,'/','Adaptive Law/epsilon'],...
		'position',[15,27,40,53])

add_block('built-in/Product',[sys,'/','Adaptive Law/Product'])
set_param([sys,'/','Adaptive Law/Product'],...
		'position',[80,65,105,85])

add_block('built-in/Demux',[sys,'/','Adaptive Law/Demux'])
set_param([sys,'/','Adaptive Law/Demux'],...
		'outputs','2',...
		'position',[140,56,180,89])

add_block('built-in/Integrator',[sys,'/','Adaptive Law/Integrator1'])
set_param([sys,'/','Adaptive Law/Integrator1'],...
		'position',[330,87,360,133])

add_block('built-in/Gain',[sys,'/','Adaptive Law/Gain1'])
set_param([sys,'/','Adaptive Law/Gain1'],...
		'Gain','-10',...
		'position',[240,94,270,126])

add_block('built-in/Gain',[sys,'/','Adaptive Law/Gain'])
set_param([sys,'/','Adaptive Law/Gain'],...
		'Gain','-10',...
		'position',[240,19,275,51])

add_block('built-in/Integrator',[sys,'/','Adaptive Law/Integrator'])
set_param([sys,'/','Adaptive Law/Integrator'],...
		'position',[330,14,360,56])

add_block('built-in/Mux',[sys,'/','Adaptive Law/Mux'])
set_param([sys,'/','Adaptive Law/Mux'],...
		'inputs','2',...
		'position',[410,56,440,89])

add_block('built-in/Outport',[sys,'/','Adaptive Law/theta'])
set_param([sys,'/','Adaptive Law/theta'],...
		'position',[480,62,505,88])

add_block('built-in/Inport',[sys,'/','Adaptive Law/omega'])
set_param([sys,'/','Adaptive Law/omega'],...
		'Port','2',...
		'position',[15,107,40,133])
add_line([sys,'/','Adaptive Law'],[275,110;325,110])
add_line([sys,'/','Adaptive Law'],[280,35;325,35])
add_line([sys,'/','Adaptive Law'],[45,40;60,40;60,70;75,70])
add_line([sys,'/','Adaptive Law'],[45,120;60,120;60,80;75,80])
add_line([sys,'/','Adaptive Law'],[110,75;135,75])
add_line([sys,'/','Adaptive Law'],[185,65;210,65;210,35;235,35])
add_line([sys,'/','Adaptive Law'],[185,80;210,80;210,110;235,110])
add_line([sys,'/','Adaptive Law'],[445,75;475,75])
add_line([sys,'/','Adaptive Law'],[365,35;390,35;390,65;405,65])
add_line([sys,'/','Adaptive Law'],[365,110;390,110;390,80;405,80])
set_param([sys,'/','Adaptive Law'],...
		'Mask Display','Adaptation')


%     Finished composite block 'Adaptive Law'.

set_param([sys,'/','Adaptive Law'],...
		'orientation',2,...
		'Drop Shadow',4,...
		'position',[310,265,400,320])

add_block('built-in/Transfer Fcn',[sys,'/','Reference Model'])
set_param([sys,'/','Reference Model'],...
		'Denominator','[1 1]',...
		'position',[300,55,365,105])


%     Subsystem  'Plant Model'.

new_system([sys,'/','Plant Model'])
set_param([sys,'/','Plant Model'],'Location',[131,119,495,333])

add_block('built-in/Outport',[sys,'/','Plant Model/y'])
set_param([sys,'/','Plant Model/y'],...
		'position',[290,72,315,98])

add_block('built-in/Sum',[sys,'/','Plant Model/Sum'])
set_param([sys,'/','Plant Model/Sum'],...
		'position',[120,67,140,103])

add_block('built-in/Inport',[sys,'/','Plant Model/u+d'])
set_param([sys,'/','Plant Model/u+d'],...
		'position',[15,62,40,88])

add_block('built-in/Integrator',[sys,'/','Plant Model/Integrator'])
set_param([sys,'/','Plant Model/Integrator'],...
		'position',[170,61,205,109])
add_line([sys,'/','Plant Model'],[145,85;165,85])
add_line([sys,'/','Plant Model'],[210,85;235,85;235,155;80,155;80,95;115,95])
add_line([sys,'/','Plant Model'],[235,85;285,85])
add_line([sys,'/','Plant Model'],[45,75;115,75])
set_param([sys,'/','Plant Model'],...
		'Mask Display','Plant')


%     Finished composite block 'Plant Model'.

set_param([sys,'/','Plant Model'],...
		'Drop Shadow',4,...
		'position',[160,178,245,232])


%     Subsystem  'Controller'.

new_system([sys,'/','Controller'])
set_param([sys,'/','Controller'],'Location',[67,127,493,320])

add_block('built-in/Inport',[sys,'/','Controller/theta'])
set_param([sys,'/','Controller/theta'],...
		'position',[15,37,40,63])

add_block('built-in/Inport',[sys,'/','Controller/omega'])
set_param([sys,'/','Controller/omega'],...
		'Port','2',...
		'position',[15,111,40,139])

add_block('built-in/Demux',[sys,'/','Controller/Demux1'])
set_param([sys,'/','Controller/Demux1'],...
		'outputs','2',...
		'position',[75,106,115,139])

add_block('built-in/Demux',[sys,'/','Controller/Demux'])
set_param([sys,'/','Controller/Demux'],...
		'outputs','2',...
		'position',[75,31,115,64])

add_block('built-in/Mux',[sys,'/','Controller/Mux'])
set_param([sys,'/','Controller/Mux'],...
		'position',[220,57,250,103])

add_block('built-in/Fcn',[sys,'/','Controller/theta*omega'])
set_param([sys,'/','Controller/theta*omega'],...
		'Expr','u(1)*u(3)+u(2)*u(4)',...
		'position',[290,67,340,93])

add_block('built-in/Outport',[sys,'/','Controller/u'])
set_param([sys,'/','Controller/u'],...
		'position',[380,66,405,94])
add_line([sys,'/','Controller'],[345,80;375,80])
add_line([sys,'/','Controller'],[255,80;285,80])
add_line([sys,'/','Controller'],[45,50;70,50])
add_line([sys,'/','Controller'],[45,125;70,125])
add_line([sys,'/','Controller'],[120,40;195,40;195,65;215,65])
add_line([sys,'/','Controller'],[120,55;185,55;185,75;215,75])
add_line([sys,'/','Controller'],[120,115;185,115;185,85;215,85])
add_line([sys,'/','Controller'],[120,130;195,130;195,95;215,95])
set_param([sys,'/','Controller'],...
		'Mask Display','Controller')


%     Finished composite block 'Controller'.

set_param([sys,'/','Controller'],...
		'orientation',2,...
		'Drop Shadow',4,...
		'position',[160,265,250,320])

add_block('built-in/Sum',[sys,'/','Sum1'])
set_param([sys,'/','Sum1'],...
		'position',[125,187,150,218])

add_block('built-in/Sine Wave',[sys,'/','Input r'])
set_param([sys,'/','Input r'],...
		'amplitude','0.1',...
		'frequency','0.01',...
		'position',[20,62,55,98])
add_line(sys,[555,95;565,115])
add_line(sys,[370,80;390,80;400,130])
add_line(sys,[60,80;295,80])
add_line(sys,[250,205;435,205])
add_line(sys,[285,80;275,80;275,220;435,220])
add_line(sys,[110,165;120,195])
add_line(sys,[155,205;155,205])
add_line(sys,[155,295;110,295;120,210])
add_line(sys,[440,140;565,140])
add_line(sys,[475,215;495,215;495,305;405,305])
add_line(sys,[305,295;285,295;285,280;255,280])
add_line(sys,[440,305;440,345;285,345;285,305;255,305])
add_line(sys,[480,140;490,80])
add_line(sys,[605,130;635,130])
add_line(sys,[260,205;260,90;130,100])
add_line(sys,[390,205;400,150])
add_line(sys,[505,140;505,280;405,280])
add_line(sys,[85,80;85,100])

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
