function [ret,x0,str,ts,xts]=exampl10(t,x,u,flag);
%EXAMPL10	is the M-file description of the SIMULINK system named EXAMPL10.
%	The block-diagram can be displayed by typing: EXAMPL10.
%
%	SYS=EXAMPL10(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 EXAMPL10 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 EXAMPL10 with a FLAG of zero:
%	[SIZES]=EXAMPL10([],[],[],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,776,655])
     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');

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


%     Subsystem  'Controller'.

new_system([sys,'/','Controller'])
set_param([sys,'/','Controller'],'Location',[87,58,620,394])

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/Inport',[sys,'/','Controller/epsilon'])
set_param([sys,'/','Controller/epsilon'],...
		'Port','3',...
		'position',[15,181,40,209])

add_block('built-in/Transfer Fcn',[sys,'/','Controller/(s+1)//(tau*s)'])
set_param([sys,'/','Controller/(s+1)//(tau*s)'],...
		'Numerator','[1 1]',...
		'Denominator','[0.5 0]',...
		'position',[105,172,165,218])

add_block('built-in/Gain',[sys,'/','Controller/Gain'])
set_param([sys,'/','Controller/Gain'],...
		'position',[225,177,260,213])

add_block('built-in/Sum',[sys,'/','Controller/Sum'])
set_param([sys,'/','Controller/Sum'],...
		'inputs','+-',...
		'position',[390,127,420,163])

add_block('built-in/Outport',[sys,'/','Controller/u'])
set_param([sys,'/','Controller/u'],...
		'position',[490,131,515,159])
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])
add_line([sys,'/','Controller'],[45,195;100,195])
add_line([sys,'/','Controller'],[170,195;220,195])
add_line([sys,'/','Controller'],[345,80;365,80;365,135;385,135])
add_line([sys,'/','Controller'],[265,195;365,195;365,155;385,155])
add_line([sys,'/','Controller'],[425,145;485,145])
set_param([sys,'/','Controller'],...
		'Mask Display','Controller\n(Modified MRAC)')


%     Finished composite block 'Controller'.

set_param([sys,'/','Controller'],...
		'orientation',2,...
		'Drop Shadow',4,...
		'position',[125,227,260,293])


%     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,60,205,110])
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,138,245,192])

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


%     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,225,400,280])

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

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

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',[800,144,1080,364],...
		'position',[495,20,530,60])

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

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

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


%     Subsystem  'Text'.

new_system([sys,'/','Text'])
set_param([sys,'/','Text'],'Location',[147,85,576,495])

add_block('built-in/Note',[sys,'/',['Text/To see the effects of the modification on the performance',13,'of the adaptive control scheme, you can run simulations',13,'for different value of tau by changing the denominator',13,'of the transfer function in the Controller block.']])
set_param([sys,'/',['Text/To see the effects of the modification on the performance',13,'of the adaptive control scheme, you can run simulations',13,'for different value of tau by changing the denominator',13,'of the transfer function in the Controller block.']],...
		'position',[210,270,215,275])

add_block('built-in/Note',[sys,'/',['Text/The modification can be turned off by changing the',13,'Gain in the Controller block to zero. When the modification',13,'is turned off, you should be able to see the bursting',13,'(the same as that in example9 on this diskette).']])
set_param([sys,'/',['Text/The modification can be turned off by changing the',13,'Gain in the Controller block to zero. When the modification',13,'is turned off, you should be able to see the bursting',13,'(the same as that in example9 on this diskette).']],...
		'position',[205,155,210,160])

add_block('built-in/Note',[sys,'/',['Text/This program simulates the modified MRAC scheme',13,'discussed in Subsection 9.4.1. It demonstrates that',13,'the modified scheme helps to eliminate the bursting',13,'(see Example 9.4.1 for discussion on bursting)',13,' Please refer to the textbook for detailed analysis.']])
set_param([sys,'/',['Text/This program simulates the modified MRAC scheme',13,'discussed in Subsection 9.4.1. It demonstrates that',13,'the modified scheme helps to eliminate the bursting',13,'(see Example 9.4.1 for discussion on bursting)',13,' Please refer to the textbook for detailed analysis.']],...
		'position',[205,30,210,35])
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,340,555,421])

add_block('built-in/Sine Wave',[sys,'/','Input r'])
set_param([sys,'/','Input r'],...
		'amplitude','0.1',...
		'frequency','0.01',...
		'position',[5,22,40,58])


%     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',[54,65,156,125])
add_line(sys,[555,55;565,75])
add_line(sys,[370,40;390,40;400,90])
add_line(sys,[45,40;295,40])
add_line(sys,[250,165;435,165])
add_line(sys,[285,40;275,40;275,180;435,180])
add_line(sys,[155,165;155,165])
add_line(sys,[120,260;110,260;120,170])
add_line(sys,[440,100;565,100])
add_line(sys,[475,175;495,175;495,265;405,265])
add_line(sys,[305,255;295,255;295,240;265,240])
add_line(sys,[440,265;440,305;285,305;285,260;265,260])
add_line(sys,[480,100;490,40])
add_line(sys,[605,90;635,90])
add_line(sys,[260,165;260,50;130,60])
add_line(sys,[390,165;400,110])
add_line(sys,[505,100;505,240;405,240])
add_line(sys,[505,235;505,320;275,320;265,280])
add_line(sys,[105,130;105,155;120,155])
add_line(sys,[80,40;80,60])

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
