function [ret,x0,str,ts,xts]=simppend(t,x,u,flag);
%SIMPPEND	is the M-file description of the SIMULINK system named SIMPPEND.
%	The block-diagram can be displayed by typing: SIMPPEND.
%
%	SYS=SIMPPEND(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 SIMPPEND 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 SIMPPEND with a FLAG of zero:
%	[SIZES]=SIMPPEND([],[],[],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',[621,72,1105,410])
     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.1')
set_param(sys,'Max step size', '0.1')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/S-Function',[sys,'/','Animation function'])
set_param([sys,'/','Animation function'],...
		'orientation',2,...
		'function name','pndanim1',...
		'parameters','0.05',...
		'position',[335,132,400,168])

add_block('built-in/Fcn',[sys,'/','g*sin(theta)'])
set_param([sys,'/','g*sin(theta)'],...
		'orientation',2,...
		'Expr','9.8*sin(u)',...
		'position',[155,208,235,242])

add_block('built-in/Mux',[sys,'/','x & theta'])
set_param([sys,'/','x & theta'],...
		'inputs','2',...
		'position',[350,65,380,105])

add_block('built-in/Constant',[sys,'/',['Pivot point',13,'for pendulum']])
set_param([sys,'/',['Pivot point',13,'for pendulum']],...
		'Value','0',...
		'position',[190,9,220,41])

add_block('built-in/Gain',[sys,'/','c//(m*len^2)'])
set_param([sys,'/','c//(m*len^2)'],...
		'orientation',2,...
		'Gain','.05',...
		'position',[185,138,220,182])

add_block('built-in/Integrator',[sys,'/',['theta',13,'dot']])
set_param([sys,'/',['theta',13,'dot']],...
		'position',[215,78,240,112])

add_block('built-in/Integrator',[sys,'/','theta'])
set_param([sys,'/','theta'],...
		'Initial','45',...
		'position',[260,78,285,112])

add_block('built-in/Sum',[sys,'/','Sum2'])
set_param([sys,'/','Sum2'],...
		'inputs','+--',...
		'position',[180,77,200,113])

add_block('built-in/Gain',[sys,'/','1//len'])
set_param([sys,'/','1//len'],...
		'Gain','0.25',...
		'position',[85,69,125,121])

add_block('built-in/Signal Generator',[sys,'/',['Applied',13,'Moment M']])
set_param([sys,'/',['Applied',13,'Moment M']],...
		'Peak','0.500000',...
		'Peak Range','Inf',...
		'Freq','0.100000',...
		'Freq Range','0.500000',...
		'Wave','Sqr',...
		'Units','Rads',...
		'position',[15,18,60,52])

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


%     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/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/This system models a simple pendulum system with',13,'an applied external moment that varies periodically.']])
set_param([sys,'/',['More Info/This system models a simple pendulum system with',13,'an applied external moment that varies periodically.']],...
		'position',[168,20,173,25])

add_block('built-in/Note',[sys,'/',['More Info/Try experimenting with different initial conditions and',13,'different setting for the applied moment M.']])
set_param([sys,'/',['More Info/Try experimenting with different initial conditions and',13,'different setting for the applied moment M.']],...
		'position',[170,110,175,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',[270,270,297,295])

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',[179,305,184,310])


%     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',[361,263,463,314])
add_line(sys,[245,95;245,160;225,160])
add_line(sys,[205,95;210,95])
add_line(sys,[180,160;145,160;145,105;175,105])
add_line(sys,[245,95;255,95])
add_line(sys,[225,25;295,25;295,75;345,75])
add_line(sys,[385,85;425,85;425,150;405,150])
add_line(sys,[290,95;345,95])
add_line(sys,[305,95;305,225;240,225])
add_line(sys,[130,95;175,95])
add_line(sys,[150,225;60,225;60,95;80,95])
add_line(sys,[65,35;145,35;145,85;175,85])

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
