function xdot = Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF(time,x)
%  synopsis:
%     xdot = Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF (time, x)
%     x0 = Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF
%
%  Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF can be used with odeN functions as follows:
%
%  x0 = Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF;
%  [t,x] = ode23s(@Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF, [0 100], Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF);
%  plot (t,x);
%
%  where 100 is the end time
%
%  When Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF is used without any arguments it returns a vector of
%  the initial concentrations of the 22 floating species.
%  Otherwise Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF should be called with two arguments:
%  time and x.  time is the current time. x is the vector of the
%  concentrations of the 22 floating species.
%  When these parameters are supplied Goldbeter2008_Somite_Segmentation_Clock_Notch_Wnt_FGF returns a vector of 
%  the rates of change of the concentrations of the 22 floating species.
%
%  the following table shows the mapping between the vector
%  index of a floating species and the species name.
%  
%  NOTE for compartmental models
%  matlab translator generates code that when simulated in matlab, 
%  produces results which have the units of species amounts. Users 
%  should divide the results for each species with the volume of the
%  compartment it resides in, in order to obtain concentrations.
%  
%  Indx      Name
%  x(1)        N
%  x(2)        Na
%  x(3)        Nan
%  x(4)        MF
%  x(5)        F
%  x(6)        Bp
%  x(7)        BN
%  x(8)        A
%  x(9)        K
%  x(10)        B
%  x(11)        MAx
%  x(12)        Rasa
%  x(13)        ERKa
%  x(14)        Xa
%  x(15)        MDusp
%  x(16)        Dusp
%  x(17)        Rast
%  x(18)        ERKt
%  x(19)        Xt
%  x(20)        D
%  x(21)        Kt
%  x(22)        Fgf

xdot = zeros(22, 1);

% List of Compartments 
vol__cytosol = 1;		%cytosol

% Global Parameters 
g_p1 = 3;		% vsF
g_p2 = 2.5;		% KIG1
g_p3 = 0;		% vsFK
g_p4 = 0.3;		% epsilon
g_p5 = 0.23;		% vsN
g_p6 = 2.82;		% vdN
g_p7 = 1.4;		% KdN
g_p8 = 3.45;		% kc
g_p9 = 0.5;		% KIF
g_p10 = 2;		% j
g_p11 = 0.01;		% VdNa
g_p12 = 0.001;		% KdNa
g_p13 = 0.1;		% kt1
g_p14 = 0.1;		% kt2
g_p15 = 0.1;		% VdNan
g_p16 = 0.001;		% KdNan
g_p17 = 2;		% p
g_p18 = 0.05;		% KA
g_p19 = 1.92;		% vmF
g_p20 = 0.768;		% KdMF
g_p21 = 0.3;		% ksF
g_p22 = 0.39;		% vdF
g_p23 = 0.37;		% KdF
g_p24 = 1.5;		% theta
g_p25 = 0.1;		% d1
g_p26 = 1.8;		% a1
g_p27 = 0.087;		% vsB
g_p28 = 0;		% kd1
g_p29 = 5.08;		% VMK
g_p30 = 0.5;		% KID
g_p31 = 0.28;		% K1
g_p32 = 1;		% VMP
g_p33 = 0.03;		% K2
g_p34 = 1.5;		% kt4
g_p35 = 0.7;		% kt3
g_p36 = 7.062;		% kd2
g_p37 = 0.06;		% v0
g_p38 = 1.64;		% vMB
g_p39 = 2;		% n
g_p40 = 0.7;		% KaB
g_p41 = 0.5;		% vMXa
g_p42 = 2;		% m
g_p43 = 0.05;		% KaXa
g_p44 = 0.8;		% vmd
g_p45 = 0.48;		% Kmd
g_p46 = 0.02;		% ksAx
g_p47 = 0.6;		% vdAx
g_p48 = 0.63;		% KdAx
g_p49 = 0.3;		% eta
g_p50 = 4.968;		% VMaRas
g_p51 = 2;		% r
g_p52 = 0.5;		% KaFgf
g_p53 = 0.103;		% KaRas
g_p54 = 0.41;		% VMdRas
g_p55 = 0.1;		% KdRas
g_p56 = 3.3;		% VMaErk
g_p57 = 0.05;		% KaErk
g_p58 = 1.35;		% kcDusp
g_p59 = 0.05;		% KdErk
g_p60 = 1.6;		% VMaX
g_p61 = 0.05;		% KaX
g_p62 = 0.5;		% VMdX
g_p63 = 0.05;		% KdX
g_p64 = 0.9;		% VMsMDusp
g_p65 = 2;		% q
g_p66 = 0.5;		% KaMDusp
g_p67 = 0.5;		% VMdMDusp
g_p68 = 0.5;		% KdMDusp
g_p69 = 0.5;		% ksDusp
g_p70 = 2;		% vdDusp
g_p71 = 0.5;		% KdDusp

% Boundary Conditions 
g_p72 = 0;		% Rasi = Rasi[Concentration]
g_p73 = 0;		% ERKi = ERKi[Concentration]
g_p74 = 0;		% Xi = Xi[Concentration]
g_p75 = 0;		% AK = AK[Concentration]
g_p76 = 0;		% __src__ = __src__[Concentration]
g_p77 = 0;		% __waste__ = __waste__[Concentration]

% Local Parameters

if (nargin == 0)

    % set initial conditions
   xdot(1) = 0.5*vol__cytosol;		% N = N [Concentration]
   xdot(2) = 0.2*vol__cytosol;		% Na = Na [Concentration]
   xdot(3) = 0*vol__cytosol;		% Nan = Nan [Concentration]
   xdot(4) = 0.1*vol__cytosol;		% MF = MF [Concentration]
   xdot(5) = 0.001*vol__cytosol;		% F = F [Concentration]
   xdot(6) = 0.1*vol__cytosol;		% Bp = Bp [Concentration]
   xdot(7) = 0.001*vol__cytosol;		% BN = BN [Concentration]
   xdot(8) = 0.1*vol__cytosol;		% A = A [Concentration]
   xdot(9) = 3*vol__cytosol;		% K = K [Concentration]
   xdot(10) = 0.1*vol__cytosol;		% B = B [Concentration]
   xdot(11) = 0.1*vol__cytosol;		% MAx = MAx [Concentration]
   xdot(12) = 0.5*vol__cytosol;		% Rasa = Rasa [Concentration]
   xdot(13) = 0.2*vol__cytosol;		% ERKa = ERKa [Concentration]
   xdot(14) = 0.1*vol__cytosol;		% Xa = Xa [Concentration]
   xdot(15) = 0.1*vol__cytosol;		% MDusp = MDusp [Concentration]
   xdot(16) = 0.1*vol__cytosol;		% Dusp = Dusp [Concentration]
   xdot(17) = 2*vol__cytosol;		% Rast = Rast [Concentration]
   xdot(18) = 2*vol__cytosol;		% ERKt = ERKt [Concentration]
   xdot(19) = 2*vol__cytosol;		% Xt = Xt [Concentration]
   xdot(20) = 2*vol__cytosol;		% D = D [Concentration]
   xdot(21) = 3*vol__cytosol;		% Kt = Kt [Concentration]
   xdot(22) = 1*vol__cytosol;		% Fgf = Fgf [Concentration]

else

    % listOfRules
   g_p3 = g_p1*(g_p2/(g_p2+(x(9))));
   (g_p75) = (x(21))-(x(9));
   (g_p72) = (x(17))-(x(12));
   (g_p73) = (x(18))-(x(13));
   (g_p74) = (x(19))-(x(14));

    % calculate rates of change
   R0 = vol__cytosol*g_p4*g_p5;
   R1 = g_p4*vol__cytosol*g_p6*(x(1))/(g_p7+(x(1)));
   R2 = g_p4*vol__cytosol*g_p8*(x(1))*pow(g_p9,g_p10)/(pow(g_p9,g_p10)+pow((x(5)),g_p10));
   R3 = g_p4*vol__cytosol*g_p11*(x(2))/(g_p12+(x(2)));
   R4 = g_p4*vol__cytosol*(g_p13*(x(2))-g_p14*NaN);
   R5 = g_p4*vol__cytosol*g_p15*NaN/(g_p16+NaN);
   R6 = g_p4*vol__cytosol*g_p3*pow(NaN,g_p17)/(pow(g_p18,g_p17)+pow(NaN,g_p17));
   R7 = g_p4*vol__cytosol*g_p19*(x(4))/(g_p20+(x(4)));
   R8 = g_p4*vol__cytosol*g_p21*(x(4));
   R9 = g_p4*vol__cytosol*g_p22*(x(5))/(g_p23+(x(5)));
   R10 = g_p24*vol__cytosol*(g_p25*(g_p75)-g_p26*(x(8))*(x(9)));
   R11 = g_p24*vol__cytosol*g_p27;
   R12 = g_p24*vol__cytosol*g_p28*(x(10));
   R13 = g_p24*vol__cytosol*g_p29*g_p30/(g_p30+(x(20)))*(x(10))/(g_p31+(x(10)))*(g_p75)/(x(21));
   R14 = g_p24*vol__cytosol*g_p32*(x(6))/(g_p33+(x(6)));
   R15 = g_p24*vol__cytosol*(g_p34*(x(7))-g_p35*(x(10)));
   R16 = g_p24*vol__cytosol*g_p36*(x(6));
   R17 = g_p24*vol__cytosol*g_p37;
   R18 = g_p24*vol__cytosol*(g_p38*pow((x(7)),g_p39)/(pow(g_p40,g_p39)+pow((x(7)),g_p39)));
   R19 = g_p24*vol__cytosol*(g_p41*pow((x(14)),g_p42)/(pow(g_p43,g_p42)+pow((x(14)),g_p42)));
   R20 = g_p24*vol__cytosol*g_p44*(x(11))/(g_p45+(x(11)));
   R21 = g_p24*vol__cytosol*g_p46*(x(11));
   R22 = g_p24*vol__cytosol*g_p47*(x(8))/(g_p48+(x(8)));
   R23 = g_p49*vol__cytosol*g_p50*pow((x(22)),g_p51)/(pow(g_p52,g_p51)+pow((x(22)),g_p51))*(g_p72)/(g_p53+(g_p72));
   R24 = g_p49*vol__cytosol*g_p54*(x(12))/(g_p55+(x(12)));
   R25 = g_p49*vol__cytosol*g_p56*(x(12))/(x(17))*(g_p73)/(g_p57+(g_p73));
   R26 = g_p49*vol__cytosol*g_p58*(x(16))*(x(13))/(g_p59+(x(13)));
   R27 = g_p49*vol__cytosol*g_p60*(x(13))/(x(18))*(g_p74)/(g_p61+(g_p74));
   R28 = g_p49*vol__cytosol*g_p62*(x(14))/(g_p63+(x(14)));
   R29 = g_p49*vol__cytosol*g_p64*pow((x(14)),g_p65)/(pow(g_p66,g_p65)+pow((x(14)),g_p65));
   R30 = g_p49*vol__cytosol*g_p67*(x(15))/(g_p68+(x(15)));
   R31 = g_p49*vol__cytosol*g_p69*(x(15));
   R32 = g_p49*vol__cytosol*g_p70*(x(16))/(g_p71+(x(16)));

   xdot = [
      + R0 - R1 - R2
      + R2 - R3 - R4
      + R4 - R5
      + R6 - R7
      + R8 - R9
      + R13 - R14 - R16
      - R15
      + R10 + R21 - R22
      + R10
      + R11 - R12 - R13 + R14 + R15
      + R17 + R18 + R19 - R20
      + R23 - R24
      + R25 - R26
      + R27 - R28
      + R29 - R30
      + R31 - R32
        0
        0
        0
        0
        0
        0
   ];
end;


function z = pow (x, y) 
    z = x^y; 


function z = sqr (x) 
    z = x*x; 


function z = piecewise(varargin) 
		numArgs = nargin; 
		result = 0; 
		foundResult = 0; 
		for k=1:2: numArgs-1 
			if varargin{k+1} == 1 
				result = varargin{k}; 
				foundResult = 1; 
				break; 
			end 
		end 
		if foundResult == 0 
			result = varargin{numArgs}; 
		end 
		z = result; 


function z = gt(a,b) 
   if a > b 
   	  z = 1; 
   else 
      z = 0; 
   end 


function z = lt(a,b) 
   if a < b 
   	  z = 1; 
   else 
      z = 0; 
   end 


function z = geq(a,b) 
   if a >= b 
   	  z = 1; 
   else 
      z = 0; 
   end 


function z = leq(a,b) 
   if a <= b 
   	  z = 1; 
   else 
      z = 0; 
   end 


function z = eq(a,b) 
   if a == b 
   	  z = 1; 
   else 
      z = 0; 
   end 


function z = neq(a,b) 
   if a ~= b 
   	  z = 1; 
   else 
      z = 0; 
   end 


function z = and(varargin) 
		result = 1;		 
		for k=1:nargin 
		   if varargin{k} ~= 1 
		      result = 0; 
		      break; 
		   end 
		end 
		z = result; 


function z = or(varargin) 
		result = 0;		 
		for k=1:nargin 
		   if varargin{k} ~= 0 
		      result = 1; 
		      break; 
		   end 
		end 
		z = result; 


function z = xor(varargin) 
		foundZero = 0; 
		foundOne = 0; 
		for k = 1:nargin 
			if varargin{k} == 0 
			   foundZero = 1; 
			else 
			   foundOne = 1; 
			end 
		end 
		if foundZero && foundOne 
			z = 1; 
		else 
		  z = 0; 
		end 
		 


function z = not(a) 
   if a == 1 
   	  z = 0; 
   else 
      z = 1; 
   end 


function z = root(a,b) 
	z = a^(1/b); 
 
