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

add_block('built-in/Constant',[sys,'/','mu'])
set_param([sys,'/','mu'],...
		'Value','0.25',...
		'position',[40,152,70,178])


%     Subsystem  'Plant Model'.

new_system([sys,'/','Plant Model'])
set_param([sys,'/','Plant Model'],'Location',[164,92,632,351])

add_block('built-in/Inport',[sys,'/','Plant Model/mu'])
set_param([sys,'/','Plant Model/mu'],...
		'Port','2',...
		'position',[10,122,35,148])

add_block('built-in/Inport',[sys,'/','Plant Model/u'])
set_param([sys,'/','Plant Model/u'],...
		'position',[10,47,35,73])

add_block('built-in/Outport',[sys,'/','Plant Model/y'])
set_param([sys,'/','Plant Model/y'],...
		'position',[440,57,465,83])


%     Subsystem  'Plant Model/Nominal Plant'.

new_system([sys,'/','Plant Model/Nominal Plant'])
set_param([sys,'/','Plant Model/Nominal Plant'],'Location',[105,234,431,373])

add_block('built-in/Integrator',[sys,'/','Plant Model/Nominal Plant/Integrator'])
set_param([sys,'/','Plant Model/Nominal Plant/Integrator'],...
		'Initial','1',...
		'position',[155,57,190,93])

add_block('built-in/Outport',[sys,'/','Plant Model/Nominal Plant/y'])
set_param([sys,'/','Plant Model/Nominal Plant/y'],...
		'position',[275,62,300,88])

add_block('built-in/Sum',[sys,'/','Plant Model/Nominal Plant/Sum'])
set_param([sys,'/','Plant Model/Nominal Plant/Sum'],...
		'position',[95,57,125,88])

add_block('built-in/Inport',[sys,'/','Plant Model/Nominal Plant/u+u_d'])
set_param([sys,'/','Plant Model/Nominal Plant/u+u_d'],...
		'position',[10,52,35,78])
add_line([sys,'/','Plant Model/Nominal Plant'],[195,75;205,75;205,120;60,120;60,80;90,80])
add_line([sys,'/','Plant Model/Nominal Plant'],[130,75;150,75])
add_line([sys,'/','Plant Model/Nominal Plant'],[40,65;90,65])
add_line([sys,'/','Plant Model/Nominal Plant'],[195,75;270,75])
set_param([sys,'/','Plant Model/Nominal Plant'],...
		'Mask Display','1/(s-a)')


%     Finished composite block 'Plant Model/Nominal Plant'.

set_param([sys,'/','Plant Model/Nominal Plant'],...
		'Drop Shadow',4,...
		'position',[325,48,405,92])

add_block('built-in/Sum',[sys,'/','Plant Model/Sum1'])
set_param([sys,'/','Plant Model/Sum1'],...
		'position',[265,52,290,83])


%     Subsystem  'Plant Model/Unmodeled Dynamics'.

new_system([sys,'/','Plant Model/Unmodeled Dynamics'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics'],'Location',[508,114,1088,385])

add_block('built-in/Gain',[sys,'/','Plant Model/Unmodeled Dynamics/Gain'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/Gain'],...
		'orientation',2,...
		'position',[230,107,265,143])

add_block('built-in/Inport',[sys,'/','Plant Model/Unmodeled Dynamics/u'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/u'],...
		'position',[10,46,35,74])

add_block('built-in/Product',[sys,'/','Plant Model/Unmodeled Dynamics/Product'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/Product'],...
		'position',[205,55,230,90])

add_block('built-in/Sum',[sys,'/','Plant Model/Unmodeled Dynamics/Sum2'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/Sum2'],...
		'inputs','+-',...
		'position',[140,52,160,83])

add_block('built-in/Inport',[sys,'/','Plant Model/Unmodeled Dynamics/mu'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/mu'],...
		'Port','2',...
		'position',[10,96,35,124])

add_block('built-in/Gain',[sys,'/','Plant Model/Unmodeled Dynamics/Gain1'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/Gain1'],...
		'Gain','2',...
		'position',[65,44,95,76])

add_block('built-in/Fcn',[sys,'/','Plant Model/Unmodeled Dynamics/Fcn'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/Fcn'],...
		'Expr','1/u(1)',...
		'position',[65,97,115,123])

add_block('built-in/Outport',[sys,'/','Plant Model/Unmodeled Dynamics/u_d'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/u_d'],...
		'position',[520,56,545,84])

add_block('built-in/Sum',[sys,'/','Plant Model/Unmodeled Dynamics/Sum3'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/Sum3'],...
		'inputs','-+',...
		'position',[450,52,475,83])

add_block('built-in/Integrator',[sys,'/','Plant Model/Unmodeled Dynamics/Integrator1'])
set_param([sys,'/','Plant Model/Unmodeled Dynamics/Integrator1'],...
		'Initial','1',...
		'position',[290,57,315,93])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[320,75;445,75])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[235,75;285,75])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[100,60;135,60])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[225,125;125,125;135,75])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[480,70;515,70])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[435,75;380,75;380,125;270,125])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[40,60;60,60])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[165,70;180,70;180,65;200,65])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[115,60;115,15;380,15;380,60;445,60])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[40,110;60,110])
add_line([sys,'/','Plant Model/Unmodeled Dynamics'],[120,110;180,110;180,80;200,80])
set_param([sys,'/','Plant Model/Unmodeled Dynamics'],...

		'Mask Display','-2*mu*s/(1+mu*s)')


%     Finished composite block 'Plant Model/Unmodeled Dynamics'.

set_param([sys,'/','Plant Model/Unmodeled Dynamics'],...
		'Drop Shadow',4,...
		'position',[65,83,195,152])
add_line([sys,'/','Plant Model'],[410,70;435,70])
add_line([sys,'/','Plant Model'],[40,60;50,60;60,100])
add_line([sys,'/','Plant Model'],[295,70;320,70])
add_line([sys,'/','Plant Model'],[40,60;260,60])
add_line([sys,'/','Plant Model'],[200,120;200,75;260,75])
add_line([sys,'/','Plant Model'],[40,135;60,135])
set_param([sys,'/','Plant Model'],...
		'Mask Display','Plant')


%     Finished composite block 'Plant Model'.

set_param([sys,'/','Plant Model'],...
		'Drop Shadow',4,...
		'position',[150,125,225,180])

add_block('built-in/Scope',[sys,'/','Tracking error'])
set_param([sys,'/','Tracking error'],...
		'Vgain','10.000000',...
		'Hgain','20.000000',...
		'Vmax','20.000000',...
		'Hmax','40.000000',...
		'Window',[808,488,1088,708],...
		'position',[360,63,395,97])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'inputs','-+',...
		'position',[270,62,300,98])


%     Subsystem  'Adaptive Law'.

new_system([sys,'/','Adaptive Law'])
set_param([sys,'/','Adaptive Law'],'Location',[4,58,688,567])


%     Subsystem  'Adaptive Law/Filters'.

new_system([sys,'/','Adaptive Law/Filters'])
set_param([sys,'/','Adaptive Law/Filters'],'Location',[91,80,542,377])

add_block('built-in/Transfer Fcn',[sys,'/','Adaptive Law/Filters/phi1 '])
set_param([sys,'/','Adaptive Law/Filters/phi1 '],...
		'Denominator','[1 2]',...
		'position',[85,7,120,43])

add_block('built-in/Outport',[sys,'/','Adaptive Law/Filters/phi_'])
set_param([sys,'/','Adaptive Law/Filters/phi_'],...
		'position',[270,60,290,80])

add_block('built-in/Inport',[sys,'/','Adaptive Law/Filters/u'])
set_param([sys,'/','Adaptive Law/Filters/u'],...
		'position',[35,15,55,35])

add_block('built-in/Inport',[sys,'/','Adaptive Law/Filters/y'])
set_param([sys,'/','Adaptive Law/Filters/y'],...
		'Port','2',...
		'position',[35,110,55,130])

add_block('built-in/Transfer Fcn',[sys,'/','Adaptive Law/Filters/phi2'])
set_param([sys,'/','Adaptive Law/Filters/phi2'],...
		'Numerator','[-1]',...
		'Denominator','[1 2]',...
		'position',[100,102,135,138])

add_block('built-in/Mux',[sys,'/','Adaptive Law/Filters/phi'])
set_param([sys,'/','Adaptive Law/Filters/phi'],...
		'inputs','2',...
		'position',[205,50,235,85])

add_block('built-in/Inport',[sys,'/','Adaptive Law/Filters/theta'])
set_param([sys,'/','Adaptive Law/Filters/theta'],...
		'Port','3',...
		'position',[40,195,60,215])

add_block('built-in/Demux',[sys,'/','Adaptive Law/Filters/Demux'])
set_param([sys,'/','Adaptive Law/Filters/Demux'],...
		'outputs','2',...
		'position',[120,185,160,220])

add_block('built-in/Transfer Fcn',[sys,'/','Adaptive Law/Filters/z '])
set_param([sys,'/','Adaptive Law/Filters/z '],...
		'Numerator','[ 1 0]',...
		'Denominator','[1 2]',...
		'position',[110,257,145,293])

add_block('built-in/Mux',[sys,'/','Adaptive Law/Filters/mux'])
set_param([sys,'/','Adaptive Law/Filters/mux'],...
		'inputs','5',...
		'position',[255,172,285,228])

add_block('built-in/Fcn',[sys,'/','Adaptive Law/Filters/Fcn'])
set_param([sys,'/','Adaptive Law/Filters/Fcn'],...
		'Expr','u(5)-u(1)*u(3)-u(2)*u(4)',...
		'position',[310,190,350,210])

add_block('built-in/Outport',[sys,'/','Adaptive Law/Filters/epsl'])
set_param([sys,'/','Adaptive Law/Filters/epsl'],...
		'Port','2',...
		'position',[390,190,410,210])
add_line([sys,'/','Adaptive Law/Filters'],[355,200;385,200])
add_line([sys,'/','Adaptive Law/Filters'],[290,200;305,200])
add_line([sys,'/','Adaptive Law/Filters'],[150,275;225,275;225,220;250,220])
add_line([sys,'/','Adaptive Law/Filters'],[165,210;250,210])
add_line([sys,'/','Adaptive Law/Filters'],[165,195;235,195;235,200;250,200])
add_line([sys,'/','Adaptive Law/Filters'],[140,120;235,120;235,190;250,190])
add_line([sys,'/','Adaptive Law/Filters'],[125,25;170,25;170,180;250,180])
add_line([sys,'/','Adaptive Law/Filters'],[60,120;75,120;75,275;105,275])
add_line([sys,'/','Adaptive Law/Filters'],[65,205;115,205])
add_line([sys,'/','Adaptive Law/Filters'],[240,70;265,70])
add_line([sys,'/','Adaptive Law/Filters'],[140,120;160,120;160,75;200,75])
add_line([sys,'/','Adaptive Law/Filters'],[125,25;170,25;170,60;200,60])
add_line([sys,'/','Adaptive Law/Filters'],[60,120;95,120])
add_line([sys,'/','Adaptive Law/Filters'],[60,25;80,25])
set_param([sys,'/','Adaptive Law/Filters'],...
		'Mask Display','phi\nepsilon')


%     Finished composite block 'Adaptive Law/Filters'.

set_param([sys,'/','Adaptive Law/Filters'],...
		'Drop Shadow',4,...
		'position',[80,130,150,190])

add_block('built-in/Fcn',[sys,'/','Adaptive Law/Fcn'])
set_param([sys,'/','Adaptive Law/Fcn'],...
		'orientation',2,...
		'Expr','u(1)-0.05',...
		'position',[445,180,485,200])

add_block('built-in/Gain',[sys,'/','Adaptive Law/Adapt_gain_'])
set_param([sys,'/','Adaptive Law/Adapt_gain_'],...
		'position',[395,229,425,261])


add_block('built-in/Inport',[sys,'/','Adaptive Law/u'])
set_param([sys,'/','Adaptive Law/u'],...
		'Port','2',...
		'position',[0,197,25,223])

add_block('built-in/Inport',[sys,'/','Adaptive Law/y'])
set_param([sys,'/','Adaptive Law/y'],...
		'position',[0,102,25,128])


%     Subsystem  'Adaptive Law/theta_dot'.

new_system([sys,'/','Adaptive Law/theta_dot'])
set_param([sys,'/','Adaptive Law/theta_dot'],'Location',[142,85,574,358])

add_block('built-in/Sum',[sys,'/','Adaptive Law/theta_dot/Sum'])
set_param([sys,'/','Adaptive Law/theta_dot/Sum'],...
		'inputs','-+',...
		'position',[280,62,315,98])

add_block('built-in/Product',[sys,'/','Adaptive Law/theta_dot/Product'])
set_param([sys,'/','Adaptive Law/theta_dot/Product'],...
		'inputs','3',...
		'position',[180,72,205,108])

add_block('built-in/Inport',[sys,'/','Adaptive Law/theta_dot/phi'])
set_param([sys,'/','Adaptive Law/theta_dot/phi'],...
		'Port','2',...
		'position',[20,20,50,50])

add_block('built-in/Inport',[sys,'/','Adaptive Law/theta_dot/epsilon'])
set_param([sys,'/','Adaptive Law/theta_dot/epsilon'],...
		'Port','3',...
		'position',[20,74,50,106])

add_block('built-in/Inport',[sys,'/','Adaptive Law/theta_dot/normalization'])
set_param([sys,'/','Adaptive Law/theta_dot/normalization'],...
		'Port','4',...
		'position',[20,139,50,171])

add_block('built-in/Outport',[sys,'/','Adaptive Law/theta_dot/theta_dot'])
set_param([sys,'/','Adaptive Law/theta_dot/theta_dot'],...
		'position',[355,64,385,96])

add_block('built-in/Inport',[sys,'/','Adaptive Law/theta_dot/sigma_switching'])
set_param([sys,'/','Adaptive Law/theta_dot/sigma_switching'],...
		'position',[175,5,205,35])
add_line([sys,'/','Adaptive Law/theta_dot'],[55,90;175,90])
add_line([sys,'/','Adaptive Law/theta_dot'],[320,80;350,80])
add_line([sys,'/','Adaptive Law/theta_dot'],[210,20;210,70;275,70])
add_line([sys,'/','Adaptive Law/theta_dot'],[210,90;275,90])
add_line([sys,'/','Adaptive Law/theta_dot'],[55,35;120,35;120,80;175,80])
add_line([sys,'/','Adaptive Law/theta_dot'],[55,155;120,155;120,100;175,100])
set_param([sys,'/','Adaptive Law/theta_dot'],...
		'Mask Display','theta_dot')


%     Finished composite block 'Adaptive Law/theta_dot'.

set_param([sys,'/','Adaptive Law/theta_dot'],...
		'Drop Shadow',4,...
		'position',[195,131,265,184])

add_block('built-in/Demux',[sys,'/','Adaptive Law/Demux'])
set_param([sys,'/','Adaptive Law/Demux'],...
		'outputs','2',...
		'position',[280,142,330,178])

add_block('built-in/Gain',[sys,'/','Adaptive Law/Adapt_gain'])
set_param([sys,'/','Adaptive Law/Adapt_gain'],...
		'position',[360,95,390,125])

add_block('built-in/Integrator',[sys,'/','Adaptive Law/est_b'])
set_param([sys,'/','Adaptive Law/est_b'],...
		'Initial','2',...
		'position',[500,123,530,167])

add_block('built-in/Switch',[sys,'/','Adaptive Law/Switch'])
set_param([sys,'/','Adaptive Law/Switch'],...
		'position',[445,104,475,136])

add_block('built-in/Constant',[sys,'/','Adaptive Law/Constant'])
set_param([sys,'/','Adaptive Law/Constant'],...
		'Value','0',...
		'position',[405,145,425,165])

add_block('built-in/Mux',[sys,'/','Adaptive Law/Mux1'])
set_param([sys,'/','Adaptive Law/Mux1'],...
		'inputs','2',...
		'position',[565,170,595,205])

add_block('built-in/Outport',[sys,'/','Adaptive Law/theta'])
set_param([sys,'/','Adaptive Law/theta'],...
		'position',[645,177,670,203])


%     Subsystem  'Adaptive Law/Normalization'.

new_system([sys,'/','Adaptive Law/Normalization'])
set_param([sys,'/','Adaptive Law/Normalization'],'Location',[41,79,584,335])

add_block('built-in/Fcn',[sys,'/','Adaptive Law/Normalization/Fcn'])
set_param([sys,'/','Adaptive Law/Normalization/Fcn'],...
		'Expr','u(1)*u(1)+u(2)*u(2)',...
		'position',[130,49,185,81])

add_block('built-in/Sum',[sys,'/','Adaptive Law/Normalization/Sum2'])
set_param([sys,'/','Adaptive Law/Normalization/Sum2'],...
		'inputs','+-',...
		'position',[220,57,240,88])

add_block('built-in/Mux',[sys,'/','Adaptive Law/Normalization/Mux'])
set_param([sys,'/','Adaptive Law/Normalization/Mux'],...
		'inputs','2',...
		'position',[70,46,100,79])

add_block('built-in/Inport',[sys,'/','Adaptive Law/Normalization/u'])
set_param([sys,'/','Adaptive Law/Normalization/u'],...
		'position',[5,7,30,33])

add_block('built-in/Inport',[sys,'/','Adaptive Law/Normalization/y'])
set_param([sys,'/','Adaptive Law/Normalization/y'],...
		'Port','2',...
		'position',[5,87,30,113])

add_block('built-in/Integrator',[sys,'/','Adaptive Law/Normalization/Integrator1'])
set_param([sys,'/','Adaptive Law/Normalization/Integrator1'],...
		'position',[265,50,290,100])

add_block('built-in/Outport',[sys,'/','Adaptive Law/Normalization/1//m'])
set_param([sys,'/','Adaptive Law/Normalization/1//m'],...
		'position',[485,62,510,88])

add_block('built-in/Fcn',[sys,'/','Adaptive Law/Normalization/Fcn1'])
set_param([sys,'/','Adaptive Law/Normalization/Fcn1'],...
		'Expr','1/(1+u(1))',...
		'Mask Display','1/(1+m*m)',...
		'position',[335,53,425,97])
add_line([sys,'/','Adaptive Law/Normalization'],[430,75;480,75])
add_line([sys,'/','Adaptive Law/Normalization'],[295,75;330,75])
add_line([sys,'/','Adaptive Law/Normalization'],[245,75;260,75])
add_line([sys,'/','Adaptive Law/Normalization'],[190,65;215,65])
add_line([sys,'/','Adaptive Law/Normalization'],[315,75;315,140;190,140;190,80;215,80])
add_line([sys,'/','Adaptive Law/Normalization'],[105,65;125,65])
add_line([sys,'/','Adaptive Law/Normalization'],[35,20;50,20;50,55;65,55])
add_line([sys,'/','Adaptive Law/Normalization'],[35,100;50,100;50,70;65,70])
set_param([sys,'/','Adaptive Law/Normalization'],...
		'Mask Display','Normalization')


%     Finished composite block 'Adaptive Law/Normalization'.

set_param([sys,'/','Adaptive Law/Normalization'],...
		'Drop Shadow',4,...
		'position',[75,290,175,345])

add_block('built-in/Integrator',[sys,'/','Adaptive Law/est_a'])
set_param([sys,'/','Adaptive Law/est_a'],...
		'Initial','-2',...
		'position',[480,224,510,266])


%     Subsystem  'Adaptive Law/Modification'.

new_system([sys,'/','Adaptive Law/Modification'])
set_param([sys,'/','Adaptive Law/Modification'],'Location',[47,69,594,333])

add_block('built-in/Product',[sys,'/','Adaptive Law/Modification/Product'])
set_param([sys,'/','Adaptive Law/Modification/Product'],...
		'position',[395,47,430,83])

add_block('built-in/Inport',[sys,'/','Adaptive Law/Modification/theta'])
set_param([sys,'/','Adaptive Law/Modification/theta'],...
		'position',[20,59,50,91])

add_block('built-in/Switch',[sys,'/','Adaptive Law/Modification/Switch'])
set_param([sys,'/','Adaptive Law/Modification/Switch'],...
		'position',[305,94,330,126])

add_block('built-in/Fcn',[sys,'/','Adaptive Law/Modification/Fcn'])
set_param([sys,'/','Adaptive Law/Modification/Fcn'],...
		'Expr','400-u(1)*u(1)-u(2)*u(2)',...
		'position',[170,94,225,126])

add_block('built-in/Fcn',[sys,'/','Adaptive Law/Modification/Fcn1'])
set_param([sys,'/','Adaptive Law/Modification/Fcn1'],...
		'Expr','0.2*(sqrt(u(1)*u(1)+u(2)*u(2))/20-1)',...
		'position',[170,139,225,171])

add_block('built-in/Constant',[sys,'/','Adaptive Law/Modification/no_modification'])
set_param([sys,'/','Adaptive Law/Modification/no_modification'],...
		'Value','0',...
		'position',[170,34,220,66])

add_block('built-in/Outport',[sys,'/','Adaptive Law/Modification/switching_theta'])
set_param([sys,'/','Adaptive Law/Modification/switching_theta'],...
		'position',[490,50,520,80])
add_line([sys,'/','Adaptive Law/Modification'],[230,110;300,110])
add_line([sys,'/','Adaptive Law/Modification'],[225,50;275,50;275,100;300,100])
add_line([sys,'/','Adaptive Law/Modification'],[230,155;275,155;275,120;300,120])
add_line([sys,'/','Adaptive Law/Modification'],[55,75;95,75;95,110;165,110])
add_line([sys,'/','Adaptive Law/Modification'],[95,105;95,155;165,155])
add_line([sys,'/','Adaptive Law/Modification'],[335,110;365,110;365,75;390,75])
add_line([sys,'/','Adaptive Law/Modification'],[95,75;95,20;365,20;365,55;390,55])
add_line([sys,'/','Adaptive Law/Modification'],[435,65;485,65])
set_param([sys,'/','Adaptive Law/Modification'],...
		'Mask Display','Switching-Sigma')


%     Finished composite block 'Adaptive Law/Modification'.

set_param([sys,'/','Adaptive Law/Modification'],...
		'orientation',2,...
		'Drop Shadow',4,...
		'position',[220,25,355,95])
add_line([sys,'/','Adaptive Law'],[430,245;475,245])
add_line([sys,'/','Adaptive Law'],[215,60;180,60;190,135])
add_line([sys,'/','Adaptive Law'],[30,115;55,115;55,160;75,160])
add_line([sys,'/','Adaptive Law'],[270,160;275,160])
add_line([sys,'/','Adaptive Law'],[535,145;535,190;490,190])
add_line([sys,'/','Adaptive Law'],[440,190;395,190;395,120;440,120])
add_line([sys,'/','Adaptive Law'],[430,155;440,130])
add_line([sys,'/','Adaptive Law'],[335,150;345,150;355,110])
add_line([sys,'/','Adaptive Law'],[155,175;180,175;190,165])
add_line([sys,'/','Adaptive Law'],[155,145;180,145;190,150])
add_line([sys,'/','Adaptive Law'],[535,145;550,145;560,180])
add_line([sys,'/','Adaptive Law'],[515,245;550,245;560,195])
add_line([sys,'/','Adaptive Law'],[30,210;45,210;45,140;75,140])
add_line([sys,'/','Adaptive Law'],[45,210;45,330;70,330])
add_line([sys,'/','Adaptive Law'],[180,320;190,180])
add_line([sys,'/','Adaptive Law'],[335,170;345,170;345,245;390,245])
add_line([sys,'/','Adaptive Law'],[395,110;440,110])
add_line([sys,'/','Adaptive Law'],[600,190;640,190])
add_line([sys,'/','Adaptive Law'],[615,190;615,60;360,60])
add_line([sys,'/','Adaptive Law'],[615,190;615,285;65,285;75,180])
add_line([sys,'/','Adaptive Law'],[480,120;485,120;495,145])
add_line([sys,'/','Adaptive Law'],[55,160;70,305])
set_param([sys,'/','Adaptive Law'],...
		'Mask Display','Adaptation')


%     Finished composite block 'Adaptive Law'.

set_param([sys,'/','Adaptive Law'],...
		'Drop Shadow',4,...
		'position',[345,124,455,186])


%     Subsystem  'Controller'.

new_system([sys,'/','Controller'])
set_param([sys,'/','Controller'],'Location',[4,58,534,353])

add_block('built-in/Inport',[sys,'/','Controller/p0'])
set_param([sys,'/','Controller/p0'],...
		'Port','3',...
		'position',[30,172,55,198])

add_block('built-in/Gain',[sys,'/','Controller/Gain'])
set_param([sys,'/','Controller/Gain'],...
		'Gain','2',...
		'position',[145,157,175,183])

add_block('built-in/Sum',[sys,'/','Controller/Sum1'])
set_param([sys,'/','Controller/Sum1'],...
		'inputs','-+',...
		'position',[205,161,230,194])

add_block('built-in/Transfer Fcn',[sys,'/','Controller/Transfer Fcn1'])
set_param([sys,'/','Controller/Transfer Fcn1'],...
		'Denominator','[1 2]',...
		'position',[180,72,215,108])

add_block('built-in/Product',[sys,'/','Controller/Product1'])
set_param([sys,'/','Controller/Product1'],...
		'position',[275,92,305,123])

add_block('built-in/Transfer Fcn',[sys,'/','Controller/Transfer Fcn'])
set_param([sys,'/','Controller/Transfer Fcn'],...
		'orientation',2,...
		'Numerator','[2]',...
		'Denominator','[1 2]',...
		'position',[360,147,395,183])

add_block('built-in/Outport',[sys,'/','Controller/out_1'])
set_param([sys,'/','Controller/out_1'],...
		'position',[465,96,490,124])

add_block('built-in/Inport',[sys,'/','Controller/p1'])
set_param([sys,'/','Controller/p1'],...
		'Port','2',...
		'position',[30,97,55,123])

add_block('built-in/Sum',[sys,'/','Controller/Sum'])
set_param([sys,'/','Controller/Sum'],...
		'inputs','--+',...
		'position',[365,92,385,128])

add_block('built-in/Product',[sys,'/','Controller/Product'])
set_param([sys,'/','Controller/Product'],...
		'position',[185,24,215,51])

add_block('built-in/Inport',[sys,'/','Controller/error'])
set_param([sys,'/','Controller/error'],...
		'position',[30,17,55,43])
add_line([sys,'/','Controller'],[390,110;460,110])
add_line([sys,'/','Controller'],[390,110;435,110;435,165;400,165])
add_line([sys,'/','Controller'],[355,165;320,165;320,120;360,120])
add_line([sys,'/','Controller'],[60,30;180,30])
add_line([sys,'/','Controller'],[60,110;150,110;150,45;180,45])
add_line([sys,'/','Controller'],[60,185;200,185])
add_line([sys,'/','Controller'],[180,170;200,170])
add_line([sys,'/','Controller'],[220,40;340,40;340,100;360,100])
add_line([sys,'/','Controller'],[310,110;360,110])
add_line([sys,'/','Controller'],[125,30;125,90;175,90])
add_line([sys,'/','Controller'],[125,110;125,170;140,170])
add_line([sys,'/','Controller'],[220,90;250,90;250,100;270,100])
add_line([sys,'/','Controller'],[235,180;250,180;250,115;270,115])
set_param([sys,'/','Controller'],...
		'Mask Display','Controller')


%     Finished composite block 'Controller'.

set_param([sys,'/','Controller'],...
		'orientation',2,...
		'Drop Shadow',4,...
		'position',[190,239,265,291])


%     Subsystem  'C-parameters'.

new_system([sys,'/','C-parameters'])
set_param([sys,'/','C-parameters'],'Location',[239,163,576,360])

add_block('built-in/Outport',[sys,'/','C-parameters/p_0'])
set_param([sys,'/','C-parameters/p_0'],...
		'Port','2',...
		'position',[275,109,305,141])

add_block('built-in/Fcn',[sys,'/','C-parameters/Fcn1'])
set_param([sys,'/','C-parameters/Fcn1'],...
		'Expr','1/u(1)',...
		'position',[185,109,240,141])

add_block('built-in/Fcn',[sys,'/','C-parameters/Fcn'])
set_param([sys,'/','C-parameters/Fcn'],...
		'Expr','(2-u(2))/u(1)',...
		'position',[185,52,240,88])

add_block('built-in/Outport',[sys,'/','C-parameters/p1'])
set_param([sys,'/','C-parameters/p1'],...
		'position',[275,54,305,86])

add_block('built-in/Inport',[sys,'/','C-parameters/theta'])
set_param([sys,'/','C-parameters/theta'],...
		'position',[60,79,90,111])
add_line([sys,'/','C-parameters'],[245,70;270,70])
add_line([sys,'/','C-parameters'],[245,125;270,125])
add_line([sys,'/','C-parameters'],[95,95;140,95;140,125;180,125])
add_line([sys,'/','C-parameters'],[140,95;140,70;180,70])
set_param([sys,'/','C-parameters'],...
		'Mask Display','Controller\nparameter\ncalculation')


%     Finished composite block 'C-parameters'.

set_param([sys,'/','C-parameters'],...
		'orientation',2,...
		'Drop Shadow',4,...
		'position',[350,235,455,295])

add_block('built-in/To Workspace',[sys,'/','To Workspace'])
set_param([sys,'/','To Workspace'],...
		'mat-name','yout',...
		'position',[535,88,605,122])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'inputs','2',...
		'position',[470,85,500,125])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'orientation',1,...
		'position',[445,25,465,45])


%     Subsystem  'Text'.

new_system([sys,'/','Text'])
set_param([sys,'/','Text'],'Location',[169,65,608,511])

add_block('built-in/Note',[sys,'/',['Text/3) The parameter for the switching-sigmal modification',13,'in the Adaptation//Modification block']])
set_param([sys,'/',['Text/3) The parameter for the switching-sigmal modification',13,'in the Adaptation//Modification block']],...
		'position',[200,330,205,335])

add_block('built-in/Note',[sys,'/',['Text/2) The normalization parameter in the Adaptation//Normalization',13,'block']])
set_param([sys,'/',['Text/2) The normalization parameter in the Adaptation//Normalization',13,'block']],...
		'position',[230,290,235,295])

add_block('built-in/Note',[sys,'/','Text/1) The adaptive gains in the Adaptation block'])
set_param([sys,'/','Text/1) The adaptive gains in the Adaptation block'],...
		'position',[170,260,175,265])

add_block('built-in/Note',[sys,'/',['Text/You can also change the following parameters',13,' of the adaptive controller to see how they affect',13,'the overall control performance:',13,'']])
set_param([sys,'/',['Text/You can also change the following parameters',13,' of the adaptive controller to see how they affect',13,'the overall control performance:',13,'']],...
		'position',[180,190,185,195])

add_block('built-in/Note',[sys,'/',['Text/To see the effects of unmodeled dynamics on the ',13,'performance of the closed loop adaptive control ',13,'scheme, change the parameter mu']])
set_param([sys,'/',['Text/To see the effects of unmodeled dynamics on the ',13,'performance of the closed loop adaptive control ',13,'scheme, change the parameter mu']],...
		'position',[185,130,190,135])

add_block('built-in/Note',[sys,'/',['Text/The switching sigma modification and projection',13,'algorithm are used. Please refer to Chapter 9',13,'of the textbook for details of the problem and algorithm.']])
set_param([sys,'/',['Text/The switching sigma modification and projection',13,'algorithm are used. Please refer to Chapter 9',13,'of the textbook for details of the problem and algorithm.']],...
		'position',[195,70,200,75])

add_block('built-in/Note',[sys,'/',['Text/This program simulates the robust pole placement',13,'adaptive control scheme for a first order plant with',13,'unmodeled dynamics discussed in Example 9.5.1.',13,' ']])
set_param([sys,'/',['Text/This program simulates the robust pole placement',13,'adaptive control scheme for a first order plant with',13,'unmodeled dynamics discussed in Example 9.5.1.',13,' ']],...
		'position',[195,0,200,5])
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',[432,332,575,411])

add_block('built-in/Constant',[sys,'/','Tracking Sigmal'])
set_param([sys,'/','Tracking Sigmal'],...
		'Mask Display','Constant',...
		'position',[40,46,115,94])
add_line(sys,[185,265;110,265;110,140;145,140])
add_line(sys,[460,155;470,155;460,265])
add_line(sys,[455,50;465,95])
add_line(sys,[505,105;530,105])
add_line(sys,[120,70;265,70])
add_line(sys,[75,165;145,165])
add_line(sys,[305,80;355,80])
add_line(sys,[315,80;315,250;270,250])
add_line(sys,[230,155;305,155;305,140;340,140])
add_line(sys,[110,195;305,195;305,170;340,170])
add_line(sys,[250,155;250,90;265,90])
add_line(sys,[345,250;325,250;325,265;270,265])
add_line(sys,[345,280;270,280])
add_line(sys,[305,140;305,115;465,115])

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
