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


%     Subsystem  'Omega'.

new_system([sys,'/','Omega'])
set_param([sys,'/','Omega'],'Location',[89,111,608,439])

add_block('built-in/Inport',[sys,'/','Omega/u'])
set_param([sys,'/','Omega/u'],...
		'position',[20,29,50,61])

add_block('built-in/Transfer Fcn',[sys,'/','Omega/F(s)'])
set_param([sys,'/','Omega/F(s)'],...
		'Denominator','[1 2]',...
		'position',[110,23,175,67])

add_block('built-in/Inport',[sys,'/','Omega/y'])
set_param([sys,'/','Omega/y'],...
		'Port','2',...
		'position',[20,103,50,137])

add_block('built-in/Transfer Fcn',[sys,'/','Omega/F(s)_'])
set_param([sys,'/','Omega/F(s)_'],...
		'Denominator','[1 2]',...
		'position',[110,100,175,140])

add_block('built-in/Mux',[sys,'/','Omega/Mux'])
set_param([sys,'/','Omega/Mux'],...
		'position',[390,102,420,148])

add_block('built-in/Inport',[sys,'/','Omega/r'])
set_param([sys,'/','Omega/r'],...
		'Port','3',...
		'position',[20,197,50,233])


add_block('built-in/Outport',[sys,'/','Omega/omega'])
set_param([sys,'/','Omega/omega'],...
		'position',[465,109,495,141])
add_line([sys,'/','Omega'],[425,125;460,125])
add_line([sys,'/','Omega'],[55,120;105,120])
add_line([sys,'/','Omega'],[55,45;105,45])
add_line([sys,'/','Omega'],[180,45;365,45;365,110;385,110])
add_line([sys,'/','Omega'],[180,120;385,120])
add_line([sys,'/','Omega'],[80,120;80,180;365,180;365,130;385,130])
add_line([sys,'/','Omega'],[55,215;375,215;385,140])
set_param([sys,'/','Omega'],...
		'Mask Display','Filter\n(generates omega)')


%     Finished composite block 'Omega'.

set_param([sys,'/','Omega'],...
		'Drop Shadow',4,...
		'position',[210,181,350,249])


%     Subsystem  'Text'.

new_system([sys,'/','Text'])
set_param([sys,'/','Text'],'Location',[58,142,488,559])

add_block('built-in/Note',[sys,'/',['Text/5) The plant model. Please remember that this program',13,'is designed for a second order minimum phase plant ',13,'that has relative degree equal to 1.']])
set_param([sys,'/',['Text/5) The plant model. Please remember that this program',13,'is designed for a second order minimum phase plant ',13,'that has relative degree equal to 1.']],...
		'position',[200,305,205,310])

add_block('built-in/Note',[sys,'/',['Text/4) The parameters in the estimator, i.e., the adaptive gains',13,'and the initial estimates']])
set_param([sys,'/',['Text/4) The parameters in the estimator, i.e., the adaptive gains',13,'and the initial estimates']],...
		'position',[215,260,220,265])

add_block('built-in/Note',[sys,'/','Text/3) The parameters of the filter'])
set_param([sys,'/','Text/3) The parameters of the filter'],...
		'position',[120,225,125,230])

add_block('built-in/Note',[sys,'/',['Text/2) The reference model',13,'']])
set_param([sys,'/',['Text/2) The reference model',13,'']],...
		'position',[100,195,105,200])

add_block('built-in/Note',[sys,'/','Text/1) The excitation input r'])
set_param([sys,'/','Text/1) The excitation input r'],...
		'position',[100,165,105,170])

add_block('built-in/Note',[sys,'/',['Text/This program simulates the model reference adaptive ',13,'control scheme discussed in Example 6.4.1. Please ',13,'refer to Example 6.4.1 on page 360 and Table 6.4.1',13,'on page 357of the textbook for details.']])
set_param([sys,'/',['Text/This program simulates the model reference adaptive ',13,'control scheme discussed in Example 6.4.1. Please ',13,'refer to Example 6.4.1 on page 360 and Table 6.4.1',13,'on page 357of the textbook for details.']],...
		'position',[205,0,210,5])

add_block('built-in/Note',[sys,'/',['Text/You can change the following parameters in this program',13,'to see their effects on the performance of the adaptive',13,'control scheme:',13,'']])
set_param([sys,'/',['Text/You can change the following parameters in this program',13,'to see their effects on the performance of the adaptive',13,'control scheme:',13,'']],...
		'position',[205,85,210,90])
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',[142,367,270,441])

add_block('built-in/Transfer Fcn',[sys,'/','Plant Model'])
set_param([sys,'/','Plant Model'],...
		'Numerator','[1 1]',...
		'Denominator','[1  3 -10]',...
		'position',[530,188,600,232])

add_block('built-in/To Workspace',[sys,'/','To Workspace'])
set_param([sys,'/','To Workspace'],...
		'mat-name','yout',...
		'position',[755,430,810,460])

add_block('built-in/Demux',[sys,'/','Demux'])
set_param([sys,'/','Demux'],...
		'position',[535,435,575,485])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'orientation',1,...
		'position',[650,370,670,390])

add_block('built-in/Mux',[sys,'/','Mux1'])
set_param([sys,'/','Mux1'],...
		'inputs','7',...
		'position',[680,408,720,482])

add_block('built-in/Scope',[sys,'/','Tracking Error'])
set_param([sys,'/','Tracking Error'],...
		'Vgain','2.000000',...
		'Hgain','100.000000',...
		'Vmax','4.000000',...
		'Hmax','200.000000',...
		'Window',[832,536,1154,916],...
		'position',[755,128,795,172])

add_block('built-in/Sum',[sys,'/','e1'])
set_param([sys,'/','e1'],...
		'inputs','-+',...
		'position',[685,132,715,163])

add_block('built-in/Transfer Fcn',[sys,'/','Reference Model'])
set_param([sys,'/','Reference Model'],...
		'Denominator','[1 1]',...
		'position',[365,68,440,112])


%     Subsystem  'Input r'.

new_system([sys,'/','Input r'])
set_param([sys,'/','Input r'],'Location',[163,146,563,413])

add_block('built-in/Step Fcn',[sys,'/','Input r/Step Input'])
set_param([sys,'/','Input r/Step Input'],...
		'position',[60,154,95,186])

add_block('built-in/Gain',[sys,'/','Input r/Gain2'])
set_param([sys,'/','Input r/Gain2'],...
		'Gain','0',...
		'position',[150,154,180,186])

add_block('built-in/Sine Wave',[sys,'/','Input r/Sine Wave'])
set_param([sys,'/','Input r/Sine Wave'],...
		'frequency','5.9',...
		'position',[55,91,95,129])

add_block('built-in/Sine Wave',[sys,'/','Input r/Sine Wave1'])
set_param([sys,'/','Input r/Sine Wave1'],...
		'amplitude','0.7',...
		'phase','1.5',...
		'position',[55,38,95,72])

add_block('built-in/Outport',[sys,'/','Input r/sin wave'])
set_param([sys,'/','Input r/sin wave'],...
		'position',[330,97,360,123])

add_block('built-in/Sum',[sys,'/','Input r/Sum'])
set_param([sys,'/','Input r/Sum'],...
		'inputs','+++',...
		'position',[240,85,275,135])

add_block('built-in/Gain',[sys,'/','Input r/Gain1'])
set_param([sys,'/','Input r/Gain1'],...
		'Gain','2',...
		'position',[150,94,180,126])

add_block('built-in/Gain',[sys,'/','Input r/Gain'])
set_param([sys,'/','Input r/Gain'],...
		'Gain','0.5',...
		'position',[150,41,180,69])
add_line([sys,'/','Input r'],[280,110;325,110])
add_line([sys,'/','Input r'],[100,55;145,55])
add_line([sys,'/','Input r'],[185,110;235,110])
add_line([sys,'/','Input r'],[100,110;145,110])
add_line([sys,'/','Input r'],[185,55;215,55;215,95;235,95])
add_line([sys,'/','Input r'],[100,170;145,170])
add_line([sys,'/','Input r'],[185,170;215,170;215,125;235,125])
set_param([sys,'/','Input r'],...
		'Mask Display','Excitation Signal')


%     Finished composite block 'Input r'.

set_param([sys,'/','Input r'],...
		'Drop Shadow',4,...
		'position',[30,179,160,241])


%     Subsystem  'theta'.

new_system([sys,'/','theta'])
set_param([sys,'/','theta'],'Location',[30,61,617,427])

add_block('built-in/Integrator',[sys,'/','theta/Integrator3'])
set_param([sys,'/','theta/Integrator3'],...
		'Initial','3',...
		'position',[375,242,405,288])

add_block('built-in/Demux',[sys,'/','theta/Demux'])
set_param([sys,'/','theta/Demux'],...
		'position',[95,122,135,168])

add_block('built-in/Mux',[sys,'/','theta/Mux'])
set_param([sys,'/','theta/Mux'],...
		'position',[455,132,485,178])

add_block('built-in/Inport',[sys,'/','theta/omega'])
set_param([sys,'/','theta/omega'],...
		'Port','2',...
		'position',[30,129,60,161])

add_block('built-in/Integrator',[sys,'/','theta/Integrator'])
set_param([sys,'/','theta/Integrator'],...
		'Initial','3',...
		'position',[365,39,395,81])

add_block('built-in/Integrator',[sys,'/','theta/Integrator1'])
set_param([sys,'/','theta/Integrator1'],...
		'Initial','-10',...
		'position',[370,114,400,156])

add_block('built-in/Integrator',[sys,'/','theta/Integrator2'])
set_param([sys,'/','theta/Integrator2'],...
		'Initial','2',...
		'position',[370,177,400,223])

add_block('built-in/Product',[sys,'/','theta/Product5'])
set_param([sys,'/','theta/Product5'],...
		'position',[230,119,255,146])

add_block('built-in/Product',[sys,'/','theta/Product6'])
set_param([sys,'/','theta/Product6'],...
		'position',[235,184,260,211])

add_block('built-in/Gain',[sys,'/','theta/Gain3'])
set_param([sys,'/','theta/Gain3'],...
		'Gain','-2',...
		'position',[315,249,345,281])

add_block('built-in/Product',[sys,'/','theta/Product7'])
set_param([sys,'/','theta/Product7'],...
		'position',[240,248,265,277])

add_block('built-in/Inport',[sys,'/','theta/e1'])
set_param([sys,'/','theta/e1'],...
		'position',[130,34,160,66])

add_block('built-in/Outport',[sys,'/','theta/theta'])
set_param([sys,'/','theta/theta'],...
		'position',[525,139,555,171])

add_block('built-in/Gain',[sys,'/','theta/Gain1'])
set_param([sys,'/','theta/Gain1'],...
		'Gain','-6',...
		'position',[305,119,335,151])

add_block('built-in/Gain',[sys,'/','theta/Gain2'])
set_param([sys,'/','theta/Gain2'],...
		'Gain','-6',...
		'position',[300,184,335,216])

add_block('built-in/Product',[sys,'/','theta/Product4'])
set_param([sys,'/','theta/Product4'],...
		'position',[240,42,265,73])

add_block('built-in/Gain',[sys,'/','theta/Gain'])
set_param([sys,'/','theta/Gain'],...
		'Gain','-2',...
		'position',[305,42,330,78])
add_line([sys,'/','theta'],[400,60;435,60;435,140;450,140])
add_line([sys,'/','theta'],[410,265;435,265;435,170;450,170])
add_line([sys,'/','theta'],[405,200;425,200;425,160;450,160])
add_line([sys,'/','theta'],[405,135;425,135;425,150;450,150])
add_line([sys,'/','theta'],[490,155;520,155])
add_line([sys,'/','theta'],[140,160;165,160;165,270;235,270])
add_line([sys,'/','theta'],[140,150;175,150;175,205;230,205])
add_line([sys,'/','theta'],[140,140;225,140])
add_line([sys,'/','theta'],[140,130;175,130;175,65;235,65])
add_line([sys,'/','theta'],[65,145;90,145])
add_line([sys,'/','theta'],[165,50;195,50;195,255;235,255])
add_line([sys,'/','theta'],[270,265;310,265])
add_line([sys,'/','theta'],[350,265;370,265])
add_line([sys,'/','theta'],[265,200;295,200])
add_line([sys,'/','theta'],[340,200;365,200])
add_line([sys,'/','theta'],[260,135;300,135])
add_line([sys,'/','theta'],[340,135;365,135])
add_line([sys,'/','theta'],[335,60;360,60])
add_line([sys,'/','theta'],[270,60;300,60])
add_line([sys,'/','theta'],[165,50;195,50;195,190;230,190])
add_line([sys,'/','theta'],[165,50;195,50;195,125;225,125])
add_line([sys,'/','theta'],[165,50;235,50])
set_param([sys,'/','theta'],...
		'Mask Display','Estimator\n(generates theta)')


%     Finished composite block 'theta'.

set_param([sys,'/','theta'],...
		'orientation',2,...
		'Drop Shadow',4,...
		'position',[425,298,545,367])


%     Subsystem  'Controller'.

new_system([sys,'/','Controller'])
set_param([sys,'/','Controller'],'Location',[111,78,577,397])

add_block('built-in/Inport',[sys,'/','Controller/omega'])
set_param([sys,'/','Controller/omega'],...
		'position',[25,64,55,96])

add_block('built-in/Inport',[sys,'/','Controller/theta'])
set_param([sys,'/','Controller/theta'],...
		'Port','2',...
		'position',[25,179,55,211])

add_block('built-in/Demux',[sys,'/','Controller/Demux'])
set_param([sys,'/','Controller/Demux'],...
		'position',[85,51,130,104])

add_block('built-in/Demux',[sys,'/','Controller/Demux1'])
set_param([sys,'/','Controller/Demux1'],...
		'position',[85,166,130,219])

add_block('built-in/Mux',[sys,'/','Controller/Mux'])
set_param([sys,'/','Controller/Mux'],...
		'inputs','8',...
		'position',[220,89,275,191])

add_block('built-in/Fcn',[sys,'/','Controller/omega * theta'])
set_param([sys,'/','Controller/omega * theta'],...
		'Expr','u(1)*u(5)+u(2)*u(6)+u(3)*u(7)+u(4)*u(8)',...
		'position',[310,127,375,153])

add_block('built-in/Outport',[sys,'/','Controller/u'])
set_param([sys,'/','Controller/u'],...
		'position',[425,122,460,158])
add_line([sys,'/','Controller'],[380,140;420,140])
add_line([sys,'/','Controller'],[60,80;80,80])
add_line([sys,'/','Controller'],[60,195;80,195])
add_line([sys,'/','Controller'],[135,55;205,55;215,105])
add_line([sys,'/','Controller'],[135,70;195,70;195,115;215,115])
add_line([sys,'/','Controller'],[135,85;185,85;185,125;215,125])
add_line([sys,'/','Controller'],[135,100;175,100;175,135;215,135])
add_line([sys,'/','Controller'],[135,170;175,170;175,145;215,145])
add_line([sys,'/','Controller'],[135,185;185,185;185,155;215,155])
add_line([sys,'/','Controller'],[135,200;195,200;195,165;215,165])
add_line([sys,'/','Controller'],[135,215;205,215;215,175])
add_line([sys,'/','Controller'],[280,140;305,140])
set_param([sys,'/','Controller'],...
		'Mask Display','Controller\n(generates u)')


%     Finished composite block 'Controller'.

set_param([sys,'/','Controller'],...
		'Drop Shadow',4,...
		'position',[385,180,485,240])
add_line(sys,[725,445;750,445])
add_line(sys,[660,395;660,415;675,415])
add_line(sys,[165,210;175,210;175,235;205,235])
add_line(sys,[490,210;525,210])
add_line(sys,[500,210;500,170;195,170;205,195])
add_line(sys,[605,210;640,210;640,155;185,155;185,215;205,215])
add_line(sys,[420,335;365,335;365,225;380,225])
add_line(sys,[355,215;355,375;565,375;565,350;550,350])
add_line(sys,[445,90;665,90;665,140;680,140])
add_line(sys,[640,205;665,205;665,155;680,155])
add_line(sys,[720,150;750,150])
add_line(sys,[730,150;730,315;550,315])
add_line(sys,[620,90;620,435;675,435])
add_line(sys,[640,205;640,425;675,425])
add_line(sys,[580,445;675,445])
add_line(sys,[580,455;675,455])
add_line(sys,[580,465;675,465])
add_line(sys,[580,475;675,475])
add_line(sys,[355,215;365,215;365,195;380,195])
add_line(sys,[175,210;175,90;360,90])
add_line(sys,[395,335;395,460;530,460])

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
