function [ret,x0,str,ts,xts]=nlmagnet(t,x,u,flag);
%NLMAGNET	is the M-file description of the SIMULINK system named NLMAGNET.
%	The block-diagram can be displayed by typing: NLMAGNET.
%
%	SYS=NLMAGNET(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 NLMAGNET 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 NLMAGNET with a FLAG of zero:
%	[SIZES]=NLMAGNET([],[],[],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',[250,174,848,471])
     open_system(sys)
end;
set_param(sys,'algorithm',     'RK-45')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     'tf')
set_param(sys,'Min step size', '0.0001')
set_param(sys,'Max step size', '0.01')
set_param(sys,'Relative error','1e-6')
set_param(sys,'Return vars',   't_nl')

add_block('built-in/Note',[sys,'/','Magnetic  Suspension System: Nonlinear Model'])
set_param([sys,'/','Magnetic  Suspension System: Nonlinear Model'],...
		'Font Name','helvetica',...
		'Font Weight','bold',...
		'Font Angle','oblique',...
		'Font Size',18,...
		'position',[305,10,310,15])


%     Subsystem  ['Double click here',13,'to start loading data',13,'and mu-syn design1'].

new_system([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],'Location',[2,439,106,512])
set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],...
		'Mask Display','Load\nData',...
		'Mask Dialogue','eval([''magdat''])')


%     Finished composite block ['Double click here',13,'to start loading data',13,'and mu-syn design1'].

set_param([sys,'/',['Double click here',13,'to start loading data',13,'and mu-syn design1']],...
		'hide name',0,...
		'Drop Shadow',4,...
		'position',[38,74,89,101])


%     Subsystem  'position'.

new_system([sys,'/','position'])
set_param([sys,'/','position'],'Location',[0,59,274,252])

add_block('built-in/Inport',[sys,'/','position/x'])
set_param([sys,'/','position/x'],...
		'position',[65,55,85,75])

add_block('built-in/S-Function',[sys,'/',['position/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['position/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfunyst',...
		'parameters','ax, color, npts, dt',...
		'position',[130,55,180,75])
add_line([sys,'/','position'],[90,65;125,65])
set_param([sys,'/','position'],...
		'Mask Display','plot(0,0,100,100,[83,76,63,52,42,38,28,16,11,84,11,11,11,90,90,11],[75,58,47,54,72,80,84,74,65,65,65,90,40,40,90,90])',...
		'Mask Type','Storage scope.')
set_param([sys,'/','position'],...
		'Mask Dialogue','Storage scope using MATLAB graph window.\nEnter plotting ranges and line type.|Initial Time Range:|Initial y-min:|Initial y-max:|Storage pts.:|Line type (rgbw-.:xo):')
set_param([sys,'/','position'],...
		'Mask Translate','npts = @4; color = @5; ax = [0, @1, @2, @3]; dt=-1;')
set_param([sys,'/','position'],...
		'Mask Help','This block uses a MATLAB figure window to plot the input signal.  The graph limits are automatically scaled to the min and max values of the signal stored in the scope''s signal buffer.  Line type must be in quotes.  See the M-file sfunyst.m.')
set_param([sys,'/','position'],...
		'Mask Entries','tf\/0.005\/.015\/2000\/''y-/g--/c-./w:/m*/ro/b+''\/')


%     Finished composite block 'position'.

set_param([sys,'/','position'],...
		'move name',0,...
		'position',[510,150,540,190])


%     Subsystem  ['Electromagnet',13,'(Nonlinear)'].

new_system([sys,'/',['Electromagnet',13,'(Nonlinear)']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)']],'Location',[116,91,618,413])

add_block('built-in/Note',[sys,'/',['Electromagnet',13,'(Nonlinear)/Electromagnet Dynamics']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/Electromagnet Dynamics']],...
		'Font Name','helvetica',...
		'Font Weight','bold',...
		'Font Angle','oblique',...
		'Font Size',18,...
		'position',[245,10,250,15])

add_block('built-in/Outport',[sys,'/',['Electromagnet',13,'(Nonlinear)/suspended object',13,'position',13,'(meters)']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/suspended object',13,'position',13,'(meters)']],...
		'position',[420,125,440,145])

add_block('built-in/Inport',[sys,'/',['Electromagnet',13,'(Nonlinear)/electromagnet',13,'voltage',13,'(Volts)']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/electromagnet',13,'voltage',13,'(Volts)']],...
		'Port','2',...
		'position',[45,225,65,245])

add_block('built-in/Inport',[sys,'/',['Electromagnet',13,'(Nonlinear)/disturbance',13,'(Newtons)']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/disturbance',13,'(Newtons)']],...
		'position',[45,125,65,145])

add_block('built-in/Gain',[sys,'/',['Electromagnet',13,'(Nonlinear)/Gain5']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/Gain5']],...
		'hide name',0,...
		'Gain','1/m',...
		'position',[95,118,130,152])

add_block('built-in/Constant',[sys,'/',['Electromagnet',13,'(Nonlinear)/gravity']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/gravity']],...
		'move name',0,...
		'Value','g',...
		'position',[100,80,120,100])

add_block('built-in/Sum',[sys,'/',['Electromagnet',13,'(Nonlinear)/Sum3']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/Sum3']],...
		'hide name',0,...
		'inputs','++-',...
		'position',[155,117,175,153])

add_block('built-in/Integrator',[sys,'/',['Electromagnet',13,'(Nonlinear)/position']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/position']],...
		'BackGround',5,...
		'Initial','Xo',...
		'position',[285,125,305,145])

add_block('built-in/Integrator',[sys,'/',['Electromagnet',13,'(Nonlinear)/velocity']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/velocity']],...
		'BackGround',5,...
		'Initial','Vo',...
		'position',[230,125,250,145])

add_block('built-in/Integrator',[sys,'/',['Electromagnet',13,'(Nonlinear)/current']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/current']],...
		'BackGround',5,...
		'Initial','Io',...
		'position',[270,230,290,250])

add_block('built-in/Sum',[sys,'/',['Electromagnet',13,'(Nonlinear)/Sum2']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/Sum2']],...
		'hide name',0,...
		'inputs','+-',...
		'position',[150,230,170,250])

add_block('built-in/Product',[sys,'/',['Electromagnet',13,'(Nonlinear)/Product']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/Product']],...
		'orientation',2,...
		'hide name',0,...
		'position',[285,174,305,196])

add_block('built-in/Fcn',[sys,'/',['Electromagnet',13,'(Nonlinear)/u^2']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/u^2']],...
		'orientation',2,...
		'hide name',0,...
		'Expr','u^2',...
		'position',[220,175,260,195])

add_block('built-in/Fcn',[sys,'/',['Electromagnet',13,'(Nonlinear)/1//u']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/1//u']],...
		'orientation',2,...
		'hide name',0,...
		'Expr','1/u',...
		'position',[330,172,365,188])

add_block('built-in/Gain',[sys,'/',['Electromagnet',13,'(Nonlinear)/Re']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/Re']],...
		'orientation',2,...
		'hide name',0,...
		'Gain','Re',...
		'position',[205,267,240,293])

add_block('built-in/Gain',[sys,'/',['Electromagnet',13,'(Nonlinear)/1//Le']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/1//Le']],...
		'hide name',0,...
		'Gain','1/Le',...
		'position',[200,223,245,257])

add_block('built-in/Gain',[sys,'/',['Electromagnet',13,'(Nonlinear)/Gain4']])
set_param([sys,'/',['Electromagnet',13,'(Nonlinear)/Gain4']],...
		'orientation',2,...
		'hide name',0,...
		'Gain','Ke/m',...
		'position',[145,163,195,207])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[295,240;325,240;325,190;310,190])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[325,240;325,280;245,280])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[200,280;135,280;145,245])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[175,240;195,240])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[250,240;265,240])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[280,185;265,185])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[215,185;200,185])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[310,135;415,135])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[325,180;310,180])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[180,135;225,135])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[255,135;280,135])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[140,185;150,145])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[70,235;145,235])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[380,135;370,180])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[135,135;150,135])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[125,90;140,90;150,125])
add_line([sys,'/',['Electromagnet',13,'(Nonlinear)']],[70,135;90,135])


%     Finished composite block ['Electromagnet',13,'(Nonlinear)'].

set_param([sys,'/',['Electromagnet',13,'(Nonlinear)']],...
		'Drop Shadow',4,...
		'position',[395,140,425,195])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'hide name',0,...
		'inputs','2',...
		'position',[420,94,445,121])


%     Subsystem  ['control  and',13,'disturbance'].

new_system([sys,'/',['control  and',13,'disturbance']])
set_param([sys,'/',['control  and',13,'disturbance']],'Location',[0,59,274,252])

add_block('built-in/S-Function',[sys,'/',['control  and',13,'disturbance/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['control  and',13,'disturbance/S-function',13,'M-file which plots',13,'lines',13,'']],...
		'function name','sfunyst',...
		'parameters','ax, color, npts, dt',...
		'position',[130,55,180,75])

add_block('built-in/Inport',[sys,'/',['control  and',13,'disturbance/x']])
set_param([sys,'/',['control  and',13,'disturbance/x']],...
		'position',[65,55,85,75])
add_line([sys,'/',['control  and',13,'disturbance']],[90,65;125,65])
set_param([sys,'/',['control  and',13,'disturbance']],...
		'Mask Display','plot(0,0,100,100,[83,76,63,52,42,38,28,16,11,84,11,11,11,90,90,11],[75,58,47,54,72,80,84,74,65,65,65,90,40,40,90,90])',...
		'Mask Type','Storage scope.')
set_param([sys,'/',['control  and',13,'disturbance']],...
		'Mask Dialogue','Storage scope using MATLAB graph window.\nEnter plotting ranges and line type.|Initial Time Range:|Initial y-min:|Initial y-max:|Storage pts.:|Line type (rgbw-.:xo):')
set_param([sys,'/',['control  and',13,'disturbance']],...
		'Mask Translate','npts = @4; color = @5; ax = [0, @1, @2, @3]; dt=-1;')
set_param([sys,'/',['control  and',13,'disturbance']],...
		'Mask Help','This block uses a MATLAB figure window to plot the input signal.  The graph limits are automatically scaled to the min and max values of the signal stored in the scope''s signal buffer.  Line type must be in quotes.  See the M-file sfunyst.m.')
set_param([sys,'/',['control  and',13,'disturbance']],...
		'Mask Entries','tf\/-5\/15\/2000\/''y-/g--/c-./w:/m*/ro/b+''\/')


%     Finished composite block ['control  and',13,'disturbance'].

set_param([sys,'/',['control  and',13,'disturbance']],...
		'move name',0,...
		'position',[510,90,540,130])

add_block('built-in/Step Fcn',[sys,'/',['disturbance',13,'(Newtons)']])
set_param([sys,'/',['disturbance',13,'(Newtons)']],...
		'Time','t_dist',...
		'After','dist',...
		'position',[325,105,345,125])


%     Subsystem  'Controller'.

new_system([sys,'/','Controller'])
set_param([sys,'/','Controller'],'Location',[198,292,545,451])

add_block('built-in/Outport',[sys,'/','Controller/to plant'])
set_param([sys,'/','Controller/to plant'],...
		'position',[290,85,310,105])

add_block('built-in/Sum',[sys,'/','Controller/Sum'])
set_param([sys,'/','Controller/Sum'],...
		'ForeGround',1,...
		'BackGround',4,...
		'hide name',0,...
		'position',[240,85,260,105])

add_block('built-in/Constant',[sys,'/',['Controller/equilibrium voltage',13,'bias']])
set_param([sys,'/',['Controller/equilibrium voltage',13,'bias']],...
		'ForeGround',1,...
		'BackGround',4,...
		'move name',0,...
		'Value','Eo',...
		'position',[150,45,170,65])

add_block('built-in/Transfer Fcn',[sys,'/','Controller/Controller'])
set_param([sys,'/','Controller/Controller'],...
		'ForeGround',1,...
		'BackGround',4,...
		'Numerator','[1 30]',...
		'Denominator','[1 300]',...
		'position',[125,80,190,120])

add_block('built-in/Gain',[sys,'/','Controller/K'])
set_param([sys,'/','Controller/K'],...
		'ForeGround',1,...
		'BackGround',4,...
		'Gain','-172',...
		'position',[75,84,105,116])

add_block('built-in/Inport',[sys,'/',['Controller/error',13,'signal']])
set_param([sys,'/',['Controller/error',13,'signal']],...
		'position',[20,90,40,110])
add_line([sys,'/','Controller'],[110,100;120,100])
add_line([sys,'/','Controller'],[45,100;70,100])
add_line([sys,'/','Controller'],[195,100;235,100])
add_line([sys,'/','Controller'],[175,55;205,55;205,90;235,90])
add_line([sys,'/','Controller'],[265,95;285,95])


%     Finished composite block 'Controller'.

set_param([sys,'/','Controller'],...
		'position',[230,162,270,198])

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'hide name',0,...
		'inputs','+-',...
		'position',[180,170,200,190])

add_block('built-in/Gain',[sys,'/','Sensor'])
set_param([sys,'/','Sensor'],...
		'orientation',2,...
		'Gain','beta',...
		'position',[290,224,340,256])

add_block('built-in/Gain',[sys,'/','Pre-filter'])
set_param([sys,'/','Pre-filter'],...
		'Gain','beta',...
		'position',[115,159,155,191])

add_block('built-in/Constant',[sys,'/',['position',13,'reference']])
set_param([sys,'/',['position',13,'reference']],...
		'move name',0,...
		'Value','Xo',...
		'position',[65,165,85,185])

add_block('built-in/S-Function',[sys,'/','Write to File'])
set_param([sys,'/','Write to File'],...
		'function name','wfile',...
		'parameters','filename',...
		'position',[510,205,560,225])

add_block('built-in/To Workspace',[sys,'/','To Workspace'])
set_param([sys,'/','To Workspace'],...
		'mat-name','y_nl',...
		'buffer','2000',...
		'position',[515,252,565,268])
add_line(sys,[285,240;165,240;175,185])
add_line(sys,[160,175;175,175])
add_line(sys,[90,175;110,175])
add_line(sys,[430,170;455,170;455,240;345,240])
add_line(sys,[350,115;415,115])
add_line(sys,[450,110;505,110])
add_line(sys,[205,180;225,180])
add_line(sys,[375,115;375,155;390,155])
add_line(sys,[275,180;390,180])
add_line(sys,[295,180;295,100;415,100])
add_line(sys,[455,170;505,170])
add_line(sys,[480,170;480,260;510,260])
add_line(sys,[480,215;505,215])

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
