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

add_block('built-in/To Workspace',[sys,'/','To Workspace12'])
set_param([sys,'/','To Workspace12'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','q',...
		'buffer','[2501,1,Ts]',...
		'position',[500,170,550,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_17'')')


%     Finished composite block 'Subsystem8'.

set_param([sys,'/','Subsystem8'],...
		'orientation',2,...
		'hide name',0,...
		'Font Name','Arial',...
		'Drop Shadow',4,...
		'position',[480,295,550,326])


%     Subsystem  ['Jacobian pseudo-inverse',13,'with constraint'].

new_system([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],'Location',[255,315,561,415])

add_block('built-in/Inport',[sys,'/',['Jacobian pseudo-inverse',13,'with constraint/v']])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint/v']],...
		'Port','2',...
		'position',[70,35,90,55])

add_block('built-in/Inport',[sys,'/',['Jacobian pseudo-inverse',13,'with constraint/dq_a']])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint/dq_a']],...
		'position',[40,5,60,25])

add_block('built-in/Inport',[sys,'/',['Jacobian pseudo-inverse',13,'with constraint/cs']])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint/cs']],...
		'Port','3',...
		'position',[90,65,110,85])

add_block('built-in/Outport',[sys,'/',['Jacobian pseudo-inverse',13,'with constraint/dq']])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint/dq']],...
		'position',[260,35,280,55])

add_block('built-in/MATLAB Fcn',[sys,'/',['Jacobian pseudo-inverse',13,'with constraint/MATLAB Fcn']])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint/MATLAB Fcn']],...
		'hide name',0,...
		'MATLAB Fcn','dagcJ_p',...
		'Output Width','3',...
		'Mask Display','dagcJ_p',...
		'position',[180,30,230,60])

add_block('built-in/Mux',[sys,'/',['Jacobian pseudo-inverse',13,'with constraint/Mux2']])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint/Mux2']],...
		'hide name',0,...
		'inputs','[3,2,6]',...
		'position',[125,3,150,87])
add_line([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],[155,45;175,45])
add_line([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],[65,15;120,15])
add_line([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],[235,45;255,45])
add_line([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],[95,45;120,45])
add_line([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],[115,75;120,75])
set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],...
		'Mask Display','dag(J_p(q))dp + P(q)dq_a')


%     Finished composite block ['Jacobian pseudo-inverse',13,'with constraint'].

set_param([sys,'/',['Jacobian pseudo-inverse',13,'with constraint']],...
		'move name',0,...
		'Font Name','Arial',...
		'position',[245,159,375,201])


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

new_system([sys,'/',['sinusoidal',13,' functions']])
set_param([sys,'/',['sinusoidal',13,' functions']],'Location',[15,45,501,260])

add_block('built-in/Note',[sys,'/',['sinusoidal',13,' functions/q1 + q2 + q3']])
set_param([sys,'/',['sinusoidal',13,' functions/q1 + q2 + q3']],...
		'position',[250,160,255,165])

add_block('built-in/Demux',[sys,'/',['sinusoidal',13,' functions/Demux']])
set_param([sys,'/',['sinusoidal',13,' functions/Demux']],...
		'hide name',0,...
		'outputs','3',...
		'position',[50,157,90,193])

add_block('built-in/Note',[sys,'/',['sinusoidal',13,' functions/q1 + q2']])
set_param([sys,'/',['sinusoidal',13,' functions/q1 + q2']],...
		'position',[150,150,155,155])

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

add_block('built-in/Inport',[sys,'/',['sinusoidal',13,' functions/q']])
set_param([sys,'/',['sinusoidal',13,' functions/q']],...
		'position',[5,165,25,185])

add_block('built-in/Sum',[sys,'/',['sinusoidal',13,' functions/Sum3']])
set_param([sys,'/',['sinusoidal',13,' functions/Sum3']],...
		'hide name',0,...
		'position',[190,161,205,194])

add_block('built-in/Fcn',[sys,'/',['sinusoidal',13,' functions/Fcn5']])
set_param([sys,'/',['sinusoidal',13,' functions/Fcn5']],...
		'hide name',0,...
		'Expr','a(3)*sin(u)',...
		'Mask Display','',...
		'position',[295,169,365,191])

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',[295,139,365,161])

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',[295,49,365,71])

add_block('built-in/Fcn',[sys,'/',['sinusoidal',13,' functions/Fcn2']])
set_param([sys,'/',['sinusoidal',13,' functions/Fcn2']],...
		'hide name',0,...
		'Expr','a(3)*cos(u)',...
		'position',[295,79,365,101])

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',[295,19,365,41])

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',[295,109,365,131])

add_block('built-in/Mux',[sys,'/',['sinusoidal',13,' functions/Mux']])
set_param([sys,'/',['sinusoidal',13,' functions/Mux']],...
		'hide name',0,...
		'inputs','6',...
		'position',[385,17,410,193])

add_block('built-in/Outport',[sys,'/',['sinusoidal',13,' functions/cs']])
set_param([sys,'/',['sinusoidal',13,' functions/cs']],...
		'position',[440,95,460,115])
add_line([sys,'/',['sinusoidal',13,' functions']],[210,180;210,90;290,90])
add_line([sys,'/',['sinusoidal',13,' functions']],[95,165;95,30;290,30])
add_line([sys,'/',['sinusoidal',13,' functions']],[95,120;290,120])
add_line([sys,'/',['sinusoidal',13,' functions']],[135,170;185,170])
add_line([sys,'/',['sinusoidal',13,' functions']],[175,170;175,60;290,60])
add_line([sys,'/',['sinusoidal',13,' functions']],[175,170;175,150;290,150])
add_line([sys,'/',['sinusoidal',13,' functions']],[210,180;290,180])
add_line([sys,'/',['sinusoidal',13,' functions']],[95,185;185,185])
add_line([sys,'/',['sinusoidal',13,' functions']],[30,175;45,175])
add_line([sys,'/',['sinusoidal',13,' functions']],[95,175;110,175])
add_line([sys,'/',['sinusoidal',13,' functions']],[95,165;110,165])
add_line([sys,'/',['sinusoidal',13,' functions']],[415,105;435,105])
add_line([sys,'/',['sinusoidal',13,' functions']],[370,180;380,180])
add_line([sys,'/',['sinusoidal',13,' functions']],[370,150;380,150])
add_line([sys,'/',['sinusoidal',13,' functions']],[370,120;380,120])
add_line([sys,'/',['sinusoidal',13,' functions']],[370,90;380,90])
add_line([sys,'/',['sinusoidal',13,' functions']],[370,60;380,60])
add_line([sys,'/',['sinusoidal',13,' functions']],[370,30;380,30])
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',[425,235,465,275])


%     Subsystem  ['constraint',13,'velocity'].

new_system([sys,'/',['constraint',13,'velocity']])
set_param([sys,'/',['constraint',13,'velocity']],'Location',[4,190,610,460])

add_block('built-in/Inport',[sys,'/',['constraint',13,'velocity/cs']])
set_param([sys,'/',['constraint',13,'velocity/cs']],...
		'Font Name','Arial',...
		'position',[10,25,30,45])

add_block('built-in/Note',[sys,'/',['constraint',13,'velocity/cs(q1,q2,q3)']])
set_param([sys,'/',['constraint',13,'velocity/cs(q1,q2,q3)']],...
		'Font Name','Arial',...
		'position',[280,15,285,21])

add_block('built-in/MATLAB Fcn',[sys,'/',['constraint',13,'velocity/MATLAB Fcn5']])
set_param([sys,'/',['constraint',13,'velocity/MATLAB Fcn5']],...
		'hide name',0,...
		'Font Name','Arial',...
		'MATLAB Fcn','d_min',...
		'Output Width','1',...
		'Mask Display','d_min',...
		'position',[330,25,370,45])

add_block('built-in/Sum',[sys,'/',['constraint',13,'velocity/Sum7']])
set_param([sys,'/',['constraint',13,'velocity/Sum7']],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','-+',...
		'position',[405,74,420,96])

add_block('built-in/Mux',[sys,'/',['constraint',13,'velocity/Mux1']])
set_param([sys,'/',['constraint',13,'velocity/Mux1']],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','3',...
		'position',[455,134,485,176])

add_block('built-in/MATLAB Fcn',[sys,'/',['constraint',13,'velocity/MATLAB Fcn3']])
set_param([sys,'/',['constraint',13,'velocity/MATLAB Fcn3']],...
		'hide name',0,...
		'Font Name','Arial',...
		'MATLAB Fcn','d_min',...
		'Output Width','1',...
		'Mask Display','d_min',...
		'position',[330,230,370,250])


%     Subsystem  ['constraint',13,'velocity/q3+Dq',13,'selection'].

new_system([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']])
set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],'Location',[272,283,549,417])

add_block('built-in/Inport',[sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/cs']])
set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/cs']],...
		'position',[20,25,40,45])

add_block('built-in/Demux',[sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/Demux1']])
set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/Demux1']],...
		'hide name',0,...
		'outputs','[2,1,2,1]',...
		'position',[65,12,105,58])

add_block('built-in/Mux',[sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/Mux6']])
set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/Mux6']],...
		'hide name',0,...
		'inputs','[2,1,2,1]',...
		'position',[190,35,215,100])

add_block('built-in/Outport',[sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/out_1']])
set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/out_1']],...
		'hide name',0,...
		'position',[240,60,260,80])

add_block('built-in/Inport',[sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/cs_D']])
set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/cs_D']],...
		'Port','2',...
		'position',[20,90,40,110])

add_block('built-in/Demux',[sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/Demux2']])
set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection/Demux2']],...
		'hide name',0,...
		'outputs','[2,1,2,1]',...
		'position',[65,77,105,123])
add_line([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],[45,35;60,35])
add_line([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],[220,70;235,70])
add_line([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],[45,100;60,100])
add_line([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],[110,20;165,20;165,45;185,45])
add_line([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],[110,95;130,95;130,60;185,60])
add_line([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],[110,40;145,40;145,75;185,75])
add_line([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],[110,115;145,115;145,90;185,90])


%     Finished composite block ['constraint',13,'velocity/q3+Dq',13,'selection'].

set_param([sys,'/',['constraint',13,'velocity/q3+Dq',13,'selection']],...
		'move name',0,...
		'Font Name','Arial',...
		'position',[200,219,230,261])

add_block('built-in/Note',[sys,'/',['constraint',13,'velocity/cs(q1,q2,q3+Dq)']])
set_param([sys,'/',['constraint',13,'velocity/cs(q1,q2,q3+Dq)']],...
		'Font Name','Arial',...
		'position',[275,220,280,226])

add_block('built-in/Note',[sys,'/',['constraint',13,'velocity/cs(q1,q2+Dq,q3)']])
set_param([sys,'/',['constraint',13,'velocity/cs(q1,q2+Dq,q3)']],...
		'Font Name','Arial',...
		'position',[275,140,280,146])


%     Subsystem  ['constraint',13,'velocity/q2+Dq',13,' selection'].

new_system([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],'Location',[272,167,544,311])

add_block('built-in/Inport',[sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/cs_D']])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/cs_D']],...
		'Port','2',...
		'position',[15,95,35,115])

add_block('built-in/Demux',[sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/Demux']])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/Demux']],...
		'hide name',0,...
		'outputs','[1,2,1,2]',...
		'position',[65,25,105,75])

add_block('built-in/Inport',[sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/cs']])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/cs']],...
		'position',[15,40,35,60])

add_block('built-in/Demux',[sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/Demux1']])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/Demux1']],...
		'hide name',0,...
		'outputs','[1,2,1,2]',...
		'position',[65,80,105,130])

add_block('built-in/Mux',[sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/Mux5']])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/Mux5']],...
		'hide name',0,...
		'inputs','[1,2,1,2]',...
		'position',[175,41,200,104])

add_block('built-in/Outport',[sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/out_1']])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection/out_1']],...
		'hide name',0,...
		'position',[240,65,260,85])
add_line([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],[40,50;60,50])
add_line([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],[205,75;235,75])
add_line([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],[40,105;60,105])
add_line([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],[110,100;140,100;140,65;170,65])
add_line([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],[110,35;140,35;140,50;170,50])
add_line([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],[110,55;130,55;130,80;170,80])
add_line([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],[110,120;155,120;155,95;170,95])
set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],...
		'Mask Display','')


%     Finished composite block ['constraint',13,'velocity/q2+Dq',13,' selection'].

set_param([sys,'/',['constraint',13,'velocity/q2+Dq',13,' selection']],...
		'move name',0,...
		'Font Name','Arial',...
		'position',[200,140,230,180])

add_block('built-in/MATLAB Fcn',[sys,'/',['constraint',13,'velocity/MATLAB Fcn2']])
set_param([sys,'/',['constraint',13,'velocity/MATLAB Fcn2']],...
		'hide name',0,...
		'Font Name','Arial',...
		'MATLAB Fcn','d_min',...
		'Output Width','1',...
		'Mask Display','d_min',...
		'position',[330,150,370,170])

add_block('built-in/Note',[sys,'/',['constraint',13,'velocity/cs(q1+Dq,q2,q3)']])
set_param([sys,'/',['constraint',13,'velocity/cs(q1+Dq,q2,q3)']],...
		'Font Name','Arial',...
		'position',[275,70,280,76])

add_block('built-in/MATLAB Fcn',[sys,'/',['constraint',13,'velocity/MATLAB Fcn4']])
set_param([sys,'/',['constraint',13,'velocity/MATLAB Fcn4']],...
		'hide name',0,...
		'Font Name','Arial',...
		'MATLAB Fcn','d_min',...
		'Output Width','1',...
		'Mask Display','d_min',...
		'position',[330,80,370,100])

add_block('built-in/Sum',[sys,'/',['constraint',13,'velocity/Sum']])
set_param([sys,'/',['constraint',13,'velocity/Sum']],...
		'hide name',0,...
		'move name',0,...
		'Font Name','Arial',...
		'position',[80,71,95,109])

add_block('built-in/Inport',[sys,'/',['constraint',13,'velocity/q']])
set_param([sys,'/',['constraint',13,'velocity/q']],...
		'Font Name','Arial',...
		'Port','2',...
		'position',[10,70,30,90])

add_block('built-in/To Workspace',[sys,'/',['constraint',13,'velocity/To Workspace11']])
set_param([sys,'/',['constraint',13,'velocity/To Workspace11']],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','d_m',...
		'buffer','[2501,1,Ts]',...
		'position',[430,25,480,45])

add_block('built-in/Outport',[sys,'/',['constraint',13,'velocity/dq_a']])
set_param([sys,'/',['constraint',13,'velocity/dq_a']],...
		'Font Name','Arial',...
		'position',[580,145,600,165])

add_block('built-in/State-Space',[sys,'/',['constraint',13,'velocity/Matrix',13,'Gain']])
set_param([sys,'/',['constraint',13,'velocity/Matrix',13,'Gain']],...
		'hide name',0,...
		'Font Name','Arial',...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','K',...
		'Mask Display','k_a/Dq',...
		'Mask Type','Matrix Gain')
set_param([sys,'/',['constraint',13,'velocity/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).')
set_param([sys,'/',['constraint',13,'velocity/Matrix',13,'Gain']],...
		'Mask Entries','(k_a/Dq)*eye(3,3)\/',...
		'position',[505,138,560,172])

add_block('built-in/Sum',[sys,'/',['constraint',13,'velocity/Sum4']])
set_param([sys,'/',['constraint',13,'velocity/Sum4']],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','-+',...
		'position',[405,144,420,166])

add_block('built-in/Sum',[sys,'/',['constraint',13,'velocity/Sum5']])
set_param([sys,'/',['constraint',13,'velocity/Sum5']],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','-+',...
		'position',[405,224,420,246])

add_block('built-in/Constant',[sys,'/',['constraint',13,'velocity/Constant']])
set_param([sys,'/',['constraint',13,'velocity/Constant']],...
		'hide name',0,...
		'Font Name','Arial',...
		'Value','[Dq;0;0]',...
		'position',[10,119,50,141])


%     Subsystem  ['constraint',13,'velocity/sinusoidal',13,' functions'].

new_system([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],'Location',[21,408,57,444])

add_block('built-in/Outport',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/cs']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/cs']],...
		'position',[440,95,460,115])

add_block('built-in/Mux',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Mux']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Mux']],...
		'hide name',0,...
		'inputs','6',...
		'position',[385,17,410,193])

add_block('built-in/Fcn',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn3']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn3']],...
		'hide name',0,...
		'Expr','a(1)*sin(u)',...
		'Mask Display','',...
		'position',[295,109,365,131])

add_block('built-in/Fcn',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn']],...
		'hide name',0,...
		'Expr','a(1)*cos(u)',...
		'Mask Display','',...
		'position',[295,19,365,41])

add_block('built-in/Fcn',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn2']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn2']],...
		'hide name',0,...
		'Expr','a(3)*cos(u)',...
		'position',[295,79,365,101])

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

add_block('built-in/Fcn',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn4']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn4']],...
		'hide name',0,...
		'Expr','a(2)*sin(u)',...
		'Mask Display','',...
		'position',[295,139,365,161])

add_block('built-in/Fcn',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn5']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Fcn5']],...
		'hide name',0,...
		'Expr','a(3)*sin(u)',...
		'Mask Display','',...
		'position',[295,169,365,191])

add_block('built-in/Sum',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Sum3']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Sum3']],...
		'hide name',0,...
		'position',[190,161,205,194])

add_block('built-in/Inport',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/q']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/q']],...
		'position',[5,165,25,185])

add_block('built-in/Sum',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Sum2']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Sum2']],...
		'hide name',0,...
		'position',[115,159,130,181])

add_block('built-in/Note',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/q1 + q2']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/q1 + q2']],...
		'position',[150,150,155,155])

add_block('built-in/Demux',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Demux']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/Demux']],...
		'hide name',0,...
		'outputs','3',...
		'position',[50,157,90,193])

add_block('built-in/Note',[sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/q1 + q2 + q3']])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions/q1 + q2 + q3']],...
		'position',[250,160,255,165])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[370,30;380,30])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[370,60;380,60])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[370,90;380,90])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[370,120;380,120])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[370,150;380,150])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[370,180;380,180])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[415,105;435,105])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[95,165;110,165])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[95,175;110,175])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[30,175;45,175])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[95,185;185,185])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[210,180;290,180])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[135,170;185,170])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[175,170;175,60;290,60])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[175,170;175,150;290,150])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[95,165;95,30;290,30])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[95,120;290,120])
add_line([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],[210,180;210,90;290,90])
set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],...
		'Mask Display','cs(q)')


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

set_param([sys,'/',['constraint',13,'velocity/sinusoidal',13,' functions']],...
		'move name',0,...
		'Font Name','Arial',...
		'position',[130,70,170,110])
add_line([sys,'/',['constraint',13,'velocity']],[235,160;325,160])
add_line([sys,'/',['constraint',13,'velocity']],[375,160;400,160])
add_line([sys,'/',['constraint',13,'velocity']],[375,240;400,240])
add_line([sys,'/',['constraint',13,'velocity']],[35,80;75,80])
add_line([sys,'/',['constraint',13,'velocity']],[55,130;60,130;60,100;75,100])
add_line([sys,'/',['constraint',13,'velocity']],[100,90;125,90])
add_line([sys,'/',['constraint',13,'velocity']],[375,90;400,90])
add_line([sys,'/',['constraint',13,'velocity']],[35,35;325,35])
add_line([sys,'/',['constraint',13,'velocity']],[175,90;325,90])
add_line([sys,'/',['constraint',13,'velocity']],[235,240;325,240])
add_line([sys,'/',['constraint',13,'velocity']],[375,35;380,35;380,230;400,230])
add_line([sys,'/',['constraint',13,'velocity']],[380,150;400,150])
add_line([sys,'/',['constraint',13,'velocity']],[380,80;400,80])
add_line([sys,'/',['constraint',13,'velocity']],[425,155;450,155])
add_line([sys,'/',['constraint',13,'velocity']],[425,85;430,85;430,140;450,140])
add_line([sys,'/',['constraint',13,'velocity']],[425,235;435,235;435,170;450,170])
add_line([sys,'/',['constraint',13,'velocity']],[490,155;500,155])
add_line([sys,'/',['constraint',13,'velocity']],[565,155;575,155])
add_line([sys,'/',['constraint',13,'velocity']],[375,35;425,35])
add_line([sys,'/',['constraint',13,'velocity']],[175,90;180,90;180,170;195,170])
add_line([sys,'/',['constraint',13,'velocity']],[180,170;180,250;195,250])
add_line([sys,'/',['constraint',13,'velocity']],[110,35;110,150;195,150])
add_line([sys,'/',['constraint',13,'velocity']],[110,150;110,230;195,230])
set_param([sys,'/',['constraint',13,'velocity']],...
		'Mask Display','dq_a')


%     Finished composite block ['constraint',13,'velocity'].

set_param([sys,'/',['constraint',13,'velocity']],...
		'orientation',2,...
		'move name',0,...
		'Font Name','Arial',...
		'position',[285,85,325,125])

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

add_block('built-in/To Workspace',[sys,'/','To Workspace10'])
set_param([sys,'/','To Workspace10'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','e_p',...
		'buffer','[2501,1,Ts]',...
		'position',[165,85,215,105])


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

new_system([sys,'/',['direct ',13,'kinematics']])
set_param([sys,'/',['direct ',13,'kinematics']],'Location',[201,202,529,320])

add_block('built-in/Inport',[sys,'/',['direct ',13,'kinematics/cs']])
set_param([sys,'/',['direct ',13,'kinematics/cs']],...
		'position',[20,50,40,70])

add_block('built-in/Sum',[sys,'/',['direct ',13,'kinematics/Sum1']])
set_param([sys,'/',['direct ',13,'kinematics/Sum1']],...
		'hide name',0,...
		'inputs','+',...
		'position',[140,54,160,76])

add_block('built-in/Demux',[sys,'/',['direct ',13,'kinematics/Demux']])
set_param([sys,'/',['direct ',13,'kinematics/Demux']],...
		'hide name',0,...
		'outputs','[3,3]',...
		'position',[65,41,115,74])

add_block('built-in/Note',[sys,'/',['direct ',13,'kinematics/y']])
set_param([sys,'/',['direct ',13,'kinematics/y']],...
		'position',[215,45,220,50])

add_block('built-in/Note',[sys,'/',['direct ',13,'kinematics/x']])
set_param([sys,'/',['direct ',13,'kinematics/x']],...
		'position',[215,30,220,35])

add_block('built-in/Sum',[sys,'/',['direct ',13,'kinematics/Sum']])
set_param([sys,'/',['direct ',13,'kinematics/Sum']],...
		'hide name',0,...
		'inputs','+',...
		'position',[180,39,200,61])

add_block('built-in/Mux',[sys,'/',['direct ',13,'kinematics/Mux']])
set_param([sys,'/',['direct ',13,'kinematics/Mux']],...
		'hide name',0,...
		'inputs','2',...
		'position',[235,43,265,72])

add_block('built-in/Outport',[sys,'/',['direct ',13,'kinematics/p']])
set_param([sys,'/',['direct ',13,'kinematics/p']],...
		'position',[290,50,310,70])
add_line([sys,'/',['direct ',13,'kinematics']],[270,60;285,60])
add_line([sys,'/',['direct ',13,'kinematics']],[45,60;60,60])
add_line([sys,'/',['direct ',13,'kinematics']],[120,50;175,50])
add_line([sys,'/',['direct ',13,'kinematics']],[120,65;135,65])
add_line([sys,'/',['direct ',13,'kinematics']],[205,50;230,50])
add_line([sys,'/',['direct ',13,'kinematics']],[165,65;230,65])
set_param([sys,'/',['direct ',13,'kinematics']],...
		'Mask Display','k_p(q)')


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

set_param([sys,'/',['direct ',13,'kinematics']],...
		'orientation',2,...
		'move name',0,...
		'Font Name','Arial',...
		'position',[135,235,175,275])

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_p',...
		'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_p\/')
set_param([sys,'/',['Matrix',13,'Gain']],...
		'position',[140,171,170,199])

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,dp_d]',...
		'position',[5,128,50,152])

add_block('built-in/To Workspace',[sys,'/','To Workspace14'])
set_param([sys,'/','To Workspace14'],...
		'hide name',0,...
		'Font Name','Arial',...
		'mat-name','time',...
		'buffer','[2501,1,Ts]',...
		'position',[500,5,550,25])

add_block('built-in/Clock',[sys,'/','Clock'])
set_param([sys,'/','Clock'],...
		'hide name',0,...
		'Font Name','Arial',...
		'position',[430,5,450,25])


%     Subsystem  ['Euler',13,'integration'].

new_system([sys,'/',['Euler',13,'integration']])
set_param([sys,'/',['Euler',13,'integration']],'Location',[392,641,765,859])

add_block('built-in/Outport',[sys,'/',['Euler',13,'integration/out_1']])
set_param([sys,'/',['Euler',13,'integration/out_1']],...
		'position',[320,85,340,105])

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

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

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

add_block('built-in/Inport',[sys,'/',['Euler',13,'integration/in_1']])
set_param([sys,'/',['Euler',13,'integration/in_1']],...
		'position',[25,70,45,90])
add_line([sys,'/',['Euler',13,'integration']],[265,95;315,95])
add_line([sys,'/',['Euler',13,'integration']],[285,95;285,165;120,165;120,110;145,110])
add_line([sys,'/',['Euler',13,'integration']],[185,95;205,95])
add_line([sys,'/',['Euler',13,'integration']],[50,80;75,80])
add_line([sys,'/',['Euler',13,'integration']],[115,80;145,80])
set_param([sys,'/',['Euler',13,'integration']],...
		'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,'/',['Euler',13,'integration']],...
		'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,'/',['Euler',13,'integration']],...
		'Mask Entries','q_i\/Tc\/')


%     Finished composite block ['Euler',13,'integration'].

set_param([sys,'/',['Euler',13,'integration']],...
		'hide name',0,...
		'move name',0,...
		'Font Name','Arial',...
		'position',[425,164,465,196])


%     Subsystem  'Subsystem6'.

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

add_block('built-in/Note',[sys,'/','Subsystem6/start'])
set_param([sys,'/','Subsystem6/start'],...
		'position',[55,45,60,50])
set_param([sys,'/','Subsystem6'],...
		'Mask Display','unconstrained\nsolution',...
		'Mask Dialogue','eval(''clear all;c = 0;i3_17;'')')


%     Finished composite block 'Subsystem6'.

set_param([sys,'/','Subsystem6'],...
		'hide name',0,...
		'Font Name','Arial',...
		'Drop Shadow',4,...
		'position',[5,5,95,46])


%     Subsystem  'Subsystem7'.

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

add_block('built-in/Note',[sys,'/','Subsystem7/start'])
set_param([sys,'/','Subsystem7/start'],...
		'position',[55,45,60,50])
set_param([sys,'/','Subsystem7'],...
		'Mask Display','constrained\nsolution',...
		'Mask Dialogue','eval(''clear all;c=1;i3_17;'')')


%     Finished composite block 'Subsystem7'.

set_param([sys,'/','Subsystem7'],...
		'hide name',0,...
		'Font Name','Arial',...
		'Drop Shadow',4,...
		'position',[120,5,210,46])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'hide name',0,...
		'Font Name','Arial',...
		'inputs','+-',...
		'position',[85,169,105,196])

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,p_d]',...
		'position',[5,163,50,187])

add_block('built-in/Sum',[sys,'/','Sum1'])
set_param([sys,'/','Sum1'],...
		'hide name',0,...
		'Font Name','Arial',...
		'position',[195,164,215,191])
add_line(sys,[55,175;80,175])
add_line(sys,[470,180;495,180])
add_line(sys,[130,255;60,255;60,190;80,190])
add_line(sys,[420,255;180,255])
add_line(sys,[470,180;480,180;480,115;330,115])
add_line(sys,[380,180;420,180])
add_line(sys,[390,255;390,95;330,95])
add_line(sys,[280,105;225,105;225,165;240,165])
add_line(sys,[220,180;240,180])
add_line(sys,[225,255;225,195;240,195])
add_line(sys,[110,185;120,185;120,95;160,95])
add_line(sys,[455,15;495,15])
add_line(sys,[400,180;400,95;495,95])
add_line(sys,[55,140;180,140;190,170])
add_line(sys,[175,185;190,185])
add_line(sys,[120,185;135,185])
add_line(sys,[480,180;470,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
