function [ret,x0,str]=ltrdemo2(t,x,u,flag);
%LTRDEMO2	is the M-file description of the SIMULINK system named LTRDEMO2.
%	The block-diagram can be displayed by typing: LTRDEMO2.
%
%	SYS=LTRDEMO2(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 LTRDEMO2 to return state derivitives, FLAG=2
%	discrete states, FLAG=3 system outputs and FLAG=4 next sample
%	time. For more information and other options see SFUNC.
%
%	Calling LTRDEMO2 with a FLAG of zero:
%	[SIZES]=LTRDEMO2([],[],[],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.

%	Copyright (c) 1990-94 by The MathWorks, Inc.

% 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',[518,574,1087,896])
     open_system(sys)
end;
set_param(sys,'algorithm',		'Linear')
set_param(sys,'Start time',	'0.0')
set_param(sys,'Stop time',		'200')
set_param(sys,'Min step size',	'0.01')
set_param(sys,'Max step size',	'0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',	'')

add_block('built-in/Note',[sys,'/','LQG and Loop Transfer Recovery Controller Design'])
set_param([sys,'/','LQG and Loop Transfer Recovery Controller Design'],...
		'position',[279,10,280,11])

add_block('built-in/Product',[sys,'/','Product'])
set_param([sys,'/','Product'],...
		'position',[345,55,370,75])

add_block('built-in/Sum',[sys,'/','Sum2'])
set_param([sys,'/','Sum2'],...
		'inputs','+++',...
		'position',[425,103,440,137])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'inputs','+++-',...
		'position',[170,107,190,153])

add_block('built-in/Sum',[sys,'/','Sum1'])
set_param([sys,'/','Sum1'],...
		'orientation',2,...
		'position',[375,195,395,215])


%     Subsystem  ['Double click here',13,'to show zero-pole',13,'plot of closed-loop4'].

new_system([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of closed-loop4']])
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of closed-loop4']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of closed-loop4']],...
		'Mask Display','Controller\nBode Plot',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of closed-loop4']],...
		'Mask Dialogue','eval(''if ~exist(''''ae''''),fprintf(''''\nMust Load Data & Design First\n''''),else  [x,y,w]=bode(ae,be,ce,de); clg; subplot(211); loglog(w,x(:,1)); subplot(212); semilogx(w,y(:,1)); subplot(111); end'')')
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of closed-loop4']],...
		'Mask Translate','',...
		'Mask Help','')


%     Finished composite block ['Double click here',13,'to show zero-pole',13,'plot of closed-loop4'].

set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of closed-loop4']],...
		'hide name',0,...
		'position',[260,266,333,298])


%     Subsystem  ['excitation',13,'noise'].

new_system([sys,'/',['excitation',13,'noise']])
set_param([sys,'/',['excitation',13,'noise']],'Location',[0,0,262,236])

add_block('built-in/Discrete Transfer Fcn',[sys,'/',['excitation',13,'noise/Zero Order Hold']])
set_param([sys,'/',['excitation',13,'noise/Zero Order Hold']],...
		'Numerator','[sqrt(Cov)]',...
		'Denominator','[sqrt(Ts)]',...
		'Sample time','Ts',...
		'position',[140,61,205,99])

add_block('built-in/White Noise',[sys,'/',['excitation',13,'noise/White Noise']])
set_param([sys,'/',['excitation',13,'noise/White Noise']],...
		'Seed','seed',...
		'position',[55,70,75,90])

add_block('built-in/Outport',[sys,'/',['excitation',13,'noise/out_1']])
set_param([sys,'/',['excitation',13,'noise/out_1']],...
		'position',[235,70,255,90])
add_line([sys,'/',['excitation',13,'noise']],[80,80;130,80])
add_line([sys,'/',['excitation',13,'noise']],[210,80;225,80])
set_param([sys,'/',['excitation',13,'noise']],...
		'Mask Display','plot(t(:),r2(:))',...
		'Mask Type','Continuous White Noise.')
set_param([sys,'/',['excitation',13,'noise']],...
		'Mask Dialogue','White noise for continuous (s-domain) systems.\nBand-limited using zero-order-hold.|Noise Variance:|Sample Time:|Seed')
set_param([sys,'/',['excitation',13,'noise']],...
		'Mask Translate','Cov = @1; Ts = @2; seed = @3; r = rand(1,12)-0.5; r2 = [r(1),r;r,r(12)]; t =[1:13;1:13];')
set_param([sys,'/',['excitation',13,'noise']],...
		'Mask Help','Implemented using white noise into Zero Order Hold block. For faster simulation set sample time to highest value possible but in accordance with the fastest dynamics of system.')
set_param([sys,'/',['excitation',13,'noise']],...
		'Mask Entries','0.1\/1\/68932234\/')


%     Finished composite block ['excitation',13,'noise'].

set_param([sys,'/',['excitation',13,'noise']],...
		'position',[45,102,85,128])

add_block('built-in/Inport',[sys,'/','Inport2'])
set_param([sys,'/','Inport2'],...
		'position',[55,155,75,175])

add_block('built-in/Signal Generator',[sys,'/','Signal Gen.'])
set_param([sys,'/','Signal Gen.'],...
		'Peak','1.000000',...
		'Peak Range','5.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[40,203,85,237])

add_block('built-in/State-space',[sys,'/','Controller'])
set_param([sys,'/','Controller'],...
		'orientation',2,...
		'A','ae',...
		'B','be',...
		'C','ce',...
		'D','de',...
		'Mask Display','LQG/LTR',...
		'Mask Type','LTR CONTROLLER')
set_param([sys,'/','Controller'],...
		'Mask Dialogue','LTR controller.\n(Requires Control Toolbox and RCT)|Controller Matrix A:|Controller Matrix B:|Controller Matrix C:|Controller Matrix D:',...
		'Mask Translate','ae=@1; be=@2; ce=@3; de=@4;')
set_param([sys,'/','Controller'],...
		'Mask Help','LTR controller design. Mask and unmask this block to see how it works.',...
		'Mask Entries','ae\/be\/ce\/de\/',...
		'position',[220,180,310,230])


%     Subsystem  ['Sensor',13,'Noise'].

new_system([sys,'/',['Sensor',13,'Noise']])
set_param([sys,'/',['Sensor',13,'Noise']],'Location',[0,0,262,236])

add_block('built-in/Outport',[sys,'/',['Sensor',13,'Noise/out_1']])
set_param([sys,'/',['Sensor',13,'Noise/out_1']],...
		'position',[235,70,255,90])

add_block('built-in/White Noise',[sys,'/',['Sensor',13,'Noise/White Noise']])
set_param([sys,'/',['Sensor',13,'Noise/White Noise']],...
		'Seed','seed',...
		'position',[55,70,75,90])

add_block('built-in/Discrete Transfer Fcn',[sys,'/',['Sensor',13,'Noise/Zero Order Hold']])
set_param([sys,'/',['Sensor',13,'Noise/Zero Order Hold']],...
		'Numerator','[sqrt(Cov)]',...
		'Denominator','[sqrt(Ts)]',...
		'Sample time','Ts',...
		'position',[140,61,205,99])
add_line([sys,'/',['Sensor',13,'Noise']],[210,80;225,80])
add_line([sys,'/',['Sensor',13,'Noise']],[80,80;130,80])
set_param([sys,'/',['Sensor',13,'Noise']],...
		'Mask Display','plot(1:20,rand(1,20))',...
		'Mask Type','Continuous White Noise.')
set_param([sys,'/',['Sensor',13,'Noise']],...
		'Mask Dialogue','White noise for continuous (s-domain) systems.\nBand-limited using zero-order-hold.|Noise Variance:|Sample Time:|Seed',...
		'Mask Translate','Cov = @1; Ts = @2; seed = @3;')
set_param([sys,'/',['Sensor',13,'Noise']],...
		'Mask Help','Implemented using white noise into Zero Order Hold block. For faster simulation set sample time to highest value possible but in accordance with the fastest dynamics of system.')
set_param([sys,'/',['Sensor',13,'Noise']],...
		'Mask Entries','0.01\/0.11\/23341\/')


%     Finished composite block ['Sensor',13,'Noise'].

set_param([sys,'/',['Sensor',13,'Noise']],...
		'orientation',2,...
		'position',[510,195,540,225])

add_block('built-in/Outport',[sys,'/','Outport'])
set_param([sys,'/','Outport'],...
		'position',[510,151,540,169])


%     Subsystem  ['Additive',13,'noise'].

new_system([sys,'/',['Additive',13,'noise']])
set_param([sys,'/',['Additive',13,'noise']],'Location',[0,0,262,236])

add_block('built-in/Discrete Transfer Fcn',[sys,'/',['Additive',13,'noise/Zero Order Hold']])
set_param([sys,'/',['Additive',13,'noise/Zero Order Hold']],...
		'Numerator','[sqrt(Cov)]',...
		'Denominator','[sqrt(Ts)]',...
		'Sample time','Ts',...
		'position',[140,61,205,99])

add_block('built-in/White Noise',[sys,'/',['Additive',13,'noise/White Noise']])
set_param([sys,'/',['Additive',13,'noise/White Noise']],...
		'Seed','seed',...
		'position',[55,70,75,90])

add_block('built-in/Outport',[sys,'/',['Additive',13,'noise/out_1']])
set_param([sys,'/',['Additive',13,'noise/out_1']],...
		'position',[235,70,255,90])
add_line([sys,'/',['Additive',13,'noise']],[80,80;130,80])
add_line([sys,'/',['Additive',13,'noise']],[210,80;225,80])
set_param([sys,'/',['Additive',13,'noise']],...
		'Mask Display','plot(1:20,rand(1,20))',...
		'Mask Type','Input Noise')
set_param([sys,'/',['Additive',13,'noise']],...
		'Mask Dialogue','White noise for continuous (s-domain) systems.\nBand-limited using zero-order-hold.|Noise Variance:|Sample Time:|Seed')
set_param([sys,'/',['Additive',13,'noise']],...
		'Mask Translate','Cov = @1; Ts = @2; seed = @3; r = rand(1,12)-0.5; ')
set_param([sys,'/',['Additive',13,'noise']],...
		'Mask Help','Implemented using white noise into Zero Order Hold block. For faster simulation set sample time to highest value possible but in accordance with the fastest dynamics of system.')
set_param([sys,'/',['Additive',13,'noise']],...
		'Mask Entries','0.1\/1\/12345\/')


%     Finished composite block ['Additive',13,'noise'].

set_param([sys,'/',['Additive',13,'noise']],...
		'position',[70,19,115,51])


%     Subsystem  ['Multiplicative',13,'noise'].

new_system([sys,'/',['Multiplicative',13,'noise']])
set_param([sys,'/',['Multiplicative',13,'noise']],'Location',[0,0,262,236])

add_block('built-in/Discrete Transfer Fcn',[sys,'/',['Multiplicative',13,'noise/Zero Order Hold']])
set_param([sys,'/',['Multiplicative',13,'noise/Zero Order Hold']],...
		'Numerator','[sqrt(Cov)]',...
		'Denominator','[sqrt(Ts)]',...
		'Sample time','Ts',...
		'position',[140,61,205,99])

add_block('built-in/White Noise',[sys,'/',['Multiplicative',13,'noise/White Noise']])
set_param([sys,'/',['Multiplicative',13,'noise/White Noise']],...
		'Seed','seed',...
		'position',[55,70,75,90])

add_block('built-in/Outport',[sys,'/',['Multiplicative',13,'noise/out_1']])
set_param([sys,'/',['Multiplicative',13,'noise/out_1']],...
		'position',[235,70,255,90])
add_line([sys,'/',['Multiplicative',13,'noise']],[80,80;130,80])
add_line([sys,'/',['Multiplicative',13,'noise']],[210,80;225,80])
set_param([sys,'/',['Multiplicative',13,'noise']],...
		'Mask Display','plot(1:20,rand(1,20))',...
		'Mask Type','Input Noise')
set_param([sys,'/',['Multiplicative',13,'noise']],...
		'Mask Dialogue','White noise for continuous (s-domain) systems.\nBand-limited using zero-order-hold.|Noise Variance:|Sample Time:|Seed')
set_param([sys,'/',['Multiplicative',13,'noise']],...
		'Mask Translate','Cov = @1; Ts = @2; seed = @3; r = rand(1,12)-0.5; ')
set_param([sys,'/',['Multiplicative',13,'noise']],...
		'Mask Help','Implemented using white noise into Zero Order Hold block. For faster simulation set sample time to highest value possible but in accordance with the fastest dynamics of system.')
set_param([sys,'/',['Multiplicative',13,'noise']],...
		'Mask Entries','0.1\/1\/12345\/')


%     Finished composite block ['Multiplicative',13,'noise'].

set_param([sys,'/',['Multiplicative',13,'noise']],...
		'position',[155,44,200,76])

add_block('built-in/State-space',[sys,'/','Plant'])
set_param([sys,'/','Plant'],...
		'A','a',...
		'B','b',...
		'C','c',...
		'D','d',...
		'position',[220,107,300,153])

add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'Vgain','7.000000',...
		'Hgain','10.000000',...
		'Vmax','Inf',...
		'Hmax','20.000000',...
		'Window',[0,0,481,255],...
		'position',[515,107,535,133])


%     Subsystem  ['About ltr',13,'demo2'].

new_system([sys,'/',['About ltr',13,'demo2']])
set_param([sys,'/',['About ltr',13,'demo2']],'Location',[2,439,106,512])
set_param([sys,'/',['About ltr',13,'demo2']],...
		'Mask Display','?',...
		'Mask Type','',...
		'Mask Dialogue','eval(''clc; more(24); help ltrdata2; more off;'')',...
		'Mask Translate','',...
		'Mask Help','')


%     Finished composite block ['About ltr',13,'demo2'].

set_param([sys,'/',['About ltr',13,'demo2']],...
		'hide name',0,...
		'Drop Shadow',4,...
		'position',[507,267,543,296])


%     Subsystem  ['Double click here',13,'to start loading data',13,'and mu-syn design'].

new_system([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],...
		'Mask Display','Re-Load\nData',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],...
		'Mask Dialogue','eval(''if ~exist(''''ltry''''),fprintf(''''\nMust be licensed for RCT Toolbox\n''''), else, ltrdata2; end'')',...
		'Mask Translate','')
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],...
		'Mask Help','')


%     Finished composite block ['Double click here',13,'to start loading data',13,'and mu-syn design'].

set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design']],...
		'hide name',0,...
		'position',[10,264,82,297])


%     Subsystem  ['Double click here',13,'to start loading data',13,'and mu-syn design1'].

new_system([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],...
		'Mask Display','Re-design',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],...
		'Mask Dialogue','eval(''if ~exist(''''ltry''''),fprintf(''''\nMust be licensed for RCT Toolbox\n''''), else, fprintf(''''\nCtrl_C to abort RCT Calculation\n\n''''); ltrdes2; end'')')
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],...
		'Mask Translate','',...
		'Mask Help','')


%     Finished composite block ['Double click here',13,'to start loading data',13,'and mu-syn design1'].

set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],...
		'hide name',0,...
		'position',[94,265,166,298])


%     Subsystem  ['Double click here',13,'to show bode plot',13,'of closed-loop3'].

new_system([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']])
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],...
		'Mask Display','Closed-Loop\nBode Plot',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],...
		'Mask Dialogue','eval(''if ~exist(''''ae''''),fprintf(''''\nMust Load Data & Design First\n''''),else [x,y,z,w]=feedback(a,b,c,d,ae,be,ce,de,-1); [x,y,w]=bode(x,y,z,w); clg; subplot(211); loglog(w,x(:,1)); subplot(212); semilogx(w,y(:,1)); subplot(111);end'')')
set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],...
		'Mask Translate','',...
		'Mask Help','')


%     Finished composite block ['Double click here',13,'to show bode plot',13,'of closed-loop3'].

set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop3']],...
		'hide name',0,...
		'position',[174,266,254,298])


%     Subsystem  ['Double click here',13,'to show zero-pole',13,'plot of controller'].

new_system([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of controller']])
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of controller']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of controller']],...
		'Mask Display','Controller\nNyquist',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of controller']],...
		'Mask Dialogue','eval(''if ~exist(''''ae''''), printf(''''Must Load Data & Desgin First''''), else,clg; nyquist(ae,be,ce,de), end'')',...
		'Mask Translate','')
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of controller']],...
		'Mask Help','')


%     Finished composite block ['Double click here',13,'to show zero-pole',13,'plot of controller'].

set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of controller']],...
		'hide name',0,...
		'position',[425,265,498,298])


%     Subsystem  ['Double click here',13,'to show bode plot ',13,'of controller'].

new_system([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],...
		'Mask Display','Closed-Loop\nNyquist',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],...
		'Mask Dialogue','eval(''if ~exist(''''ae''''), printf(''''Must Load Data & Desgin First''''), else,[x,y,z,w]=feedback(a,b,c,d,ae,be,ce,de,-1); clg, nyquist(x,y,z,w); end'')')
set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],...
		'Mask Translate','',...
		'Mask Help','')


%     Finished composite block ['Double click here',13,'to show bode plot ',13,'of controller'].

set_param([sys,'/',['Double click here',13,'to show bode plot ',13,'of controller']],...
		'hide name',0,...
		'position',[340,267,420,298])
add_line(sys,[445,120;460,120;460,200;405,200])
add_line(sys,[460,160;500,160])
add_line(sys,[120,35;400,35;400,110;415,110])
add_line(sys,[305,130;320,130;320,70;335,70])
add_line(sys,[320,130;415,130])
add_line(sys,[205,60;335,60])
add_line(sys,[445,120;505,120])
add_line(sys,[375,65;385,65;385,120;415,120])
add_line(sys,[195,130;210,130])
add_line(sys,[80,165;120,165;120,125;160,125])
add_line(sys,[90,220;130,220;130,135;160,135])
add_line(sys,[370,205;320,205])
add_line(sys,[215,205;145,205;145,145;160,145])
add_line(sys,[90,115;160,115])
add_line(sys,[505,210;405,210])
% 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]=',sys,'(t,x,u,flag);'])
		else
			eval(['ret =', sys,'(t,x,u,flag);'])
		end
	else
		[ret,x0,str] = feval(sys);
	end
end
