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 =32;
end
% There are a total of 23 entries in each of the rate and state variable arrays.
% There are a total of 50 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 (second)');
    LEGEND_STATES(:,1) = strpad('EGF in component EGF (nanomolar)');
    LEGEND_ALGEBRAIC(:,1) = strpad('v1 in component v1 (flux)');
    LEGEND_STATES(:,2) = strpad('R in component R (nanomolar)');
    LEGEND_STATES(:,3) = strpad('Ra in component Ra (nanomolar)');
    LEGEND_ALGEBRAIC(:,9) = strpad('v2 in component v2 (flux)');
    LEGEND_STATES(:,4) = strpad('R2 in component R2 (nanomolar)');
    LEGEND_ALGEBRAIC(:,10) = strpad('v3 in component v3 (flux)');
    LEGEND_ALGEBRAIC(:,11) = strpad('v4 in component v4 (flux)');
    LEGEND_STATES(:,5) = strpad('RP in component RP (nanomolar)');
    LEGEND_ALGEBRAIC(:,14) = strpad('v7 in component v7 (flux)');
    LEGEND_ALGEBRAIC(:,19) = strpad('v11 in component v11 (flux)');
    LEGEND_ALGEBRAIC(:,23) = strpad('v15 in component v15 (flux)');
    LEGEND_ALGEBRAIC(:,26) = strpad('v18 in component v18 (flux)');
    LEGEND_ALGEBRAIC(:,28) = strpad('v20 in component v20 (flux)');
    LEGEND_ALGEBRAIC(:,12) = strpad('v5 in component v5 (flux)');
    LEGEND_ALGEBRAIC(:,15) = strpad('v9 in component v9 (flux)');
    LEGEND_ALGEBRAIC(:,21) = strpad('v13 in component v13 (flux)');
    LEGEND_STATES(:,6) = strpad('R_PL in component R_PL (nanomolar)');
    LEGEND_ALGEBRAIC(:,13) = strpad('v6 in component v6 (flux)');
    LEGEND_STATES(:,7) = strpad('R_PLP in component R_PLP (nanomolar)');
    LEGEND_STATES(:,8) = strpad('R_G in component R_G (nanomolar)');
    LEGEND_ALGEBRAIC(:,17) = strpad('v10 in component v10 (flux)');
    LEGEND_STATES(:,9) = strpad('R_G_S in component R_G_S (nanomolar)');
    LEGEND_STATES(:,10) = strpad('R_Sh in component R_Sh (nanomolar)');
    LEGEND_ALGEBRAIC(:,22) = strpad('v14 in component v14 (flux)');
    LEGEND_STATES(:,11) = strpad('R_ShP in component R_ShP (nanomolar)');
    LEGEND_ALGEBRAIC(:,32) = strpad('v24 in component v24 (flux)');
    LEGEND_ALGEBRAIC(:,25) = strpad('v17 in component v17 (flux)');
    LEGEND_STATES(:,12) = strpad('R_Sh_G in component R_Sh_G (nanomolar)');
    LEGEND_ALGEBRAIC(:,27) = strpad('v19 in component v19 (flux)');
    LEGEND_STATES(:,13) = strpad('R_Sh_G_S in component R_Sh_G_S (nanomolar)');
    LEGEND_STATES(:,14) = strpad('G_S in component G_S (nanomolar)');
    LEGEND_ALGEBRAIC(:,31) = strpad('v23 in component v23 (flux)');
    LEGEND_ALGEBRAIC(:,20) = strpad('v12 in component v12 (flux)');
    LEGEND_STATES(:,15) = strpad('ShP in component ShP (nanomolar)');
    LEGEND_ALGEBRAIC(:,29) = strpad('v21 in component v21 (flux)');
    LEGEND_ALGEBRAIC(:,24) = strpad('v16 in component v16 (flux)');
    LEGEND_STATES(:,16) = strpad('Sh_G in component Sh_G (nanomolar)');
    LEGEND_ALGEBRAIC(:,30) = strpad('v22 in component v22 (flux)');
    LEGEND_STATES(:,17) = strpad('Sh_G_S in component Sh_G_S (nanomolar)');
    LEGEND_STATES(:,18) = strpad('PLC_gamma in component PLC_gamma (nanomolar)');
    LEGEND_ALGEBRAIC(:,16) = strpad('v8 in component v8 (flux)');
    LEGEND_STATES(:,19) = strpad('PLC_gamma_P in component PLC_gamma_P (nanomolar)');
    LEGEND_ALGEBRAIC(:,18) = strpad('v25 in component v25 (flux)');
    LEGEND_STATES(:,20) = strpad('PLC_gamma_P_I in component PLC_gamma_P_I (nanomolar)');
    LEGEND_STATES(:,21) = strpad('Grb in component Grb (nanomolar)');
    LEGEND_STATES(:,22) = strpad('Shc in component Shc (nanomolar)');
    LEGEND_STATES(:,23) = strpad('SOS in component SOS (nanomolar)');
    LEGEND_CONSTANTS(:,1) = strpad('k1 in component v1 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,2) = strpad('k1_ in component v1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,3) = strpad('k2 in component v2 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,4) = strpad('k2_ in component v2 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,5) = strpad('k3 in component v3 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,6) = strpad('k3_ in component v3 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,7) = strpad('K4 in component v4 (nanomolar)');
    LEGEND_CONSTANTS(:,8) = strpad('V4 in component v4 (flux)');
    LEGEND_CONSTANTS(:,9) = strpad('k5 in component v5 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,10) = strpad('k5_ in component v5 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,11) = strpad('k6 in component v6 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,12) = strpad('k6_ in component v6 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,13) = strpad('k7 in component v7 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,14) = strpad('k7_ in component v7 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,15) = strpad('K8 in component v8 (nanomolar)');
    LEGEND_CONSTANTS(:,16) = strpad('V8 in component v8 (flux)');
    LEGEND_CONSTANTS(:,17) = strpad('k9 in component v9 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,18) = strpad('k9_ in component v9 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,19) = strpad('k10 in component v10 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,20) = strpad('k10_ in component v10 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,21) = strpad('k11 in component v11 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,22) = strpad('k11_ in component v11 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,23) = strpad('k12 in component v12 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,24) = strpad('k12_ in component v12 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,25) = strpad('k13 in component v13 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,26) = strpad('k13_ in component v13 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,27) = strpad('k14 in component v14 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,28) = strpad('k14_ in component v14 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,29) = strpad('k15 in component v15 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,30) = strpad('k15_ in component v15 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,31) = strpad('K16 in component v16 (nanomolar)');
    LEGEND_CONSTANTS(:,32) = strpad('V16 in component v16 (flux)');
    LEGEND_CONSTANTS(:,33) = strpad('k17 in component v17 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,34) = strpad('k17_ in component v17 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,35) = strpad('k18 in component v18 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,36) = strpad('k18_ in component v18 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,37) = strpad('k19 in component v19 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,38) = strpad('k19_ in component v19 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,39) = strpad('k20 in component v20 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,40) = strpad('k20_ in component v20 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,41) = strpad('k21 in component v21 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,42) = strpad('k21_ in component v21 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,43) = strpad('k22 in component v22 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,44) = strpad('k22_ in component v22 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,45) = strpad('k23 in component v23 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,46) = strpad('k23_ in component v23 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,47) = strpad('k24 in component v24 (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,48) = strpad('k24_ in component v24 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,49) = strpad('k25 in component v25 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,50) = strpad('k25_ in component v25 (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,2) = strpad('totEGFRphos in component combined_concs (nanomolar)');
    LEGEND_ALGEBRAIC(:,3) = strpad('totPLCgammaphos in component combined_concs (nanomolar)');
    LEGEND_ALGEBRAIC(:,4) = strpad('totGrb_EGFR in component combined_concs (nanomolar)');
    LEGEND_ALGEBRAIC(:,5) = strpad('totGrb_Shc in component combined_concs (nanomolar)');
    LEGEND_ALGEBRAIC(:,6) = strpad('totShcphos in component combined_concs (nanomolar)');
    LEGEND_ALGEBRAIC(:,7) = strpad('totShc_EGFR in component combined_concs (nanomolar)');
    LEGEND_ALGEBRAIC(:,8) = strpad('totSOS_EGFR in component combined_concs (nanomolar)');
    LEGEND_RATES(:,1) = strpad('d/dt EGF in component EGF (nanomolar)');
    LEGEND_RATES(:,2) = strpad('d/dt R in component R (nanomolar)');
    LEGEND_RATES(:,3) = strpad('d/dt Ra in component Ra (nanomolar)');
    LEGEND_RATES(:,4) = strpad('d/dt R2 in component R2 (nanomolar)');
    LEGEND_RATES(:,5) = strpad('d/dt RP in component RP (nanomolar)');
    LEGEND_RATES(:,6) = strpad('d/dt R_PL in component R_PL (nanomolar)');
    LEGEND_RATES(:,7) = strpad('d/dt R_PLP in component R_PLP (nanomolar)');
    LEGEND_RATES(:,8) = strpad('d/dt R_G in component R_G (nanomolar)');
    LEGEND_RATES(:,9) = strpad('d/dt R_G_S in component R_G_S (nanomolar)');
    LEGEND_RATES(:,10) = strpad('d/dt R_Sh in component R_Sh (nanomolar)');
    LEGEND_RATES(:,11) = strpad('d/dt R_ShP in component R_ShP (nanomolar)');
    LEGEND_RATES(:,12) = strpad('d/dt R_Sh_G in component R_Sh_G (nanomolar)');
    LEGEND_RATES(:,13) = strpad('d/dt R_Sh_G_S in component R_Sh_G_S (nanomolar)');
    LEGEND_RATES(:,14) = strpad('d/dt G_S in component G_S (nanomolar)');
    LEGEND_RATES(:,15) = strpad('d/dt ShP in component ShP (nanomolar)');
    LEGEND_RATES(:,16) = strpad('d/dt Sh_G in component Sh_G (nanomolar)');
    LEGEND_RATES(:,17) = strpad('d/dt Sh_G_S in component Sh_G_S (nanomolar)');
    LEGEND_RATES(:,18) = strpad('d/dt PLC_gamma in component PLC_gamma (nanomolar)');
    LEGEND_RATES(:,19) = strpad('d/dt PLC_gamma_P in component PLC_gamma_P (nanomolar)');
    LEGEND_RATES(:,20) = strpad('d/dt PLC_gamma_P_I in component PLC_gamma_P_I (nanomolar)');
    LEGEND_RATES(:,21) = strpad('d/dt Grb in component Grb (nanomolar)');
    LEGEND_RATES(:,22) = strpad('d/dt Shc in component Shc (nanomolar)');
    LEGEND_RATES(:,23) = strpad('d/dt SOS in component SOS (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) = 680;
    STATES(:,2) = 100;
    STATES(:,3) = 0;
    STATES(:,4) = 0;
    STATES(:,5) = 0;
    STATES(:,6) = 0;
    STATES(:,7) = 0;
    STATES(:,8) = 0;
    STATES(:,9) = 0;
    STATES(:,10) = 0;
    STATES(:,11) = 0;
    STATES(:,12) = 0;
    STATES(:,13) = 0;
    STATES(:,14) = 0;
    STATES(:,15) = 0;
    STATES(:,16) = 0;
    STATES(:,17) = 0;
    STATES(:,18) = 105;
    STATES(:,19) = 0;
    STATES(:,20) = 0;
    STATES(:,21) = 85;
    STATES(:,22) = 150;
    STATES(:,23) = 34;
    CONSTANTS(:,1) = 0.003;
    CONSTANTS(:,2) = 0.06;
    CONSTANTS(:,3) = 0.01;
    CONSTANTS(:,4) = 0.1;
    CONSTANTS(:,5) = 1;
    CONSTANTS(:,6) = 0.01;
    CONSTANTS(:,7) = 50;
    CONSTANTS(:,8) = 450;
    CONSTANTS(:,9) = 0.06;
    CONSTANTS(:,10) = 0.2;
    CONSTANTS(:,11) = 1;
    CONSTANTS(:,12) = 0.05;
    CONSTANTS(:,13) = 0.3;
    CONSTANTS(:,14) = 0.006;
    CONSTANTS(:,15) = 100;
    CONSTANTS(:,16) = 1;
    CONSTANTS(:,17) = 0.003;
    CONSTANTS(:,18) = 0.05;
    CONSTANTS(:,19) = 0.01;
    CONSTANTS(:,20) = 0.06;
    CONSTANTS(:,21) = 0.03;
    CONSTANTS(:,22) = 4.5e-3;
    CONSTANTS(:,23) = 1.5e-3;
    CONSTANTS(:,24) = 1e-4;
    CONSTANTS(:,25) = 0.09;
    CONSTANTS(:,26) = 0.6;
    CONSTANTS(:,27) = 6;
    CONSTANTS(:,28) = 0.06;
    CONSTANTS(:,29) = 0.3;
    CONSTANTS(:,30) = 9e-4;
    CONSTANTS(:,31) = 340;
    CONSTANTS(:,32) = 1.7;
    CONSTANTS(:,33) = 0.003;
    CONSTANTS(:,34) = 0.1;
    CONSTANTS(:,35) = 0.3;
    CONSTANTS(:,36) = 9e-4;
    CONSTANTS(:,37) = 0.01;
    CONSTANTS(:,38) = 2.14e-2;
    CONSTANTS(:,39) = 0.12;
    CONSTANTS(:,40) = 2.4e-4;
    CONSTANTS(:,41) = 0.003;
    CONSTANTS(:,42) = 0.1;
    CONSTANTS(:,43) = 0.03;
    CONSTANTS(:,44) = 0.064;
    CONSTANTS(:,45) = 0.1;
    CONSTANTS(:,46) = 0.021;
    CONSTANTS(:,47) = 0.009;
    CONSTANTS(:,48) = 4.29e-2;
    CONSTANTS(:,49) = 1;
    CONSTANTS(:,50) = 0.03;
    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
    ALGEBRAIC(:,1) =  CONSTANTS(:,1).*STATES(:,2).*STATES(:,1) -  CONSTANTS(:,2).*STATES(:,3);
    RATES(:,1) =  - ALGEBRAIC(:,1);
    RATES(:,2) =  - ALGEBRAIC(:,1);
    ALGEBRAIC(:,9) =  CONSTANTS(:,3).*STATES(:,3).*STATES(:,3) -  CONSTANTS(:,4).*STATES(:,4);
    RATES(:,3) = ALGEBRAIC(:,1) -  2.00000.*ALGEBRAIC(:,9);
    ALGEBRAIC(:,10) =  CONSTANTS(:,5).*STATES(:,4) -  CONSTANTS(:,6).*STATES(:,5);
    ALGEBRAIC(:,11) = ( CONSTANTS(:,8).*STATES(:,5))./(CONSTANTS(:,7)+STATES(:,5));
    RATES(:,4) = (ALGEBRAIC(:,9)+ALGEBRAIC(:,11)) - ALGEBRAIC(:,10);
    ALGEBRAIC(:,12) =  CONSTANTS(:,9).*STATES(:,5).*STATES(:,18) -  CONSTANTS(:,10).*STATES(:,6);
    ALGEBRAIC(:,13) =  CONSTANTS(:,11).*STATES(:,6) -  CONSTANTS(:,12).*STATES(:,7);
    RATES(:,6) = ALGEBRAIC(:,12) - ALGEBRAIC(:,13);
    ALGEBRAIC(:,14) =  CONSTANTS(:,13).*STATES(:,7) -  CONSTANTS(:,14).*STATES(:,5).*STATES(:,19);
    RATES(:,7) = ALGEBRAIC(:,13) - ALGEBRAIC(:,14);
    ALGEBRAIC(:,16) = ( CONSTANTS(:,16).*STATES(:,19))./(CONSTANTS(:,15)+STATES(:,19));
    RATES(:,18) = ALGEBRAIC(:,16) - ALGEBRAIC(:,12);
    ALGEBRAIC(:,15) =  CONSTANTS(:,17).*STATES(:,5).*STATES(:,21) -  CONSTANTS(:,18).*STATES(:,8);
    ALGEBRAIC(:,17) =  CONSTANTS(:,19).*STATES(:,8).*STATES(:,23) -  CONSTANTS(:,20).*STATES(:,9);
    RATES(:,8) = ALGEBRAIC(:,15) - ALGEBRAIC(:,17);
    ALGEBRAIC(:,18) =  CONSTANTS(:,49).*STATES(:,19) -  CONSTANTS(:,50).*STATES(:,20);
    RATES(:,19) = ALGEBRAIC(:,14) - (ALGEBRAIC(:,16)+ALGEBRAIC(:,18));
    RATES(:,20) = ALGEBRAIC(:,18);
    ALGEBRAIC(:,19) =  CONSTANTS(:,21).*STATES(:,9) -  CONSTANTS(:,22).*STATES(:,5).*STATES(:,14);
    RATES(:,9) = ALGEBRAIC(:,17) - ALGEBRAIC(:,19);
    ALGEBRAIC(:,21) =  CONSTANTS(:,25).*STATES(:,5).*STATES(:,22) -  CONSTANTS(:,26).*STATES(:,10);
    ALGEBRAIC(:,22) =  CONSTANTS(:,27).*STATES(:,10) -  CONSTANTS(:,28).*STATES(:,11);
    RATES(:,10) = ALGEBRAIC(:,21) - ALGEBRAIC(:,22);
    ALGEBRAIC(:,24) = ( CONSTANTS(:,32).*STATES(:,15))./(CONSTANTS(:,31)+STATES(:,15));
    RATES(:,22) = ALGEBRAIC(:,24) - ALGEBRAIC(:,21);
    ALGEBRAIC(:,26) =  CONSTANTS(:,35).*STATES(:,12) -  CONSTANTS(:,36).*STATES(:,5).*STATES(:,16);
    ALGEBRAIC(:,25) =  CONSTANTS(:,33).*STATES(:,11).*STATES(:,21) -  CONSTANTS(:,34).*STATES(:,12);
    ALGEBRAIC(:,27) =  CONSTANTS(:,37).*STATES(:,12).*STATES(:,23) -  CONSTANTS(:,38).*STATES(:,13);
    RATES(:,12) = ALGEBRAIC(:,25) - (ALGEBRAIC(:,26)+ALGEBRAIC(:,27));
    ALGEBRAIC(:,23) =  CONSTANTS(:,29).*STATES(:,11) -  CONSTANTS(:,30).*STATES(:,15).*STATES(:,5);
    ALGEBRAIC(:,28) =  CONSTANTS(:,39).*STATES(:,13) -  CONSTANTS(:,40).*STATES(:,17).*STATES(:,5);
    RATES(:,5) = (ALGEBRAIC(:,10)+ALGEBRAIC(:,14)+ALGEBRAIC(:,19)+ALGEBRAIC(:,23)+ALGEBRAIC(:,26)+ALGEBRAIC(:,28)) - (ALGEBRAIC(:,11)+ALGEBRAIC(:,12)+ALGEBRAIC(:,15)+ALGEBRAIC(:,21));
    ALGEBRAIC(:,20) =  CONSTANTS(:,23).*STATES(:,14) -  CONSTANTS(:,24).*STATES(:,21).*STATES(:,23);
    ALGEBRAIC(:,29) =  CONSTANTS(:,41).*STATES(:,15).*STATES(:,21) -  CONSTANTS(:,42).*STATES(:,16);
    RATES(:,21) = ALGEBRAIC(:,20) - (ALGEBRAIC(:,15)+ALGEBRAIC(:,25)+ALGEBRAIC(:,29));
    ALGEBRAIC(:,30) =  CONSTANTS(:,43).*STATES(:,16).*STATES(:,23) -  CONSTANTS(:,44).*STATES(:,17);
    RATES(:,16) = (ALGEBRAIC(:,26)+ALGEBRAIC(:,29)) - ALGEBRAIC(:,30);
    RATES(:,23) = ALGEBRAIC(:,20) - (ALGEBRAIC(:,17)+ALGEBRAIC(:,27)+ALGEBRAIC(:,30));
    ALGEBRAIC(:,31) =  CONSTANTS(:,45).*STATES(:,17) -  CONSTANTS(:,46).*STATES(:,15).*STATES(:,14);
    RATES(:,15) = (ALGEBRAIC(:,23)+ALGEBRAIC(:,31)) - (ALGEBRAIC(:,29)+ALGEBRAIC(:,24));
    RATES(:,17) = (ALGEBRAIC(:,28)+ALGEBRAIC(:,30)) - ALGEBRAIC(:,31);
    ALGEBRAIC(:,32) =  CONSTANTS(:,47).*STATES(:,11).*STATES(:,14) -  CONSTANTS(:,48).*STATES(:,13);
    RATES(:,11) = ALGEBRAIC(:,22) - (ALGEBRAIC(:,32)+ALGEBRAIC(:,23)+ALGEBRAIC(:,25));
    RATES(:,13) = (ALGEBRAIC(:,27)+ALGEBRAIC(:,32)) - ALGEBRAIC(:,28);
    RATES(:,14) = (ALGEBRAIC(:,19)+ALGEBRAIC(:,31)) - (ALGEBRAIC(:,20)+ALGEBRAIC(:,32));
   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(:,1).*STATES(:,2).*STATES(:,1) -  CONSTANTS(:,2).*STATES(:,3);
    ALGEBRAIC(:,9) =  CONSTANTS(:,3).*STATES(:,3).*STATES(:,3) -  CONSTANTS(:,4).*STATES(:,4);
    ALGEBRAIC(:,10) =  CONSTANTS(:,5).*STATES(:,4) -  CONSTANTS(:,6).*STATES(:,5);
    ALGEBRAIC(:,11) = ( CONSTANTS(:,8).*STATES(:,5))./(CONSTANTS(:,7)+STATES(:,5));
    ALGEBRAIC(:,12) =  CONSTANTS(:,9).*STATES(:,5).*STATES(:,18) -  CONSTANTS(:,10).*STATES(:,6);
    ALGEBRAIC(:,13) =  CONSTANTS(:,11).*STATES(:,6) -  CONSTANTS(:,12).*STATES(:,7);
    ALGEBRAIC(:,14) =  CONSTANTS(:,13).*STATES(:,7) -  CONSTANTS(:,14).*STATES(:,5).*STATES(:,19);
    ALGEBRAIC(:,16) = ( CONSTANTS(:,16).*STATES(:,19))./(CONSTANTS(:,15)+STATES(:,19));
    ALGEBRAIC(:,15) =  CONSTANTS(:,17).*STATES(:,5).*STATES(:,21) -  CONSTANTS(:,18).*STATES(:,8);
    ALGEBRAIC(:,17) =  CONSTANTS(:,19).*STATES(:,8).*STATES(:,23) -  CONSTANTS(:,20).*STATES(:,9);
    ALGEBRAIC(:,18) =  CONSTANTS(:,49).*STATES(:,19) -  CONSTANTS(:,50).*STATES(:,20);
    ALGEBRAIC(:,19) =  CONSTANTS(:,21).*STATES(:,9) -  CONSTANTS(:,22).*STATES(:,5).*STATES(:,14);
    ALGEBRAIC(:,21) =  CONSTANTS(:,25).*STATES(:,5).*STATES(:,22) -  CONSTANTS(:,26).*STATES(:,10);
    ALGEBRAIC(:,22) =  CONSTANTS(:,27).*STATES(:,10) -  CONSTANTS(:,28).*STATES(:,11);
    ALGEBRAIC(:,24) = ( CONSTANTS(:,32).*STATES(:,15))./(CONSTANTS(:,31)+STATES(:,15));
    ALGEBRAIC(:,26) =  CONSTANTS(:,35).*STATES(:,12) -  CONSTANTS(:,36).*STATES(:,5).*STATES(:,16);
    ALGEBRAIC(:,25) =  CONSTANTS(:,33).*STATES(:,11).*STATES(:,21) -  CONSTANTS(:,34).*STATES(:,12);
    ALGEBRAIC(:,27) =  CONSTANTS(:,37).*STATES(:,12).*STATES(:,23) -  CONSTANTS(:,38).*STATES(:,13);
    ALGEBRAIC(:,23) =  CONSTANTS(:,29).*STATES(:,11) -  CONSTANTS(:,30).*STATES(:,15).*STATES(:,5);
    ALGEBRAIC(:,28) =  CONSTANTS(:,39).*STATES(:,13) -  CONSTANTS(:,40).*STATES(:,17).*STATES(:,5);
    ALGEBRAIC(:,20) =  CONSTANTS(:,23).*STATES(:,14) -  CONSTANTS(:,24).*STATES(:,21).*STATES(:,23);
    ALGEBRAIC(:,29) =  CONSTANTS(:,41).*STATES(:,15).*STATES(:,21) -  CONSTANTS(:,42).*STATES(:,16);
    ALGEBRAIC(:,30) =  CONSTANTS(:,43).*STATES(:,16).*STATES(:,23) -  CONSTANTS(:,44).*STATES(:,17);
    ALGEBRAIC(:,31) =  CONSTANTS(:,45).*STATES(:,17) -  CONSTANTS(:,46).*STATES(:,15).*STATES(:,14);
    ALGEBRAIC(:,32) =  CONSTANTS(:,47).*STATES(:,11).*STATES(:,14) -  CONSTANTS(:,48).*STATES(:,13);
    ALGEBRAIC(:,2) =  2.00000.*(STATES(:,5)+STATES(:,6)+STATES(:,7)+STATES(:,8)+STATES(:,9)+STATES(:,10)+STATES(:,11)+STATES(:,12)+STATES(:,13));
    ALGEBRAIC(:,3) = STATES(:,7)+STATES(:,19);
    ALGEBRAIC(:,4) = STATES(:,8)+STATES(:,9)+STATES(:,12)+STATES(:,13);
    ALGEBRAIC(:,5) = STATES(:,12)+STATES(:,16)+STATES(:,13)+STATES(:,17);
    ALGEBRAIC(:,6) = STATES(:,11)+STATES(:,12)+STATES(:,13)+STATES(:,15)+STATES(:,16)+STATES(:,17);
    ALGEBRAIC(:,7) = STATES(:,11)+STATES(:,12)+STATES(:,13);
    ALGEBRAIC(:,8) = STATES(:,9)+STATES(:,13);
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