function Fy=Fy_Pacejka(x,varargin)

%Fy_Pacjeka
%
%  Fy = Fy_Pacjeka(x,B,C,D,E) reutrns the value of the magic
%  formula tire model given by:
%
%     Fy =  -D*sin(C*atan(B*((1-E)*x+(E/B)*atan(B*x))));
%
%  Fy = Fy_Pacjeka(x,B,C,D,E,Sh,Sv) reutrns the value of the 
%  magic formula tire model given by:
%
%     Fy =  -D*sin(C*atan(B*((1-E)*(x+Sh)+(E/B)*atan(B*(x+Sh)))))-Sv;
%

% Version 1.2
% Chris Gerdes 
% Dynamic Design Lab
% Stanford University
% 4/6/2002
% Function for use with ME106/227
% This revised version also includes camber angle change.

if (nargin == 5)
   B = varargin{1};
   C = varargin{2};
   D = varargin{3};
   E = varargin{4};
   Fy =  -D*sin(C*atan(B*((1-E)*x+(E/B)*atan(B*x))));
elseif (nargin == 7)
   B = varargin{1};
   C = varargin{2};
   D = varargin{3};
   E = varargin{4};
   Sh = varargin{5};
   Sv = varargin{6};
   Fy =  -D*sin(C*atan(B*((1-E)*(x+Sh)+(E/B)*atan(B*(x+Sh)))))-Sv;
else
   error('Incorrect number of parameters sent to Fy_Pacejka');
end