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

% 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',[212,294,831,540])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '4')
set_param(sys,'Min step size', '0.05')
set_param(sys,'Max step size', '0.05')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   't')
set_param(sys,'Load callback','nndatcs');

add_block('built-in/Gain',[sys,'/',['radians to ',13,'degrees']])
set_param([sys,'/',['radians to ',13,'degrees']],...
		'Gain','180/pi',...
		'position',[495,51,550,89])


%     Subsystem  ['Nonlinear',13,'Antenna',13,'Model'].

new_system([sys,'/',['Nonlinear',13,'Antenna',13,'Model']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],'Location',[221,349,841,541])

add_block('built-in/Note',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/ThetaDot',13,'(omega)']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/ThetaDot',13,'(omega)']],...
		'position',[480,45,485,50])

add_block('built-in/Integrator',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/Integrator1']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/Integrator1']],...
		'Initial','pi/18',...
		'position',[510,70,530,90])

add_block('built-in/Integrator',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/Integrator']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/Integrator']],...
		'position',[415,70,435,90])

add_block('built-in/Fcn',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/Fcn']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/Fcn']],...
		'Expr','10*sin(u[2]) -2*u[3] +u[1]',...
		'position',[130,67,350,93])

add_block('built-in/Mux',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/Mux']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/Mux']],...
		'inputs','3',...
		'position',[70,62,105,98])

add_block('built-in/Inport',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/in_1']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/in_1']],...
		'position',[15,60,35,80])

add_block('built-in/Outport',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/out_1']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/out_1']],...
		'position',[585,70,605,90])

add_block('built-in/Outport',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/out_2']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/out_2']],...
		'Port','2',...
		'position',[585,115,605,135])

add_block('built-in/Note',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/ThetaDDot',13,'(alpha)']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/ThetaDDot',13,'(alpha)']],...
		'position',[385,45,390,50])

add_block('built-in/Note',[sys,'/',['Nonlinear',13,'Antenna',13,'Model/Theta']])
set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model/Theta']],...
		'position',[551,54,569,61])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[535,80;580,80])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[535,80;540,80;540,20;45,20;45,80;65,80])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[440,80;505,80])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[460,80;460,120;50,120;50,90;65,90])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[110,80;125,80])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[355,80;410,80])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[40,70;65,70])
add_line([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],[440,80;480,80;480,125;580,125])


%     Finished composite block ['Nonlinear',13,'Antenna',13,'Model'].

set_param([sys,'/',['Nonlinear',13,'Antenna',13,'Model']],...
		'position',[385,127,415,178])

add_block('built-in/Note',[sys,'/','Theta'])
set_param([sys,'/','Theta'],...
		'position',[431,116,440,122])

add_block('built-in/Note',[sys,'/','ThetaDot'])
set_param([sys,'/','ThetaDot'],...
		'position',[440,145,445,150])

add_block('built-in/Mux',[sys,'/','Mux1'])
set_param([sys,'/','Mux1'],...
		'inputs','2',...
		'position',[510,126,540,179])

add_block('built-in/Note',[sys,'/','u'])
set_param([sys,'/','u'],...
		'position',[360,129,370,134])

add_block('built-in/Zero-Order Hold',[sys,'/',['Zero-Order',13,'Hold']])
set_param([sys,'/',['Zero-Order',13,'Hold']],...
		'Sample time','Ts',...
		'position',[45,134,80,166])

add_block('built-in/Fcn',[sys,'/','Fcn1'])
set_param([sys,'/','Fcn1'],...
		'Expr','9*u[1] -9*u[3] -6*u[4] +(u[6]-u[2])/Ts',...
		'position',[315,145,355,165])

add_block('built-in/Constant',[sys,'/',['Reference Signal',13,'(in radians)']])
set_param([sys,'/',['Reference Signal',13,'(in radians)']],...
		'Value','pi/2',...
		'position',[100,48,135,72])

add_block('built-in/Note',[sys,'/','Neural Net controller'])
set_param([sys,'/','Neural Net controller'],...
		'position',[160,100,165,105])

add_block('built-in/Mux',[sys,'/','Mux2'])
set_param([sys,'/','Mux2'],...
		'inputs','[1 1 2 2]',...
		'position',[265,137,300,173])


%     Subsystem  'tansig'.

new_system([sys,'/','tansig'])
set_param([sys,'/','tansig'],'Location',[215,502,546,725])

add_block('built-in/Constant',[sys,'/','tansig/Bias'])
set_param([sys,'/','tansig/Bias'],...
		'Value','b',...
		'position',[60,155,80,175])

add_block('built-in/Sum',[sys,'/','tansig/Sum'])
set_param([sys,'/','tansig/Sum'],...
		'position',[150,100,170,120])

add_block('built-in/State-Space',[sys,'/','tansig/Weight'])
set_param([sys,'/','tansig/Weight'],...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','W',...
		'Mask Type','Matrix Gain',...
		'Mask Dialogue','Matrix Gain.|Gain matrix:',...
		'Mask Translate','K = @1;')
set_param([sys,'/','tansig/Weight'],...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','W\/',...
		'position',[60,91,85,119])

add_block('built-in/Inport',[sys,'/','tansig/in_1'])
set_param([sys,'/','tansig/in_1'],...
		'position',[15,95,35,115])

add_block('built-in/Outport',[sys,'/','tansig/out_1'])
set_param([sys,'/','tansig/out_1'],...
		'position',[275,100,295,120])

add_block('built-in/S-Function',[sys,'/','tansig/tansig'])
set_param([sys,'/','tansig/tansig'],...
		'function name','tansigc',...
		'position',[200,100,250,120])
add_line([sys,'/','tansig'],[85,165;110,165;110,115;145,115])
add_line([sys,'/','tansig'],[90,105;145,105])
add_line([sys,'/','tansig'],[40,105;55,105])
add_line([sys,'/','tansig'],[255,110;270,110])
add_line([sys,'/','tansig'],[175,110;195,110])
set_param([sys,'/','tansig'],...
		'Mask Display','plot(0,0,100,100,[80,20],[90,70],[80,20],[50,50],[80,20],[10,30],[80,20],[50,30],[80,21],[90,30],[80,20],[10,50],[80,21],[91,50],[80,20],[50,70],[80,20],[10,70])',...
		'Mask Type','Neuron layer')
set_param([sys,'/','tansig'],...
		'Mask Dialogue','Tansig neuron layer|Weight:|Bias:',...
		'Mask Translate','W=@1; b=@2;',...
		'Mask Help','Implements tansig(W*p,b) where W is the Weight, b is the Bias, and p is the input to the block.')
set_param([sys,'/','tansig'],...
		'Mask Entries','W1\/B1\/')


%     Finished composite block 'tansig'.

set_param([sys,'/','tansig'],...
		'position',[125,125,155,175])


%     Subsystem  'purelin'.

new_system([sys,'/','purelin'])
set_param([sys,'/','purelin'],'Location',[215,502,546,725])

add_block('built-in/Outport',[sys,'/','purelin/out_1'])
set_param([sys,'/','purelin/out_1'],...
		'position',[275,100,295,120])

add_block('built-in/Inport',[sys,'/','purelin/in_1'])
set_param([sys,'/','purelin/in_1'],...
		'position',[15,95,35,115])

add_block('built-in/State-Space',[sys,'/','purelin/Weight'])
set_param([sys,'/','purelin/Weight'],...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','W',...
		'Mask Type','Matrix Gain',...
		'Mask Dialogue','Matrix Gain.|Gain matrix:',...
		'Mask Translate','K = @1;')
set_param([sys,'/','purelin/Weight'],...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','W\/',...
		'position',[60,91,85,119])

add_block('built-in/Sum',[sys,'/','purelin/Sum'])
set_param([sys,'/','purelin/Sum'],...
		'position',[150,100,170,120])

add_block('built-in/Constant',[sys,'/','purelin/Bias'])
set_param([sys,'/','purelin/Bias'],...
		'Value','b',...
		'position',[60,155,80,175])
add_line([sys,'/','purelin'],[175,110;270,110])
add_line([sys,'/','purelin'],[40,105;55,105])
add_line([sys,'/','purelin'],[90,105;145,105])
add_line([sys,'/','purelin'],[85,165;110,165;110,115;145,115])
set_param([sys,'/','purelin'],...
		'Mask Display','plot(0,0,100,100,[80,20],[90,70],[80,20],[50,50],[80,20],[10,30],[80,20],[50,30],[80,21],[90,30],[80,20],[10,50],[80,21],[91,50],[80,20],[50,70],[80,20],[10,70])',...
		'Mask Type','Neuron layer')
set_param([sys,'/','purelin'],...
		'Mask Dialogue','Purelin neuron layer|Weight:|Bias:',...
		'Mask Translate','W=@1; b=@2;',...
		'Mask Help','Implements purelin(W*p,b) where W is the Weight, b is the Bias, and p is the input to the block.')
set_param([sys,'/','purelin'],...
		'Mask Entries','W2\/B2\/')


%     Finished composite block 'purelin'.

set_param([sys,'/','purelin'],...
		'position',[170,125,200,175])

add_block('built-in/Note',[sys,'/',['Neural Network Control Design example from Neural Network Toolbox User''s Guide.']])
set_param([sys,'/',['Neural Network Control Design example from Neural Network Toolbox User''s Guide.']],...
		'position',[320,10,325,15])


%     Subsystem  ['Double click here',13,'to start optimizing',13,'Matrix Gain, FF Gain, and I Gain. '].

new_system([sys,'/',['Double click here',13,'to start optimizing',13,'Matrix Gain, FF Gain, and I Gain. ']])
set_param([sys,'/',['Double click here',13,'to start optimizing',13,'Matrix Gain, FF Gain, and I Gain. ']],'Location',[-10,380,117,533])
set_param([sys,'/',['Double click here',13,'to start optimizing',13,'Matrix Gain, FF Gain, and I Gain. ']],...
		'Mask Display','Reload\nNeural Net\nController',...
		'Mask Dialogue','eval(''nndatcs'')')


%     Finished composite block ['Double click here',13,'to start optimizing',13,'Matrix Gain, FF Gain, and I Gain. '].

set_param([sys,'/',['Double click here',13,'to start optimizing',13,'Matrix Gain, FF Gain, and I Gain. ']],...
		'hide name',0,...
		'position',[287,49,384,87])

add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'Vgain','100.000000',...
		'Hgain','5.000000',...
		'Vmax','200.000000',...
		'Hmax','10.000000',...
		'Window',[411,702,691,922])
open_system([sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'position',[570,57,590,83])
add_line(sys,[420,165;505,165])
add_line(sys,[555,70;565,70])
add_line(sys,[160,150;165,150])
add_line(sys,[205,150;260,150])
add_line(sys,[305,155;310,155])
add_line(sys,[140,60;230,60;230,140;260,140])
add_line(sys,[545,155;550,155;550,220;15,220;15,150;40,150])
add_line(sys,[85,150;120,150])
add_line(sys,[105,150;105,200;225,200;225,160;260,160])
add_line(sys,[225,170;260,170])
add_line(sys,[420,140;505,140])
add_line(sys,[480,140;490,70])
add_line(sys,[360,155;380,155])

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
