function [ret,x0,str,ts,xts]=vdp(t,x,u,flag);
%VDP	is the M-file description of the SIMULINK system named VDP.
%	The block-diagram can be displayed by typing: VDP.
%
%	SYS=VDP(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 VDP 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 VDP with a FLAG of zero:
%	[SIZES]=VDP([],[],[],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',[25,80,520,406])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.2')
set_param(sys,'Stop time',     '10000')
set_param(sys,'Min step size', '0.0002')
set_param(sys,'Max step size', '5')
set_param(sys,'Relative error','1e-3')
set_param(sys,'Return vars',   '')

add_block('built-in/Note',[sys,'/',['X1'' = X1( 1 - X2*X2 ) - X2']])
set_param([sys,'/',['X1'' = X1( 1 - X2*X2 ) - X2']],...
		'position',[349,10,354,15])

add_block('built-in/Fcn',[sys,'/','(1-x2*x2)'])
set_param([sys,'/','(1-x2*x2)'],...
		'Expr','1 - u * u',...
		'position',[45,137,115,163])

add_block('built-in/Scope',[sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'Vgain','3.000000',...
		'Hgain','30.000000',...
		'Vmax','6.000000',...
		'Hmax','60.000000',...
		'Window',[560,201,817,395])
open_system([sys,'/','Scope'])
set_param([sys,'/','Scope'],...
		'position',[455,135,480,165])

add_block('built-in/Integrator',[sys,'/','int x2'])
set_param([sys,'/','int x2'],...
		'hide name',0,...
		'Initial','0.25',...
		'position',[375,132,420,168])

add_block('built-in/Integrator',[sys,'/','int x1'])
set_param([sys,'/','int x1'],...
		'hide name',0,...
		'Initial','0.25',...
		'position',[295,132,340,168])

add_block('built-in/Note',[sys,'/','X2'])
set_param([sys,'/','X2'],...
		'position',[240,65,245,70])

add_block('built-in/Product',[sys,'/','prod'])
set_param([sys,'/','prod'],...
		'hide name',0,...
		'position',[145,139,165,181])

add_block('built-in/Note',[sys,'/','or'])
set_param([sys,'/','or'],...
		'position',[235,20,240,25])

add_block('built-in/Note',[sys,'/',['X'''' + ( X*X - 1 ) X'' + X = 0']])
set_param([sys,'/',['X'''' + ( X*X - 1 ) X'' + X = 0']],...
		'position',[131,30,136,35])

add_block('built-in/Note',[sys,'/','The Van der Pol Equation:'])
set_param([sys,'/','The Van der Pol Equation:'],...
		'position',[124,10,129,15])

add_block('built-in/Gain',[sys,'/','-1'])
set_param([sys,'/','-1'],...
		'hide name',0,...
		'move name',0,...
		'position',[160,79,205,121])

add_block('built-in/Sum',[sys,'/','Diff'])
set_param([sys,'/','Diff'],...
		'hide name',0,...
		'inputs','-+',...
		'position',[235,124,255,171])

add_block('built-in/Note',[sys,'/',['X1''']])
set_param([sys,'/',['X1''']],...
		'position',[270,130,275,135])

add_block('built-in/Note',[sys,'/','X1'])
set_param([sys,'/','X1'],...
		'position',[244,209,249,214])

add_block('built-in/Note',[sys,'/',['The Van der Pol Equations',13,'(Double click on the "?" for more info)']])
set_param([sys,'/',['The Van der Pol Equations',13,'(Double click on the "?" for more info)']],...
		'position',[160,235,165,240])

add_block('built-in/Note',[sys,'/',['X2'' = X1 ']])
set_param([sys,'/',['X2'' = X1 ']],...
		'position',[294,30,299,35])

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,280,164,285])


%     Subsystem  'More Info'.

new_system([sys,'/','More Info'])
set_param([sys,'/','More Info'],'Location',[81,131,465,316])

add_block('built-in/Note',[sys,'/',['More Info/This demonstration models a second order nonlinear',13,'system. The equations that describe the system can ',13,'be found on the diagram.']])
set_param([sys,'/',['More Info/This demonstration models a second order nonlinear',13,'system. The equations that describe the system can ',13,'be found on the diagram.']],...
		'position',[178,15,183,20])

add_block('built-in/Note',[sys,'/',['More Info/In addition to running from the menus, you can ',13,'control the simulation of a system from the command line, ',13,'thereby speeding up the analysis.']])
set_param([sys,'/',['More Info/In addition to running from the menus, you can ',13,'control the simulation of a system from the command line, ',13,'thereby speeding up the analysis.']],...
		'position',[179,65,184,70])

add_block('built-in/Note',[sys,'/',['More Info/To see a demo of this, just type "vdpdemo" at the',13,'command line when the "vdp" window is open.']])
set_param([sys,'/',['More Info/To see a demo of this, just type "vdpdemo" at the',13,'command line when the "vdp" window is open.']],...
		'position',[176,120,181,125])
set_param([sys,'/','More Info'],...
		'Mask Display','?')


%     Finished composite block 'More Info'.

set_param([sys,'/','More Info'],...
		'hide name',0,...
		'Drop Shadow',4,...
		'position',[290,235,317,260])


%     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,243,463,294])
add_line(sys,[425,150;430,150;430,60;25,60;25,150;40,150])
add_line(sys,[425,150;450,150])
add_line(sys,[345,150;355,150;355,205;120,205;120,170;140,170])
add_line(sys,[355,150;370,150])
add_line(sys,[130,60;130,100;155,100])
add_line(sys,[170,160;230,160])
add_line(sys,[260,150;290,150])
add_line(sys,[120,150;140,150])
add_line(sys,[210,100;215,100;215,135;230,135])

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
