function [ret,x0,str,ts,xts]=dblpend1(t,x,u,flag);
%DBLPEND1	is the M-file description of the SIMULINK system named DBLPEND1.
%	The block-diagram can be displayed by typing: DBLPEND1.
%
%	SYS=DBLPEND1(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 DBLPEND1 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 DBLPEND1 with a FLAG of zero:
%	[SIZES]=DBLPEND1([],[],[],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',[531,94,1097,479])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0')
set_param(sys,'Stop time',     '10000')
set_param(sys,'Min step size', '0.005')
set_param(sys,'Max step size', '0.05')
set_param(sys,'Relative error','1e-5')
set_param(sys,'Return vars',   '')
set_param(sys,'Load callback','l21=5;w21=5;n1=1/4;e1=1/2;');

add_block('built-in/Fcn',[sys,'/','sin(alpha)'])
set_param([sys,'/','sin(alpha)'],...
		'Expr','sin(u)',...
		'position',[105,15,150,45])

add_block('built-in/Fcn',[sys,'/','(alphaDot)^2'])
set_param([sys,'/','(alphaDot)^2'],...
		'Expr','u*u',...
		'position',[105,60,150,90])

add_block('built-in/Fcn',[sys,'/','sin(gamma)'])
set_param([sys,'/','sin(gamma)'],...
		'Expr','sin(u)',...
		'position',[105,105,150,135])

add_block('built-in/Fcn',[sys,'/','(gammaDot)^2'])
set_param([sys,'/','(gammaDot)^2'],...
		'Expr','u*u',...
		'position',[105,150,150,180])

add_block('built-in/Fcn',[sys,'/','S'])
set_param([sys,'/','S'],...
		'Expr','sin(u(1)-u(3))',...
		'position',[105,240,150,270])

add_block('built-in/Fcn',[sys,'/','C'])
set_param([sys,'/','C'],...
		'Expr','cos(u(1)-u(3))',...
		'position',[105,195,150,225])

add_block('built-in/Demux',[sys,'/',['state',13,'vector',13,'[a aD g gD]']])
set_param([sys,'/',['state',13,'vector',13,'[a aD g gD]']],...
		'position',[25,77,65,123])

add_block('built-in/Scope',[sys,'/',['State',13,'Scope']])
set_param([sys,'/',['State',13,'Scope']],...
		'orientation',2,...
		'Vgain','2.000000',...
		'Hgain','40.000000',...
		'Vmax','4.000000',...
		'Hmax','80.000000',...
		'Window',[787,501,1075,733],...
		'position',[235,225,260,255])

add_block('built-in/Mux',[sys,'/',['state',13,'vector']])
set_param([sys,'/',['state',13,'vector']],...
		'orientation',2,...
		'position',[340,259,370,316])

add_block('built-in/Integrator',[sys,'/','alpha'])
set_param([sys,'/','alpha'],...
		'Initial','100*(pi/180)',...
		'position',[430,98,455,132])

add_block('built-in/Integrator',[sys,'/','alphaDot'])
set_param([sys,'/','alphaDot'],...
		'position',[340,98,365,132])

add_block('built-in/Integrator',[sys,'/','gamma'])
set_param([sys,'/','gamma'],...
		'Initial','0*(pi/180)',...
		'position',[430,153,455,187])

add_block('built-in/Integrator',[sys,'/','gammaDot'])
set_param([sys,'/','gammaDot'],...
		'position',[340,153,365,187])

add_block('built-in/Mux',[sys,'/',['modified',13,'state',13,'vector']])
set_param([sys,'/',['modified',13,'state',13,'vector']],...
		'inputs','6',...
		'position',[190,112,220,178])

add_block('built-in/S-Function',[sys,'/',['Animation',13,'Function']])
set_param([sys,'/',['Animation',13,'Function']],...
		'orientation',2,...
		'function name','pndanim2',...
		'parameters','0.05',...
		'position',[295,17,360,53])

add_block('built-in/Fcn',[sys,'/','gammaDDot'])
set_param([sys,'/','gammaDDot'],...
		'Expr','(-w21*u(3)+e1*l21*u(5)*u(1)+n1*e1*u(5)*u(6)*u(4)+e1*u(6)*u(2))/(1-n1*e1*u(5)*u(5))',...
		'position',[260,155,305,185])

add_block('built-in/Fcn',[sys,'/','alphaDDot'])
set_param([sys,'/','alphaDDot'],...
		'Expr','(-l21*u(1)+n1*w21*u(5)*u(3)-n1*e1*u(5)*u(6)*u(2)-n1*u(6)*u(4))/(1-n1*e1*u(5)*u(5))',...
		'position',[260,100,305,130])

add_block('built-in/Note',[sys,'/',['Double Pendulum System I',13,'(Double click on the "?" for more info)']])
set_param([sys,'/',['Double Pendulum System I',13,'(Double click on the "?" for more info)']],...
		'position',[130,305,135,310])


%     Subsystem  'More Info'.

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

add_block('built-in/Note',[sys,'/',['More Info/This system models a double pendulum system where',13,'the rest state has both pendulums hanging vertically.']])
set_param([sys,'/',['More Info/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 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/Try experimenting with different initial conditions for',13,'alpha and gamma to see the unusal coupling effects.']])
set_param([sys,'/',['More Info/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 Info'],...
		'Mask Display','?')


%     Finished composite block 'More Info'.

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

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,345,164,350])

add_block('built-in/Scope',[sys,'/','scope'])
set_param([sys,'/','scope'],...
		'orientation',2,...
		'Vgain','2.000000',...
		'Hgain','32.000000',...
		'Vmax','4.000000',...
		'Hmax','64.000000',...
		'Window',[802,576,1090,808],...
		'position',[380,50,405,80])


%     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/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])

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/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])
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',[426,318,528,369])

add_block('built-in/Mux',[sys,'/',['state',13,'vector1']])
set_param([sys,'/',['state',13,'vector1']],...
		'orientation',2,...
		'inputs','2',...
		'position',[440,8,470,57])
add_line(sys,[310,115;335,115])
add_line(sys,[370,115;425,115])
add_line(sys,[370,170;425,170])
add_line(sys,[310,170;335,170])
add_line(sys,[460,115;505,115;505,265;375,265])
add_line(sys,[460,170;485,170;485,295;375,295])
add_line(sys,[390,115;390,280;375,280])
add_line(sys,[410,170;410,310;375,310])
add_line(sys,[335,290;10,290;20,100])
add_line(sys,[40,290;40,210;100,210])
add_line(sys,[40,255;100,255])
add_line(sys,[505,115;505,20;475,20])
add_line(sys,[485,170;475,45])
add_line(sys,[435,35;365,35])
add_line(sys,[420,35;420,65;410,65])
add_line(sys,[295,290;295,240;265,240])
add_line(sys,[155,255;175,255;185,170])
add_line(sys,[155,210;170,210;170,160;185,160])
add_line(sys,[155,165;165,165;165,150;185,150])
add_line(sys,[155,120;165,120;165,140;185,140])
add_line(sys,[155,75;170,75;170,130;185,130])
add_line(sys,[155,30;175,30;185,120])
add_line(sys,[70,115;85,115;85,165;100,165])
add_line(sys,[70,105;90,105;100,120])
add_line(sys,[70,95;90,95;100,75])
add_line(sys,[70,85;85,85;85,30;100,30])
add_line(sys,[225,145;235,145;235,115;255,115])
add_line(sys,[235,145;235,170;255,170])

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
