function [ret,x0,str,ts,xts]=s3_18a(t,x,u,flag);
%S3_18A	is the M-file description of the SIMULINK system named S3_18A.
%	The block-diagram can be displayed by typing: S3_18A.
%
%	SYS=S3_18A(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 S3_18A 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 S3_18A with a FLAG of zero:
%	[SIZES]=S3_18A([],[],[],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,42,544,397])
     open_system(sys)
end;
set_param(sys,'algorithm',     'Euler')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     't_d')
set_param(sys,'Min step size', 'Tc')
set_param(sys,'Max step size', 'Tc')
set_param(sys,'Relative error','1e-6')
set_param(sys,'Return vars',   '')


%     Subsystem  'Subsystem2'.

new_system([sys,'/','Subsystem2'])
set_param([sys,'/','Subsystem2'],'Location',[355,393414,500,393509])

add_block('built-in/Note',[sys,'/','Subsystem2/start'])
set_param([sys,'/','Subsystem2/start'],...
		'position',[55,45,60,50])
set_param([sys,'/','Subsystem2'],...
		'Mask Display','variables\n initialization',...
		'Mask Dialogue','eval(''clear all;i3_18;'')')


%     Finished composite block 'Subsystem2'.

set_param([sys,'/','Subsystem2'],...
		'hide name',0,...
		'Font Name','Arial',...
		'Drop Shadow',4,...
		'position',[10,7,125,66])

add_block('built-in/From Workspace',[sys,'/',['From',13,'Workspace']])
set_param([sys,'/',['From',13,'Workspace']],...
		'hide name',0,...
		'Font Name','Arial',...
		'matl_expr','[T,dx_d]',...
		'position',[10,122,60,148])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','+-',...
		'position',[90,159,110,186])

add_block('built-in/From Workspace',[sys,'/',['From',13,'Workspace1']])
set_param([sys,'/',['From',13,'Workspace1']],...
		'hide name',0,...
		'Font Name','Arial',...
		'matl_expr','[T,x_d]',...
		'position',[10,153,60,177])

add_block('built-in/State-Space',[sys,'/',['Matrix',13,'Gain']])
set_param([sys,'/',['Matrix',13,'Gain']],...
		'hide name',0,...
		'Font Name','Arial',...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','K',...
		'Mask Type','Matrix Gain')
set_param([sys,'/',['Matrix',13,'Gain']],...
		'Mask Dialogue','Matrix Gain.|Gain matrix:',...
		'Mask Translate','K = @1;',...
		'Mask Help','Multiplies input vector by entered matrix to produce output vector (y=Au).',...
		'Mask Entries','K\/')
set_param([sys,'/',['Matrix',13,'Gain']],...
		'position',[140,158,175,192])

add_block('built-in/To Workspace',[sys,'/','To Workspace6'])
set_param([sys,'/','To Workspace6'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','e',...
		'buffer','[2501,1,Ts]',...
		'position',[205,85,255,105])


%     Subsystem  ['Jacobian',13,'inverse'].

new_system([sys,'/',['Jacobian',13,'inverse']])
set_param([sys,'/',['Jacobian',13,'inverse']],'Location',[183,307,460,413])

add_block('built-in/Mux',[sys,'/',['Jacobian',13,'inverse/Mux2']])
set_param([sys,'/',['Jacobian',13,'inverse/Mux2']],...
		'hide name',0,...
		'inputs','[4,4]',...
		'position',[110,18,140,67])

add_block('built-in/MATLAB Fcn',[sys,'/',['Jacobian',13,'inverse/MATLAB Fcn']])
set_param([sys,'/',['Jacobian',13,'inverse/MATLAB Fcn']],...
		'hide name',0,...
		'MATLAB Fcn','invJs_a',...
		'Output Width','4',...
		'Mask Display','invJ_a',...
		'position',[165,30,215,60])

add_block('built-in/Outport',[sys,'/',['Jacobian',13,'inverse/dq']])
set_param([sys,'/',['Jacobian',13,'inverse/dq']],...
		'position',[245,35,265,55])

add_block('built-in/Inport',[sys,'/',['Jacobian',13,'inverse/cs']])
set_param([sys,'/',['Jacobian',13,'inverse/cs']],...
		'Port','2',...
		'position',[60,45,80,65])

add_block('built-in/Inport',[sys,'/',['Jacobian',13,'inverse/v']])
set_param([sys,'/',['Jacobian',13,'inverse/v']],...
		'position',[30,20,50,40])
add_line([sys,'/',['Jacobian',13,'inverse']],[85,55;105,55])
add_line([sys,'/',['Jacobian',13,'inverse']],[220,45;240,45])
add_line([sys,'/',['Jacobian',13,'inverse']],[55,30;105,30])
add_line([sys,'/',['Jacobian',13,'inverse']],[145,45;160,45])
set_param([sys,'/',['Jacobian',13,'inverse']],...
		'Mask Display','inv(J_a(q))dx')


%     Finished composite block ['Jacobian',13,'inverse'].

set_param([sys,'/',['Jacobian',13,'inverse']],...
		'move name',0,...
		'Font Name','Arial',...
		'position',[265,159,340,201])

add_block('built-in/Sum',[sys,'/','Sum1'])
set_param([sys,'/','Sum1'],...
		'hide name',0,...
		'Font Name','Arial',...
		'position',[205,154,225,181])


%     Subsystem  ['direct',13,'kinematics'].

new_system([sys,'/',['direct',13,'kinematics']])
set_param([sys,'/',['direct',13,'kinematics']],'Location',[210,119,563,367])

add_block('built-in/Note',[sys,'/',['direct',13,'kinematics/y']])
set_param([sys,'/',['direct',13,'kinematics/y']],...
		'position',[185,85,190,90])

add_block('built-in/Note',[sys,'/',['direct',13,'kinematics/x']])
set_param([sys,'/',['direct',13,'kinematics/x']],...
		'position',[185,35,190,40])

add_block('built-in/Demux',[sys,'/',['direct',13,'kinematics/Demux']])
set_param([sys,'/',['direct',13,'kinematics/Demux']],...
		'hide name',0,...
		'position',[70,28,110,127])

add_block('built-in/Inport',[sys,'/',['direct',13,'kinematics/cs']])
set_param([sys,'/',['direct',13,'kinematics/cs']],...
		'position',[10,70,30,90])

add_block('built-in/Sum',[sys,'/',['direct',13,'kinematics/Sum']])
set_param([sys,'/',['direct',13,'kinematics/Sum']],...
		'hide name',0,...
		'position',[130,29,145,76])

add_block('built-in/Note',[sys,'/',['direct',13,'kinematics/z']])
set_param([sys,'/',['direct',13,'kinematics/z']],...
		'position',[185,140,190,146])

add_block('built-in/Demux',[sys,'/',['direct',13,'kinematics/Demux1']])
set_param([sys,'/',['direct',13,'kinematics/Demux1']],...
		'hide name',0,...
		'position',[70,171,115,234])

add_block('built-in/Sum',[sys,'/',['direct',13,'kinematics/Sum3']])
set_param([sys,'/',['direct',13,'kinematics/Sum3']],...
		'hide name',0,...
		'inputs','+++',...
		'position',[180,169,195,221])

add_block('built-in/Mux',[sys,'/',['direct',13,'kinematics/Mux']])
set_param([sys,'/',['direct',13,'kinematics/Mux']],...
		'hide name',0,...
		'position',[240,80,275,145])

add_block('built-in/Outport',[sys,'/',['direct',13,'kinematics/(x,y,z,phi)']])
set_param([sys,'/',['direct',13,'kinematics/(x,y,z,phi)']],...
		'position',[305,105,325,125])

add_block('built-in/Note',[sys,'/',['direct',13,'kinematics/phi',13,'']])
set_param([sys,'/',['direct',13,'kinematics/phi',13,'']],...
		'position',[220,155,235,163])

add_block('built-in/Inport',[sys,'/',['direct',13,'kinematics/q']])
set_param([sys,'/',['direct',13,'kinematics/q']],...
		'Port','2',...
		'position',[10,195,30,215])

add_block('built-in/Sum',[sys,'/',['direct',13,'kinematics/Sum2']])
set_param([sys,'/',['direct',13,'kinematics/Sum2']],...
		'hide name',0,...
		'position',[155,78,170,127])
add_line([sys,'/',['direct',13,'kinematics']],[175,105;235,105])
add_line([sys,'/',['direct',13,'kinematics']],[35,205;65,205])
add_line([sys,'/',['direct',13,'kinematics']],[115,65;125,65])
add_line([sys,'/',['direct',13,'kinematics']],[280,115;300,115])
add_line([sys,'/',['direct',13,'kinematics']],[150,55;200,55;200,90;235,90])
add_line([sys,'/',['direct',13,'kinematics']],[115,40;125,40])
add_line([sys,'/',['direct',13,'kinematics']],[35,80;65,80])
add_line([sys,'/',['direct',13,'kinematics']],[115,90;150,90])
add_line([sys,'/',['direct',13,'kinematics']],[115,115;150,115])
add_line([sys,'/',['direct',13,'kinematics']],[120,195;175,195])
add_line([sys,'/',['direct',13,'kinematics']],[120,180;175,180])
add_line([sys,'/',['direct',13,'kinematics']],[120,225;150,225;150,210;175,210])
add_line([sys,'/',['direct',13,'kinematics']],[120,210;135,210;135,160;205,160;205,120;235,120])
add_line([sys,'/',['direct',13,'kinematics']],[200,195;215,195;215,135;235,135])
set_param([sys,'/',['direct',13,'kinematics']],...
		'Mask Display','k(q)')


%     Finished composite block ['direct',13,'kinematics'].

set_param([sys,'/',['direct',13,'kinematics']],...
		'orientation',2,...
		'move name',0,...
		'Font Name','Arial',...
		'position',[140,244,180,291])

add_block('built-in/To Workspace',[sys,'/','To Workspace4'])
set_param([sys,'/','To Workspace4'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','time',...
		'buffer','[2501,1,Ts]',...
		'position',[465,10,515,30])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'hide name',0,...
		'Font Name','Arial',...
		'position',[410,10,430,30])

add_block('built-in/To Workspace',[sys,'/','To Workspace7'])
set_param([sys,'/','To Workspace7'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','dq',...
		'buffer','[2501,1,Ts]',...
		'position',[465,85,515,105])


%     Subsystem  ['Discrete-Time',13,'Integrator'].

new_system([sys,'/',['Discrete-Time',13,'Integrator']])
set_param([sys,'/',['Discrete-Time',13,'Integrator']],'Location',[392,641,765,859])

add_block('built-in/Inport',[sys,'/',['Discrete-Time',13,'Integrator/in_1']])
set_param([sys,'/',['Discrete-Time',13,'Integrator/in_1']],...
		'position',[25,70,45,90])

add_block('built-in/Sum',[sys,'/',['Discrete-Time',13,'Integrator/Sum']])
set_param([sys,'/',['Discrete-Time',13,'Integrator/Sum']],...
		'position',[150,63,180,127])

add_block('built-in/Unit Delay',[sys,'/',['Discrete-Time',13,'Integrator/Unit Delay']])
set_param([sys,'/',['Discrete-Time',13,'Integrator/Unit Delay']],...
		'Sample time','Ts',...
		'x0','X0',...
		'position',[210,85,260,105])

add_block('built-in/Gain',[sys,'/',['Discrete-Time',13,'Integrator/Gain']])
set_param([sys,'/',['Discrete-Time',13,'Integrator/Gain']],...
		'Gain','Ts',...
		'position',[80,61,110,99])

add_block('built-in/Outport',[sys,'/',['Discrete-Time',13,'Integrator/out_1']])
set_param([sys,'/',['Discrete-Time',13,'Integrator/out_1']],...
		'position',[320,85,340,105])
add_line([sys,'/',['Discrete-Time',13,'Integrator']],[115,80;145,80])
add_line([sys,'/',['Discrete-Time',13,'Integrator']],[50,80;75,80])
add_line([sys,'/',['Discrete-Time',13,'Integrator']],[185,95;205,95])
add_line([sys,'/',['Discrete-Time',13,'Integrator']],[265,95;315,95])
add_line([sys,'/',['Discrete-Time',13,'Integrator']],[285,95;285,165;120,165;120,110;145,110])
set_param([sys,'/',['Discrete-Time',13,'Integrator']],...
		'Mask Display','dpoly(Ts*[1 0],[1 -1],''z'')',...
		'Mask Type','Discrete-Time Integrator',...
		'Mask Dialogue','Discrete-Time Integrator:|Initial Condition:|Sample Time:')
set_param([sys,'/',['Discrete-Time',13,'Integrator']],...
		'Mask Translate','X0=@1;Ts=@2;',...
		'Mask Help','Implements a zeroth order discrete\nintegration using a gain, a sum, and\na unit delay. Inputs may be scalar\nor vector.\n')
set_param([sys,'/',['Discrete-Time',13,'Integrator']],...
		'Mask Entries','q_i\/Tc\/')


%     Finished composite block ['Discrete-Time',13,'Integrator'].

set_param([sys,'/',['Discrete-Time',13,'Integrator']],...
		'hide name',0,...
		'Font Name','Arial',...
		'position',[370,162,410,198])

add_block('built-in/To Workspace',[sys,'/','To Workspace5'])
set_param([sys,'/','To Workspace5'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','q',...
		'buffer','[2501,1,Ts]',...
		'position',[465,170,515,190])


%     Subsystem  'Subsystem8'.

new_system([sys,'/','Subsystem8'])
set_param([sys,'/','Subsystem8'],'Location',[355,393414,500,393509])

add_block('built-in/Note',[sys,'/','Subsystem8/start'])
set_param([sys,'/','Subsystem8/start'],...
		'position',[55,45,60,50])
set_param([sys,'/','Subsystem8'],...
		'Mask Display','plot',...
		'Mask Dialogue','eval(''p3_18a;'')')


%     Finished composite block 'Subsystem8'.

set_param([sys,'/','Subsystem8'],...
		'orientation',2,...
		'hide name',0,...
		'Font Name','Arial',...
		'Drop Shadow',4,...
		'position',[445,305,515,336])


%     Subsystem  ['sinusoidal ',13,'functions'].

new_system([sys,'/',['sinusoidal ',13,'functions']])
set_param([sys,'/',['sinusoidal ',13,'functions']],'Location',[78,74,525,234])

add_block('built-in/Demux',[sys,'/',['sinusoidal ',13,'functions/Demux']])
set_param([sys,'/',['sinusoidal ',13,'functions/Demux']],...
		'hide name',0,...
		'outputs','[1,1,2]',...
		'position',[60,99,100,131])

add_block('built-in/Sum',[sys,'/',['sinusoidal ',13,'functions/Sum2']])
set_param([sys,'/',['sinusoidal ',13,'functions/Sum2']],...
		'hide name',0,...
		'position',[130,99,145,121])

add_block('built-in/Note',[sys,'/',['sinusoidal ',13,'functions/q1 + q2']])
set_param([sys,'/',['sinusoidal ',13,'functions/q1 + q2']],...
		'position',[175,90,180,96])

add_block('built-in/Fcn',[sys,'/',['sinusoidal ',13,'functions/Fcn4']])
set_param([sys,'/',['sinusoidal ',13,'functions/Fcn4']],...
		'hide name',0,...
		'Expr','a(2)*sin(u)',...
		'Mask Display','',...
		'position',[250,99,320,121])

add_block('built-in/Fcn',[sys,'/',['sinusoidal ',13,'functions/Fcn']])
set_param([sys,'/',['sinusoidal ',13,'functions/Fcn']],...
		'hide name',0,...
		'Expr','a(1)*cos(u)',...
		'Mask Display','',...
		'position',[250,24,320,46])

add_block('built-in/Fcn',[sys,'/',['sinusoidal ',13,'functions/Fcn3']])
set_param([sys,'/',['sinusoidal ',13,'functions/Fcn3']],...
		'hide name',0,...
		'Expr','a(1)*sin(u)',...
		'Mask Display','',...
		'position',[250,74,320,96])

add_block('built-in/Fcn',[sys,'/',['sinusoidal ',13,'functions/Fcn1']])
set_param([sys,'/',['sinusoidal ',13,'functions/Fcn1']],...
		'hide name',0,...
		'Expr','a(2)*cos(u)',...
		'position',[250,49,320,71])

add_block('built-in/Outport',[sys,'/',['sinusoidal ',13,'functions/cs']])
set_param([sys,'/',['sinusoidal ',13,'functions/cs']],...
		'position',[400,65,420,85])

add_block('built-in/Mux',[sys,'/',['sinusoidal ',13,'functions/Mux']])
set_param([sys,'/',['sinusoidal ',13,'functions/Mux']],...
		'hide name',0,...
		'position',[350,18,375,127])

add_block('built-in/Inport',[sys,'/',['sinusoidal ',13,'functions/q']])
set_param([sys,'/',['sinusoidal ',13,'functions/q']],...
		'position',[15,105,35,125])
add_line([sys,'/',['sinusoidal ',13,'functions']],[40,115;55,115])
add_line([sys,'/',['sinusoidal ',13,'functions']],[105,115;125,115])
add_line([sys,'/',['sinusoidal ',13,'functions']],[105,105;125,105])
add_line([sys,'/',['sinusoidal ',13,'functions']],[380,75;395,75])
add_line([sys,'/',['sinusoidal ',13,'functions']],[325,60;345,60])
add_line([sys,'/',['sinusoidal ',13,'functions']],[325,35;345,35])
add_line([sys,'/',['sinusoidal ',13,'functions']],[325,85;345,85])
add_line([sys,'/',['sinusoidal ',13,'functions']],[325,110;345,110])
add_line([sys,'/',['sinusoidal ',13,'functions']],[150,110;210,110;210,60;245,60])
add_line([sys,'/',['sinusoidal ',13,'functions']],[210,110;245,110])
add_line([sys,'/',['sinusoidal ',13,'functions']],[105,105;110,105;110,85;245,85])
add_line([sys,'/',['sinusoidal ',13,'functions']],[110,85;110,35;245,35])
set_param([sys,'/',['sinusoidal ',13,'functions']],...
		'Mask Display','cs(q)')


%     Finished composite block ['sinusoidal ',13,'functions'].

set_param([sys,'/',['sinusoidal ',13,'functions']],...
		'orientation',2,...
		'move name',0,...
		'Font Name','Arial',...
		'position',[280,235,320,275])
add_line(sys,[115,175;135,175])
add_line(sys,[65,165;85,165])
add_line(sys,[435,20;460,20])
add_line(sys,[180,175;200,175])
add_line(sys,[415,180;460,180])
add_line(sys,[345,180;365,180])
add_line(sys,[275,255;185,255])
add_line(sys,[135,270;70,270;70,180;85,180])
add_line(sys,[240,255;240,190;260,190])
add_line(sys,[230,170;260,170])
add_line(sys,[115,175;120,175;120,95;200,95])
add_line(sys,[65,135;180,135;180,160;200,160])
add_line(sys,[355,180;355,95;460,95])
add_line(sys,[430,180;430,280;185,280])
add_line(sys,[430,255;325,255])

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
