Generated Code

The following is matlab code generated by the CellML API from this CellML file. (Back to language selection)

The raw code is available.

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = mainFunction()
    % This is the "main function".  In Matlab, things work best if you rename this function to match the filename.
   [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel();
end

function [algebraicVariableCount] = getAlgebraicVariableCount() 
    % Used later when setting a global variable with the number of algebraic variables.
    % Note: This is not the "main method".  
    algebraicVariableCount =18;
end
% There are a total of 16 entries in each of the rate and state variable arrays.
% There are a total of 76 entries in the constant variable array.
%

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel()
    % Create ALGEBRAIC of correct size
    global algebraicVariableCount;  algebraicVariableCount = getAlgebraicVariableCount();
    % Initialise constants and state variables
    [INIT_STATES, CONSTANTS] = initConsts;

    % Set timespan to solve over 
    tspan = [0, 10];

    % Set numerical accuracy options for ODE solver
    options = odeset('RelTol', 1e-06, 'AbsTol', 1e-06, 'MaxStep', 1);

    % Solve model with ODE solver
    [VOI, STATES] = ode15s(@(VOI, STATES)computeRates(VOI, STATES, CONSTANTS), tspan, INIT_STATES, options);

    % Compute algebraic variables
    [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS);
    ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI);

    % Plot state variables against variable of integration
    [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends();
    figure();
    plot(VOI, STATES);
    xlabel(LEGEND_VOI);
    l = legend(LEGEND_STATES);
    set(l,'Interpreter','none');
end

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (minute)');
    LEGEND_STATES(:,1) = strpad('N in component N (nanomolar)');
    LEGEND_CONSTANTS(:,1) = strpad('KdN in component N (nanomolar)');
    LEGEND_CONSTANTS(:,2) = strpad('vsN in component N (flux)');
    LEGEND_CONSTANTS(:,3) = strpad('vdN in component N (flux)');
    LEGEND_CONSTANTS(:,4) = strpad('kc in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,5) = strpad('KIF in component model_parameters (nanomolar)');
    LEGEND_STATES(:,2) = strpad('F in component F (nanomolar)');
    LEGEND_CONSTANTS(:,6) = strpad('epsilon in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,7) = strpad('j in component model_parameters (dimensionless)');
    LEGEND_STATES(:,3) = strpad('Na in component Na (nanomolar)');
    LEGEND_ALGEBRAIC(:,1) = strpad('Vtr in component Na (flux)');
    LEGEND_CONSTANTS(:,8) = strpad('KdNa in component Na (nanomolar)');
    LEGEND_CONSTANTS(:,9) = strpad('VdNa in component Na (flux)');
    LEGEND_CONSTANTS(:,10) = strpad('kt1 in component Na (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,11) = strpad('kt2 in component Na (first_order_rate_constant)');
    LEGEND_STATES(:,4) = strpad('Nan in component Nan (nanomolar)');
    LEGEND_CONSTANTS(:,12) = strpad('KdNan in component Nan (nanomolar)');
    LEGEND_CONSTANTS(:,13) = strpad('VdNan in component Nan (flux)');
    LEGEND_STATES(:,5) = strpad('MF in component MF (nanomolar)');
    LEGEND_CONSTANTS(:,14) = strpad('KdMF in component MF (nanomolar)');
    LEGEND_CONSTANTS(:,15) = strpad('KIG1 in component MF (nanomolar)');
    LEGEND_ALGEBRAIC(:,2) = strpad('vsFK in component MF (flux)');
    LEGEND_CONSTANTS(:,16) = strpad('vsF in component MF (flux)');
    LEGEND_CONSTANTS(:,17) = strpad('vmF in component MF (flux)');
    LEGEND_CONSTANTS(:,18) = strpad('KA in component MF (nanomolar)');
    LEGEND_STATES(:,6) = strpad('K in component K (nanomolar)');
    LEGEND_CONSTANTS(:,19) = strpad('p in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,20) = strpad('KdF in component F (nanomolar)');
    LEGEND_CONSTANTS(:,21) = strpad('vdF in component F (flux)');
    LEGEND_CONSTANTS(:,22) = strpad('ksF in component F (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,8) = strpad('V1 in component Wnt_parameters (flux)');
    LEGEND_CONSTANTS(:,23) = strpad('theta in component model_parameters (dimensionless)');
    LEGEND_STATES(:,7) = strpad('B in component B (nanomolar)');
    LEGEND_CONSTANTS(:,24) = strpad('kd1 in component B (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,25) = strpad('vsB in component B (flux)');
    LEGEND_ALGEBRAIC(:,14) = strpad('VK in component Wnt_parameters (flux)');
    LEGEND_ALGEBRAIC(:,18) = strpad('VP in component Wnt_parameters (flux)');
    LEGEND_ALGEBRAIC(:,9) = strpad('V2 in component Wnt_parameters (flux)');
    LEGEND_CONSTANTS(:,26) = strpad('Kt in component Wnt_parameters (nanomolar)');
    LEGEND_ALGEBRAIC(:,3) = strpad('AK in component Wnt_parameters (nanomolar)');
    LEGEND_STATES(:,8) = strpad('Bp in component Bp (nanomolar)');
    LEGEND_CONSTANTS(:,27) = strpad('kd2 in component Bp (first_order_rate_constant)');
    LEGEND_STATES(:,9) = strpad('BN in component BN (nanomolar)');
    LEGEND_STATES(:,10) = strpad('MAx in component MAx (nanomolar)');
    LEGEND_CONSTANTS(:,28) = strpad('v0 in component MAx (flux)');
    LEGEND_CONSTANTS(:,29) = strpad('vMB in component MAx (flux)');
    LEGEND_CONSTANTS(:,30) = strpad('vmd in component MAx (flux)');
    LEGEND_CONSTANTS(:,31) = strpad('KaB in component MAx (nanomolar)');
    LEGEND_CONSTANTS(:,32) = strpad('KaXa in component MAx (nanomolar)');
    LEGEND_CONSTANTS(:,33) = strpad('Kmd in component MAx (nanomolar)');
    LEGEND_CONSTANTS(:,34) = strpad('n in component MAx (dimensionless)');
    LEGEND_CONSTANTS(:,35) = strpad('m in component MAx (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('vMXa in component MAx (flux)');
    LEGEND_STATES(:,11) = strpad('Xa in component Xa (nanomolar)');
    LEGEND_STATES(:,12) = strpad('A in component A (nanomolar)');
    LEGEND_CONSTANTS(:,37) = strpad('ksAx in component A (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,38) = strpad('vdAx in component A (flux)');
    LEGEND_CONSTANTS(:,39) = strpad('KdAx in component A (nanomolar)');
    LEGEND_CONSTANTS(:,40) = strpad('d1 in component Wnt_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,41) = strpad('a1 in component Wnt_parameters (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,42) = strpad('K1 in component Wnt_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,43) = strpad('K2 in component Wnt_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,44) = strpad('D in component Wnt_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,45) = strpad('KID in component Wnt_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,46) = strpad('kt3 in component Wnt_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,47) = strpad('kt4 in component Wnt_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,48) = strpad('VMK in component Wnt_parameters (flux)');
    LEGEND_CONSTANTS(:,49) = strpad('VMP in component Wnt_parameters (flux)');
    LEGEND_STATES(:,13) = strpad('Rasa in component Rasa (nanomolar)');
    LEGEND_ALGEBRAIC(:,10) = strpad('VaRas in component FGF_parameters (flux)');
    LEGEND_ALGEBRAIC(:,15) = strpad('VdRas in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,50) = strpad('eta in component model_parameters (dimensionless)');
    LEGEND_STATES(:,14) = strpad('ERKa in component ERKa (nanomolar)');
    LEGEND_ALGEBRAIC(:,11) = strpad('VaErk in component FGF_parameters (flux)');
    LEGEND_ALGEBRAIC(:,16) = strpad('VdErk in component FGF_parameters (flux)');
    LEGEND_ALGEBRAIC(:,12) = strpad('VaX in component FGF_parameters (flux)');
    LEGEND_ALGEBRAIC(:,17) = strpad('VdX in component FGF_parameters (flux)');
    LEGEND_STATES(:,15) = strpad('MDusp in component MDusp (nanomolar)');
    LEGEND_ALGEBRAIC(:,7) = strpad('VsMDusp in component FGF_parameters (flux)');
    LEGEND_ALGEBRAIC(:,13) = strpad('VdMDusp in component FGF_parameters (flux)');
    LEGEND_STATES(:,16) = strpad('Dusp in component Dusp (nanomolar)');
    LEGEND_CONSTANTS(:,51) = strpad('ksDusp in component Dusp (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,52) = strpad('vdDusp in component Dusp (flux)');
    LEGEND_CONSTANTS(:,53) = strpad('KdDusp in component Dusp (nanomolar)');
    LEGEND_ALGEBRAIC(:,4) = strpad('Rasi in component FGF_parameters (nanomolar)');
    LEGEND_ALGEBRAIC(:,5) = strpad('ERKi in component FGF_parameters (nanomolar)');
    LEGEND_ALGEBRAIC(:,6) = strpad('Xi in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,54) = strpad('Rast in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,55) = strpad('ERKt in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,56) = strpad('Xt in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,57) = strpad('kcDusp in component FGF_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,58) = strpad('VMaRas in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,59) = strpad('VMdRas in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,60) = strpad('VMaErk in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,61) = strpad('VMaX in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,62) = strpad('VMdX in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,63) = strpad('VMsMDusp in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,64) = strpad('VMdMDusp in component FGF_parameters (flux)');
    LEGEND_CONSTANTS(:,65) = strpad('Fgf in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,66) = strpad('KaFgf in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,67) = strpad('KaRas in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,68) = strpad('KdRas in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,69) = strpad('KdErk in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,70) = strpad('KaErk in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,71) = strpad('KaX in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,72) = strpad('KdX in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,73) = strpad('KaMDusp in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,74) = strpad('KdMDusp in component FGF_parameters (nanomolar)');
    LEGEND_CONSTANTS(:,75) = strpad('q in component FGF_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,76) = strpad('r in component FGF_parameters (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt N in component N (nanomolar)');
    LEGEND_RATES(:,3) = strpad('d/dt Na in component Na (nanomolar)');
    LEGEND_RATES(:,4) = strpad('d/dt Nan in component Nan (nanomolar)');
    LEGEND_RATES(:,5) = strpad('d/dt MF in component MF (nanomolar)');
    LEGEND_RATES(:,2) = strpad('d/dt F in component F (nanomolar)');
    LEGEND_RATES(:,6) = strpad('d/dt K in component K (nanomolar)');
    LEGEND_RATES(:,7) = strpad('d/dt B in component B (nanomolar)');
    LEGEND_RATES(:,8) = strpad('d/dt Bp in component Bp (nanomolar)');
    LEGEND_RATES(:,9) = strpad('d/dt BN in component BN (nanomolar)');
    LEGEND_RATES(:,10) = strpad('d/dt MAx in component MAx (nanomolar)');
    LEGEND_RATES(:,12) = strpad('d/dt A in component A (nanomolar)');
    LEGEND_RATES(:,13) = strpad('d/dt Rasa in component Rasa (nanomolar)');
    LEGEND_RATES(:,14) = strpad('d/dt ERKa in component ERKa (nanomolar)');
    LEGEND_RATES(:,11) = strpad('d/dt Xa in component Xa (nanomolar)');
    LEGEND_RATES(:,15) = strpad('d/dt MDusp in component MDusp (nanomolar)');
    LEGEND_RATES(:,16) = strpad('d/dt Dusp in component Dusp (nanomolar)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    STATES(:,1) = 0.5;
    CONSTANTS(:,1) = 1.4;
    CONSTANTS(:,2) = 0.23;
    CONSTANTS(:,3) = 2.82;
    CONSTANTS(:,4) = 3.45;
    CONSTANTS(:,5) = 0.5;
    STATES(:,2) = 0.001;
    CONSTANTS(:,6) = 0.3;
    CONSTANTS(:,7) = 2.0;
    STATES(:,3) = 0.2;
    CONSTANTS(:,8) = 0.001;
    CONSTANTS(:,9) = 0.01;
    CONSTANTS(:,10) = 0.1;
    CONSTANTS(:,11) = 0.1;
    STATES(:,4) = 0.0;
    CONSTANTS(:,12) = 0.001;
    CONSTANTS(:,13) = 0.1;
    STATES(:,5) = 0.1;
    CONSTANTS(:,14) = 0.768;
    CONSTANTS(:,15) = 2.5;
    CONSTANTS(:,16) = 3.0;
    CONSTANTS(:,17) = 1.92;
    CONSTANTS(:,18) = 0.05;
    STATES(:,6) = 3.0;
    CONSTANTS(:,19) = 2.0;
    CONSTANTS(:,20) = 0.37;
    CONSTANTS(:,21) = 0.39;
    CONSTANTS(:,22) = 0.3;
    CONSTANTS(:,23) = 1.5;
    STATES(:,7) = 0.1;
    CONSTANTS(:,24) = 0.0;
    CONSTANTS(:,25) = 0.087;
    CONSTANTS(:,26) = 3.0;
    STATES(:,8) = 0.1;
    CONSTANTS(:,27) = 7.062;
    STATES(:,9) = 0.001;
    STATES(:,10) = 0.1;
    CONSTANTS(:,28) = 0.06;
    CONSTANTS(:,29) = 1.64;
    CONSTANTS(:,30) = 0.8;
    CONSTANTS(:,31) = 0.7;
    CONSTANTS(:,32) = 0.05;
    CONSTANTS(:,33) = 0.48;
    CONSTANTS(:,34) = 2.0;
    CONSTANTS(:,35) = 2.0;
    CONSTANTS(:,36) = 0.5;
    STATES(:,11) = 0.1;
    STATES(:,12) = 0.1;
    CONSTANTS(:,37) = 0.02;
    CONSTANTS(:,38) = 0.6;
    CONSTANTS(:,39) = 0.63;
    CONSTANTS(:,40) = 0.1;
    CONSTANTS(:,41) = 1.8;
    CONSTANTS(:,42) = 0.28;
    CONSTANTS(:,43) = 0.03;
    CONSTANTS(:,44) = 2.0;
    CONSTANTS(:,45) = 0.5;
    CONSTANTS(:,46) = 0.7;
    CONSTANTS(:,47) = 1.5;
    CONSTANTS(:,48) = 5.08;
    CONSTANTS(:,49) = 1.0;
    STATES(:,13) = 0.5;
    CONSTANTS(:,50) = 0.3;
    STATES(:,14) = 0.2;
    STATES(:,15) = 0.1;
    STATES(:,16) = 0.1;
    CONSTANTS(:,51) = 0.5;
    CONSTANTS(:,52) = 2.0;
    CONSTANTS(:,53) = 0.5;
    CONSTANTS(:,54) = 2.0;
    CONSTANTS(:,55) = 2.0;
    CONSTANTS(:,56) = 2.0;
    CONSTANTS(:,57) = 1.35;
    CONSTANTS(:,58) = 4.968;
    CONSTANTS(:,59) = 0.41;
    CONSTANTS(:,60) = 3.30;
    CONSTANTS(:,61) = 1.6;
    CONSTANTS(:,62) = 0.5;
    CONSTANTS(:,63) = 0.9;
    CONSTANTS(:,64) = 0.5;
    CONSTANTS(:,65) = 1.0;
    CONSTANTS(:,66) = 0.5;
    CONSTANTS(:,67) = 0.103;
    CONSTANTS(:,68) = 0.1;
    CONSTANTS(:,69) = 0.05;
    CONSTANTS(:,70) = 0.05;
    CONSTANTS(:,71) = 0.05;
    CONSTANTS(:,72) = 0.05;
    CONSTANTS(:,73) = 0.5;
    CONSTANTS(:,74) = 0.5;
    CONSTANTS(:,75) = 2.0;
    CONSTANTS(:,76) = 2.0;
    if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
    global algebraicVariableCount;
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        ALGEBRAIC = zeros(1, algebraicVariableCount);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    RATES(:,1) =  CONSTANTS(:,6).*(CONSTANTS(:,2) - ( CONSTANTS(:,3).*(STATES(:,1)./(CONSTANTS(:,1)+STATES(:,1)))+ CONSTANTS(:,4).*STATES(:,1).*(power(CONSTANTS(:,5), CONSTANTS(:,7))./(power(CONSTANTS(:,5), CONSTANTS(:,7))+power(STATES(:,2), CONSTANTS(:,7))))));
    RATES(:,2) =  CONSTANTS(:,6).*( CONSTANTS(:,22).*STATES(:,5) -  CONSTANTS(:,21).*(STATES(:,2)./(CONSTANTS(:,20)+STATES(:,2))));
    RATES(:,10) =  CONSTANTS(:,23).*((CONSTANTS(:,28)+ CONSTANTS(:,29).*(power(STATES(:,9), CONSTANTS(:,34))./(power(CONSTANTS(:,31), CONSTANTS(:,34))+power(STATES(:,9), CONSTANTS(:,34))))+ CONSTANTS(:,36).*(power(STATES(:,11), CONSTANTS(:,35))./(power(CONSTANTS(:,32), CONSTANTS(:,35))+power(STATES(:,11), CONSTANTS(:,35))))) -  CONSTANTS(:,30).*(STATES(:,10)./(CONSTANTS(:,33)+STATES(:,10))));
    RATES(:,16) =  CONSTANTS(:,50).*( CONSTANTS(:,51).*STATES(:,15) -  CONSTANTS(:,52).*(STATES(:,16)./(CONSTANTS(:,53)+STATES(:,16))));
    ALGEBRAIC(:,1) =  CONSTANTS(:,10).*STATES(:,3) -  CONSTANTS(:,11).*STATES(:,4);
    RATES(:,3) =  CONSTANTS(:,6).*( CONSTANTS(:,4).*STATES(:,1).*(power(CONSTANTS(:,5), CONSTANTS(:,7))./(power(CONSTANTS(:,5), CONSTANTS(:,7))+power(STATES(:,2), CONSTANTS(:,7)))) - ( CONSTANTS(:,9).*(STATES(:,3)./(CONSTANTS(:,8)+STATES(:,3)))+ALGEBRAIC(:,1)));
    RATES(:,4) =  CONSTANTS(:,6).*(ALGEBRAIC(:,1) -  CONSTANTS(:,13).*(STATES(:,4)./(CONSTANTS(:,12)+STATES(:,4))));
    ALGEBRAIC(:,2) =  CONSTANTS(:,16).*(CONSTANTS(:,15)./(CONSTANTS(:,15)+STATES(:,6)));
    RATES(:,5) =  CONSTANTS(:,6).*( ALGEBRAIC(:,2).*(power(STATES(:,4), CONSTANTS(:,19))./(power(CONSTANTS(:,18), CONSTANTS(:,19))+power(STATES(:,4), CONSTANTS(:,19)))) -  CONSTANTS(:,17).*(STATES(:,5)./(CONSTANTS(:,14)+STATES(:,5))));
    ALGEBRAIC(:,3) = CONSTANTS(:,26) - STATES(:,6);
    ALGEBRAIC(:,8) =  CONSTANTS(:,40).*ALGEBRAIC(:,3) -  CONSTANTS(:,41).*STATES(:,12).*STATES(:,6);
    RATES(:,6) =  CONSTANTS(:,23).*ALGEBRAIC(:,8);
    ALGEBRAIC(:,9) =  CONSTANTS(:,47).*STATES(:,9) -  CONSTANTS(:,46).*STATES(:,7);
    RATES(:,9) =  - ( CONSTANTS(:,23).*ALGEBRAIC(:,9));
    RATES(:,12) =  CONSTANTS(:,23).*(( CONSTANTS(:,37).*STATES(:,10)+ALGEBRAIC(:,8)) -  CONSTANTS(:,38).*(STATES(:,12)./(CONSTANTS(:,39)+STATES(:,12))));
    ALGEBRAIC(:,7) =  CONSTANTS(:,63).*(power(STATES(:,11), CONSTANTS(:,75))./(power(CONSTANTS(:,73), CONSTANTS(:,75))+power(STATES(:,11), CONSTANTS(:,75))));
    ALGEBRAIC(:,13) =  CONSTANTS(:,64).*(STATES(:,15)./(CONSTANTS(:,74)+STATES(:,15)));
    RATES(:,15) =  CONSTANTS(:,50).*(ALGEBRAIC(:,7) - ALGEBRAIC(:,13));
    ALGEBRAIC(:,4) = CONSTANTS(:,54) - STATES(:,13);
    ALGEBRAIC(:,10) =  CONSTANTS(:,58).*(power(CONSTANTS(:,65), CONSTANTS(:,76))./(power(CONSTANTS(:,66), CONSTANTS(:,76))+power(CONSTANTS(:,65), CONSTANTS(:,76)))).*(ALGEBRAIC(:,4)./(CONSTANTS(:,67)+ALGEBRAIC(:,4)));
    ALGEBRAIC(:,15) =  CONSTANTS(:,59).*(STATES(:,13)./(CONSTANTS(:,68)+STATES(:,13)));
    RATES(:,13) =  CONSTANTS(:,50).*(ALGEBRAIC(:,10) - ALGEBRAIC(:,15));
    ALGEBRAIC(:,5) = CONSTANTS(:,55) - STATES(:,14);
    ALGEBRAIC(:,11) =  CONSTANTS(:,60).*(STATES(:,13)./CONSTANTS(:,54)).*(ALGEBRAIC(:,5)./(CONSTANTS(:,70)+ALGEBRAIC(:,5)));
    ALGEBRAIC(:,16) =  CONSTANTS(:,57).*STATES(:,16).*(STATES(:,14)./(CONSTANTS(:,69)+STATES(:,14)));
    RATES(:,14) =  CONSTANTS(:,50).*(ALGEBRAIC(:,11) - ALGEBRAIC(:,16));
    ALGEBRAIC(:,6) = CONSTANTS(:,56) - STATES(:,11);
    ALGEBRAIC(:,12) =  CONSTANTS(:,61).*(STATES(:,14)./CONSTANTS(:,55)).*(ALGEBRAIC(:,6)./(CONSTANTS(:,71)+ALGEBRAIC(:,6)));
    ALGEBRAIC(:,17) =  CONSTANTS(:,62).*(STATES(:,11)./(CONSTANTS(:,72)+STATES(:,11)));
    RATES(:,11) =  CONSTANTS(:,50).*(ALGEBRAIC(:,12) - ALGEBRAIC(:,17));
    ALGEBRAIC(:,14) =  CONSTANTS(:,48).*(CONSTANTS(:,45)./(CONSTANTS(:,45)+CONSTANTS(:,44))).*(STATES(:,7)./(CONSTANTS(:,42)+STATES(:,7)));
    ALGEBRAIC(:,18) =  CONSTANTS(:,49).*(STATES(:,8)./(CONSTANTS(:,43)+STATES(:,8)));
    RATES(:,7) =  CONSTANTS(:,23).*((CONSTANTS(:,25)+ALGEBRAIC(:,18)+ALGEBRAIC(:,9)) - ( ALGEBRAIC(:,14).*(ALGEBRAIC(:,3)./CONSTANTS(:,26))+ CONSTANTS(:,24).*STATES(:,7)));
    RATES(:,8) =  CONSTANTS(:,23).*( ALGEBRAIC(:,14).*(ALGEBRAIC(:,3)./CONSTANTS(:,26)) - (ALGEBRAIC(:,18)+ CONSTANTS(:,27).*STATES(:,8)));
   RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        utilOnes = ones(statesRowCount, 1);
    end
    ALGEBRAIC(:,1) =  CONSTANTS(:,10).*STATES(:,3) -  CONSTANTS(:,11).*STATES(:,4);
    ALGEBRAIC(:,2) =  CONSTANTS(:,16).*(CONSTANTS(:,15)./(CONSTANTS(:,15)+STATES(:,6)));
    ALGEBRAIC(:,3) = CONSTANTS(:,26) - STATES(:,6);
    ALGEBRAIC(:,8) =  CONSTANTS(:,40).*ALGEBRAIC(:,3) -  CONSTANTS(:,41).*STATES(:,12).*STATES(:,6);
    ALGEBRAIC(:,9) =  CONSTANTS(:,47).*STATES(:,9) -  CONSTANTS(:,46).*STATES(:,7);
    ALGEBRAIC(:,7) =  CONSTANTS(:,63).*(power(STATES(:,11), CONSTANTS(:,75))./(power(CONSTANTS(:,73), CONSTANTS(:,75))+power(STATES(:,11), CONSTANTS(:,75))));
    ALGEBRAIC(:,13) =  CONSTANTS(:,64).*(STATES(:,15)./(CONSTANTS(:,74)+STATES(:,15)));
    ALGEBRAIC(:,4) = CONSTANTS(:,54) - STATES(:,13);
    ALGEBRAIC(:,10) =  CONSTANTS(:,58).*(power(CONSTANTS(:,65), CONSTANTS(:,76))./(power(CONSTANTS(:,66), CONSTANTS(:,76))+power(CONSTANTS(:,65), CONSTANTS(:,76)))).*(ALGEBRAIC(:,4)./(CONSTANTS(:,67)+ALGEBRAIC(:,4)));
    ALGEBRAIC(:,15) =  CONSTANTS(:,59).*(STATES(:,13)./(CONSTANTS(:,68)+STATES(:,13)));
    ALGEBRAIC(:,5) = CONSTANTS(:,55) - STATES(:,14);
    ALGEBRAIC(:,11) =  CONSTANTS(:,60).*(STATES(:,13)./CONSTANTS(:,54)).*(ALGEBRAIC(:,5)./(CONSTANTS(:,70)+ALGEBRAIC(:,5)));
    ALGEBRAIC(:,16) =  CONSTANTS(:,57).*STATES(:,16).*(STATES(:,14)./(CONSTANTS(:,69)+STATES(:,14)));
    ALGEBRAIC(:,6) = CONSTANTS(:,56) - STATES(:,11);
    ALGEBRAIC(:,12) =  CONSTANTS(:,61).*(STATES(:,14)./CONSTANTS(:,55)).*(ALGEBRAIC(:,6)./(CONSTANTS(:,71)+ALGEBRAIC(:,6)));
    ALGEBRAIC(:,17) =  CONSTANTS(:,62).*(STATES(:,11)./(CONSTANTS(:,72)+STATES(:,11)));
    ALGEBRAIC(:,14) =  CONSTANTS(:,48).*(CONSTANTS(:,45)./(CONSTANTS(:,45)+CONSTANTS(:,44))).*(STATES(:,7)./(CONSTANTS(:,42)+STATES(:,7)));
    ALGEBRAIC(:,18) =  CONSTANTS(:,49).*(STATES(:,8)./(CONSTANTS(:,43)+STATES(:,8)));
end

% Pad out or shorten strings to a set length
function strout = strpad(strin)
    req_length = 160;
    insize = size(strin,2);
    if insize > req_length
        strout = strin(1:req_length);
    else
        strout = [strin, blanks(req_length - insize)];
    end
end