function [ret,x0,str,ts,xts]=lmagnet(t,x,u,flag);
%LMAGNET	is the M-file description of the SIMULINK system named LMAGNET.
%	The block-diagram can be displayed by typing: LMAGNET.
%
%	SYS=LMAGNET(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 LMAGNET 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 LMAGNET with a FLAG of zero:
%	[SIZES]=LMAGNET([],[],[],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',[291,91,901,437])
     open_system(sys)
end;
set_param(sys,'algorithm',     'Linear')
set_param(sys,'Start time',    '0.0')
set_param(sys,'Stop time',     '1')
set_param(sys,'Min step size', '0.001')
set_param(sys,'Max step size', '0.001')
set_param(sys,'Relative error','1e-4')
set_param(sys,'Return vars',   't_lin')

add_block('built-in/Sum',[sys,'/','Sum'])
set_param([sys,'/','Sum'],...
		'ForeGround',1,...
		'BackGround',4,...
		'hide name',0,...
		'inputs','+-',...
		'position',[170,224,185,246])

add_block('built-in/Gain',[sys,'/','Pre-filter'])
set_param([sys,'/','Pre-filter'],...
		'ForeGround',1,...
		'BackGround',4,...
		'move name',0,...
		'Gain','beta',...
		'position',[115,214,155,246])

add_block('built-in/Step Fcn',[sys,'/',['position',13,'command']])
set_param([sys,'/',['position',13,'command']],...
		'ForeGround',1,...
		'BackGround',2,...
		'move name',0,...
		'Time','0',...
		'Before','Xo',...
		'After','Xo',...
		'position',[30,195,50,215])

add_block('built-in/Sum',[sys,'/','Sum1'])
set_param([sys,'/','Sum1'],...
		'ForeGround',1,...
		'BackGround',2,...
		'hide name',0,...
		'inputs','+-',...
		'position',[85,219,100,241])

add_block('built-in/Constant',[sys,'/',['equilibrium',13,'bias']])
set_param([sys,'/',['equilibrium',13,'bias']],...
		'ForeGround',1,...
		'BackGround',2,...
		'Value','Xo',...
		'position',[30,235,50,265])

add_block('built-in/Step Fcn',[sys,'/',['disturbance',13,'(N)']])
set_param([sys,'/',['disturbance',13,'(N)']],...
		'ForeGround',1,...
		'BackGround',2,...
		'Time','.05',...
		'After','.1',...
		'position',[335,135,355,155])

add_block('built-in/Mux',[sys,'/','Mux'])
set_param([sys,'/','Mux'],...
		'BackGround',3,...
		'hide name',0,...
		'inputs','2',...
		'position',[425,124,450,151])

add_block('built-in/Constant',[sys,'/',['output equilibrium',13,'bias']])
set_param([sys,'/',['output equilibrium',13,'bias']],...
		'ForeGround',1,...
		'BackGround',5,...
		'move name',0,...
		'Value','Xo',...
		'position',[435,190,455,220])

add_block('built-in/Sum',[sys,'/','Sum2'])
set_param([sys,'/','Sum2'],...
		'ForeGround',1,...
		'BackGround',5,...
		'hide name',0,...
		'position',[480,209,495,231])

add_block('built-in/To Workspace',[sys,'/','To Workspace'])
set_param([sys,'/','To Workspace'],...
		'BackGround',3,...
		'mat-name','y_lin',...
		'buffer','2000',...
		'position',[520,269,555,291])


%     Subsystem  'position (m)'.

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

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

add_block('built-in/S-Function',[sys,'/',['position (m)/S-function',13,'M-file which plots',13,'lines',13,'']])
set_param([sys,'/',['position (m)/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 (m)'],[90,65;125,65])
set_param([sys,'/','position (m)'],...
		'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 (m)'],...
		'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 (m)'],...
		'Mask Translate','npts = @4; color = @5; ax = [0, @1, @2, @3]; dt=-1;')
set_param([sys,'/','position (m)'],...
		'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 (m)'],...
		'Mask Entries','tf\/0.005\/.015\/2000\/''y-/g--/c-./w:/m*/ro/b+''\/')


%     Finished composite block 'position (m)'.

set_param([sys,'/','position (m)'],...
		'BackGround',3,...
		'move name',0,...
		'position',[520,200,550,240])


%     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\/1000\/''y-/g--/c-./w:/m*/ro/b+''\/')


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

set_param([sys,'/',['control  and',13,'disturbance']],...
		'BackGround',3,...
		'move name',0,...
		'position',[520,120,550,160])


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

new_system([sys,'/',['Electromagnet',13,'(Linear)']])
set_param([sys,'/',['Electromagnet',13,'(Linear)']],'Location',[264,83,730,279])

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

add_block('built-in/Mux',[sys,'/',['Electromagnet',13,'(Linear)/Mux']])
set_param([sys,'/',['Electromagnet',13,'(Linear)/Mux']],...
		'inputs','2',...
		'position',[155,91,185,124])

add_block('built-in/Inport',[sys,'/',['Electromagnet',13,'(Linear)/disturbance']])
set_param([sys,'/',['Electromagnet',13,'(Linear)/disturbance']],...
		'move name',0,...
		'position',[70,90,90,110])

add_block('built-in/Inport',[sys,'/',['Electromagnet',13,'(Linear)/electromagnet',13,'voltage']])
set_param([sys,'/',['Electromagnet',13,'(Linear)/electromagnet',13,'voltage']],...
		'Port','2',...
		'position',[70,120,90,140])

add_block('built-in/State-Space',[sys,'/',['Electromagnet',13,'(Linear)/State-Space']])
set_param([sys,'/',['Electromagnet',13,'(Linear)/State-Space']],...
		'A','A',...
		'B','B',...
		'C','C',...
		'D','D',...
		'position',[215,89,290,131])

add_block('built-in/Outport',[sys,'/',['Electromagnet',13,'(Linear)/suspended',13,'object',13,'position']])
set_param([sys,'/',['Electromagnet',13,'(Linear)/suspended',13,'object',13,'position']],...
		'position',[335,100,355,120])
add_line([sys,'/',['Electromagnet',13,'(Linear)']],[95,100;150,100])
add_line([sys,'/',['Electromagnet',13,'(Linear)']],[95,130;105,130;105,115;150,115])
add_line([sys,'/',['Electromagnet',13,'(Linear)']],[190,110;210,110])
add_line([sys,'/',['Electromagnet',13,'(Linear)']],[295,110;330,110])


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

set_param([sys,'/',['Electromagnet',13,'(Linear)']],...
		'BackGround',6,...
		'Drop Shadow',4,...
		'position',[395,195,425,250])

add_block('built-in/Gain',[sys,'/','Sensor'])
set_param([sys,'/','Sensor'],...
		'orientation',2,...
		'BackGround',6,...
		'Gain','beta',...
		'position',[300,274,350,306])

add_block('built-in/Note',[sys,'/','Magnetic  Suspension System: Linear Model'])
set_param([sys,'/','Magnetic  Suspension System: Linear Model'],...
		'Font Name','helvetica',...
		'Font Weight','bold',...
		'Font Angle','oblique',...
		'Font Size',18,...
		'position',[275,20,280,25])


%     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',[18,84,69,111])

add_block('built-in/Gain',[sys,'/','K'])
set_param([sys,'/','K'],...
		'ForeGround',1,...
		'BackGround',4,...
		'Gain','-172',...
		'position',[205,219,235,251])

add_block('built-in/Transfer Fcn',[sys,'/','Controller'])
set_param([sys,'/','Controller'],...
		'ForeGround',1,...
		'BackGround',4,...
		'Numerator','[1 30]',...
		'Denominator','[1 300]',...
		'position',[250,214,295,256])
add_line(sys,[430,225;455,225;455,290;355,290])
add_line(sys,[360,145;420,145])
add_line(sys,[455,140;515,140])
add_line(sys,[190,235;200,235])
add_line(sys,[240,235;245,235])
add_line(sys,[300,235;390,235])
add_line(sys,[160,230;165,230])
add_line(sys,[105,230;110,230])
add_line(sys,[55,250;65,250;65,235;80,235])
add_line(sys,[55,205;70,205;80,225])
add_line(sys,[500,220;515,220])
add_line(sys,[455,225;475,225])
add_line(sys,[460,205;460,215;475,215])
add_line(sys,[500,220;500,280;515,280])
add_line(sys,[380,145;390,210])
add_line(sys,[295,290;155,290;165,240])
add_line(sys,[300,235;300,130;420,130])

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
