function [ret,x0,str]=musyndm2(t,x,u,flag);
%MUSYNDM2	is the M-file description of the SIMULINK system named MUSYNDM2.
%	The block-diagram can be displayed by typing: MUSYNDM2.
%
%	SYS=MUSYNDM2(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 MUSYNDM2 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 MUSYNDM2 with a FLAG of zero:
%	[SIZES]=MUSYNDM2([],[],[],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',[24,105,678,442])
     open_system(sys)
end;
set_param(sys,'algorithm',		'Linear')
set_param(sys,'Start time',	'0.0')
set_param(sys,'Stop time',		'9999')
set_param(sys,'Min step size',	'0.05')
set_param(sys,'Max step size',	'0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',	'')

add_block('built-in/Sum',[sys,'/','Sum4'])
set_param([sys,'/','Sum4'],...
		'orientation',1,...
		'position',[455,205,475,225])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'position',[310,135,330,155])

add_block('built-in/Product',[sys,'/','Product'])
set_param([sys,'/','Product'],...
		'position',[255,40,280,60])

add_block('built-in/Signal Generator',[sys,'/','Signal Gen.'])
set_param([sys,'/','Signal Gen.'],...
		'Peak','2.000000',...
		'Peak Range','10.000000',...
		'Freq','1.000000',...
		'Freq Range','5.000000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[20,78,65,112])

add_block('built-in/Inport',[sys,'/','Inport2'])
set_param([sys,'/','Inport2'],...
		'position',[25,140,45,160])

add_block('built-in/State-space',[sys,'/','controller'])
set_param([sys,'/','controller'],...
		'A','ak',...
		'B','bk',...
		'C','ck',...
		'D','dk',...
		'Mask Display','H_infinity\nController',...
		'Mask Type','H_infty Controller',...
		'Mask Dialogue','H_infty Controller:|ak:|bk:|ck:|dk:')
set_param([sys,'/','controller'],...
		'Mask Translate','ak=@1;bk=@2;ck=@3;dk=@4;')
set_param([sys,'/','controller'],...
		'Mask Help','. Mask and unmask this block to see how it works.Usinf Mu Analysis and Synthesis Toolbox to design a H_infinity Controller. Change the parameters, see the designed system.')
set_param([sys,'/','controller'],...
		'Mask Entries','ak\/bk\/ck\/dk\/',...
		'position',[170,131,245,169])

add_block('built-in/Outport',[sys,'/','Outport'])
set_param([sys,'/','Outport'],...
		'position',[535,61,565,79])


%     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/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_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/Outport',[sys,'/',['Sensor',13,'Noise/out_1']])
set_param([sys,'/',['Sensor',13,'Noise/out_1']],...
		'position',[235,70,255,90])
add_line([sys,'/',['Sensor',13,'Noise']],[80,80;130,80])
add_line([sys,'/',['Sensor',13,'Noise']],[210,80;225,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',[525,165,555,195])

add_block('built-in/Outport',[sys,'/','Outport1'])
set_param([sys,'/','Outport1'],...
		'Port','2',...
		'position',[600,231,630,249])

add_block('built-in/State-space',[sys,'/','plant'])
set_param([sys,'/','plant'],...
		'A','a',...
		'B','b',...
		'C','c',...
		'D','d',...
		'Mask Display','plant\nmodel',...
		'Mask Type','plant',...
		'Mask Dialogue','state space model:|a: |b: |c: |d:')
set_param([sys,'/','plant'],...
		'Mask Translate','a=@1; b=@2; c=@3; d=@4;',...
		'Mask Help','system plant',...
		'Mask Entries','a\/b\/c\/d\/',...
		'position',[355,126,430,164])

add_block('built-in/Sum',[sys,'/','Sum2'])
set_param([sys,'/','Sum2'],...
		'inputs','-++',...
		'position',[115,132,135,168])

add_block('built-in/State-space',[sys,'/','perf. weighting'])
set_param([sys,'/','perf. weighting'],...
		'A','ap',...
		'B','bp',...
		'C','cp',...
		'D','dp',...
		'Mask Display','output\nweighting.',...
		'Mask Type','Performance weighting function')
set_param([sys,'/','perf. weighting'],...
		'Mask Dialogue','Performance weighting function:|numerator:|denominator:',...
		'Mask Translate','[ap,bp,cp,dp]=tf2ss(@1,@2);',...
		'Mask Help','This is the weighting function of the plant model.')
set_param([sys,'/','perf. weighting'],...
		'Mask Entries','num_o\/den_o\/',...
		'position',[495,221,570,259])

add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'Vgain','4.000000',...
		'Hgain','10.000000',...
		'Vmax','40.000000',...
		'Hmax','20.000000',...
		'Window',[577,194,936,349],...
		'position',[575,132,595,158])


%     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-Load\nData',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],...
		'Mask Dialogue','eval(''if ~exist(''''mu''''),fprintf(''''\nMust be licensed for MuSyn Toolbox\n''''), else, fprintf(''''\nLoading Data\nWarning: New data will overlap the original working data\n>>\n''''); mudata2; 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',[10,284,84,326])


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

new_system([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design2']])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design2']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design2']],...
		'Mask Display','Re-design',...
		'Mask Type','')
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design2']],...
		'Mask Dialogue','eval(''if ~exist(''''a''''),fprintf(''''\nMust load data first\n''''), else, fprintf(''''\nCtrl_C to abort MuSyn Calculation\n\n''''); mudes2; end'')')
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design2']],...
		'Mask Translate','',...
		'Mask Help','')


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

set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design2']],...
		'hide name',0,...
		'position',[99,285,168,325])


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

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


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

set_param([sys,'/',['Double click here',13,'to show bode plot',13,'of closed-loop4']],...
		'hide name',0,...
		'position',[184,285,266,324])


%     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(''''k1''''),fprintf(''''\nMust Load Data & Design First\n''''),else [x,y,z,w]=unpck(k1); [x,y,z]=bode(x,y,z,w); clg; subplot(211); loglog(z,x(:,1)); subplot(212); semilogx(z,y(:,1)); 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',[290,284,366,322])


%     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(''''g1''''), printf(''''Must Load Data First''''), else, clg, [x,y,z,w]=unpck(g1); nyquist(x,y,z,w); grid; 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',[380,285,461,322])


%     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(''''k1''''), printf(''''Must Load Data & Desgin First''''), else,clg,plot(1:10), [x,y,z,w]=unpck(k1); clg, nyquist(x,y,z,w), end'')')
set_param([sys,'/',['Double click here',13,'to show zero-pole',13,'plot of controller']],...
		'Mask Translate','',...
		'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',[475,285,544,323])


%     Subsystem  ['About the musyn',13,'demo1'].

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


%     Finished composite block ['About the musyn',13,'demo1'].

set_param([sys,'/',['About the musyn',13,'demo1']],...
		'hide name',0,...
		'position',[567,288,619,323])

add_block('built-in/State-space',[sys,'/','pertu. weighting'])
set_param([sys,'/','pertu. weighting'],...
		'A','ad',...
		'B','bd',...
		'C','cd',...
		'D','dd',...
		'Mask Display','input\nweighting.',...
		'Mask Type','Performance weighting function')
set_param([sys,'/','pertu. weighting'],...
		'Mask Dialogue','Performance weighting function:|numerator:|denominator:',...
		'Mask Translate','[ad,bd,cd,dd]=tf2ss(@1,@2);',...
		'Mask Help','This is the weighting function of the plant model.')
set_param([sys,'/','pertu. weighting'],...
		'Mask Entries','num_i\/den_i\/',...
		'position',[155,71,230,109])


%     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/Outport',[sys,'/',['multiplicative',13,'noise/out_1']])
set_param([sys,'/',['multiplicative',13,'noise/out_1']],...
		'position',[235,70,255,90])

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/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_line([sys,'/',['multiplicative',13,'noise']],[210,80;225,80])
add_line([sys,'/',['multiplicative',13,'noise']],[80,80;130,80])
set_param([sys,'/',['multiplicative',13,'noise']],...
		'Mask Display','plot(t(:),r2(:))',...
		'Mask Type','Continuous White 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; r2 = [r(1),r;r,r(12)]; t =[1:13;1:13];')
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\/68932234\/')


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

set_param([sys,'/',['multiplicative',13,'noise']],...
		'position',[95,32,135,58])
add_line(sys,[435,145;565,145])
add_line(sys,[460,145;460,70;525,70])
add_line(sys,[460,145;460,195])
add_line(sys,[140,150;160,150])
add_line(sys,[50,150;105,150])
add_line(sys,[575,240;590,240])
add_line(sys,[235,90;235,55;245,55])
add_line(sys,[335,145;345,145])
add_line(sys,[140,45;245,45])
add_line(sys,[520,180;470,180;470,195])
add_line(sys,[70,95;85,95;85,140;105,140])
add_line(sys,[465,230;465,240;90,240;90,160;105,160])
add_line(sys,[465,240;485,240])
add_line(sys,[285,50;295,50;295,140;300,140])
add_line(sys,[250,150;300,150])
add_line(sys,[260,150;260,125;130,125;130,90;145,90])
% 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
