function [ret,x0,str,ts,xts]=dblcart1(t,x,u,flag);
%DBLCART1	is the M-file description of the SIMULINK system named DBLCART1.
%	The block-diagram can be displayed by typing: DBLCART1.
%
%	SYS=DBLCART1(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 DBLCART1 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 DBLCART1 with a FLAG of zero:
%	[SIZES]=DBLCART1([],[],[],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',[511,107,1006,474])
     open_system(sys)
end;
set_param(sys,'algorithm',     'Linear')
set_param(sys,'Start time',    '0')
set_param(sys,'Stop time',     '10000')
set_param(sys,'Min step size', '0.1')
set_param(sys,'Max step size', '0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')
set_param(sys,'Load callback','load dblcart1');

add_block('built-in/State-Space',[sys,'/',['State',13,'estimator']])
set_param([sys,'/',['State',13,'estimator']],...
		'orientation',2,...
		'A','ae',...
		'B','be',...
		'C','ce',...
		'D','de',...
		'position',[210,129,285,181])

add_block('built-in/State-Space',[sys,'/',['Feedback',13,'gain using',13,'LQR design.']])
set_param([sys,'/',['Feedback',13,'gain using',13,'LQR design.']],...
		'orientation',2,...
		'A','[]',...
		'B','[]',...
		'C','[]',...
		'D','k',...
		'Mask Display','K',...
		'Mask Type','Regulator',...
		'Mask Dialogue','Matrix Gain|K')
set_param([sys,'/',['Feedback',13,'gain using',13,'LQR design.']],...
		'Mask Translate','k=@1;',...
		'Mask Help','Matrix Gain block',...
		'Mask Entries','K\/',...
		'position',[125,127,190,183])

add_block('built-in/Sum',[sys,'/','Sum3'])
set_param([sys,'/','Sum3'],...
		'inputs','+-',...
		'position',[130,37,150,73])

add_block('built-in/Signal Generator',[sys,'/','Signal Gen.2'])
set_param([sys,'/','Signal Gen.2'],...
		'Peak','15.000000',...
		'Peak Range','Inf',...
		'Freq','0.300000',...
		'Freq Range','1.500000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[40,28,85,62])

add_block('built-in/State-Space',[sys,'/','Plant'])
set_param([sys,'/','Plant'],...
		'A','[0 1 0 0; -ka/m1 0 ka/m1 0; 0 0 0 1;ka/m2 0 -ka/m2 0]',...
		'B','[0; 1; 0; 0]',...
		'C','[1 0 0 0;0 0 1 0;0 0 1 0]',...
		'D','zeros(3,1)',...
		'position',[200,32,280,78])

add_block('built-in/Demux',[sys,'/','Demux'])
set_param([sys,'/','Demux'],...
		'outputs','[2,1]',...
		'position',[300,35,340,70])

add_block('built-in/Mux',[sys,'/',['Inputs & ',13,'Sensors']])
set_param([sys,'/',['Inputs & ',13,'Sensors']],...
		'orientation',2,...
		'inputs','2',...
		'position',[310,135,340,170])

add_block('built-in/S-Function',[sys,'/',['Animation',13,'function']])
set_param([sys,'/',['Animation',13,'function']],...
		'function name','crtanim2',...
		'parameters','.1',...
		'position',[410,142,475,178])

add_block('built-in/Note',[sys,'/',['To start and stop the simulation, use the "Start//Stop"',13,'selection in the "Simulation" pull-down menu']])
set_param([sys,'/',['To start and stop the simulation, use the "Start//Stop"',13,'selection in the "Simulation" pull-down menu']],...
		'position',[159,330,164,335])

add_block('built-in/Note',[sys,'/',['Double Mass-Spring System',13,'(Double click on the "?" for more info)']])
set_param([sys,'/',['Double Mass-Spring System',13,'(Double click on the "?" for more info)']],...
		'position',[130,295,135,300])


%     Subsystem  'More Info'.

new_system([sys,'/','More Info'])
set_param([sys,'/','More Info'],'Location',[133,305,492,478])

add_block('built-in/Note',[sys,'/',['More Info/This system models a double spring-mass-damper',13,'system with a periodically varying forcing function.']])
set_param([sys,'/',['More Info/This system models a double spring-mass-damper',13,'system with a periodically varying forcing function.']],...
		'position',[168,20,173,25])

add_block('built-in/Note',[sys,'/',['More Info/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']])
set_param([sys,'/',['More Info/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']],...
		'position',[174,65,179,70])

add_block('built-in/Note',[sys,'/',['More Info/In this system, the only sensor is attached to the mass',13,'on the left, and the actuator is attached to the mass on',13,'the left. State estimation and LQR control are used.']])
set_param([sys,'/',['More Info/In this system, the only sensor is attached to the mass',13,'on the left, and the actuator is attached to the mass on',13,'the left. State estimation and LQR control are used.']],...
		'position',[175,110,180,115])
set_param([sys,'/','More Info'],...
		'Mask Display','?')


%     Finished composite block 'More Info'.

set_param([sys,'/','More Info'],...
		'hide name',0,...
		'Drop Shadow',4,...
		'position',[260,300,287,325])

add_block('built-in/Demux',[sys,'/','Demux1'])
set_param([sys,'/','Demux1'],...
		'position',[255,217,295,263])

add_block('built-in/Mux',[sys,'/',['Inputs & ',13,'Sensors1']])
set_param([sys,'/',['Inputs & ',13,'Sensors1']],...
		'inputs','2',...
		'position',[330,215,360,255])

add_block('built-in/Scope',[sys,'/',['Estimated',13,'Position']])
set_param([sys,'/',['Estimated',13,'Position']],...
		'Vgain','10.000000',...
		'Hgain','40.000000',...
		'Vmax','20.000000',...
		'Hmax','80.000000',...
		'Window',[686,533,974,765],...
		'position',[395,222,415,248])


%     Subsystem  'More Info1'.

new_system([sys,'/','More Info1'])
set_param([sys,'/','More Info1'],'Location',[128,280,487,453])

add_block('built-in/Note',[sys,'/',['More Info1/This system models a double pendulum system where',13,'the rest state has both pendulums hanging vertically.']])
set_param([sys,'/',['More Info1/This system models a double pendulum system where',13,'the rest state has both pendulums hanging vertically.']],...
		'position',[168,20,173,25])

add_block('built-in/Note',[sys,'/',['More Info1/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']])
set_param([sys,'/',['More Info1/Associated with the demo is an animation function that',13,'will automatically open a figure window and display to it.']],...
		'position',[174,65,179,70])

add_block('built-in/Note',[sys,'/',['More Info1/Try experimenting with different initial conditions for',13,'alpha and gamma to see the unusal coupling effects.']])
set_param([sys,'/',['More Info1/Try experimenting with different initial conditions for',13,'alpha and gamma to see the unusal coupling effects.']],...
		'position',[175,115,180,120])
set_param([sys,'/','More Info1'],...
		'Mask Display','Double click\nhere for\nSIMULINK Help',...
		'Mask Dialogue','eval(''[cs,cb]=get_param;str=[''''simcad '''' cs];eval(str);'')')


%     Finished composite block 'More Info1'.

set_param([sys,'/','More Info1'],...
		'hide name',0,...
		'Drop Shadow',4,...
		'position',[351,303,453,354])

add_block('built-in/Scope',[sys,'/',['Actual',13,'Position']])
set_param([sys,'/',['Actual',13,'Position']],...
		'Vgain','10.000000',...
		'Hgain','40.000000',...
		'Vmax','20.000000',...
		'Hmax','80.000000',...
		'Window',[685,170,973,402],...
		'position',[430,32,450,58])
add_line(sys,[90,45;125,45])
add_line(sys,[285,55;295,55])
add_line(sys,[155,55;195,55])
add_line(sys,[345,60;370,60;370,160;345,160])
add_line(sys,[345,45;425,45])
add_line(sys,[120,155;110,155;110,65;125,65])
add_line(sys,[205,155;195,155])
add_line(sys,[390,45;390,160;405,160])
add_line(sys,[175,55;175,100;360,100;360,145;345,145])
add_line(sys,[305,155;290,155])
add_line(sys,[205,155;205,240;250,240])
add_line(sys,[300,225;325,225])
add_line(sys,[300,245;325,245])
add_line(sys,[365,235;390,235])

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
