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 =65;
end
% There are a total of 15 entries in each of the rate and state variable arrays.
% There are a total of 39 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('t in component environment (second)');
    LEGEND_STATES(:,1) = strpad('q_Ca_i in component environment (fmol)');
    LEGEND_STATES(:,2) = strpad('q_Ca_SR in component environment (fmol)');
    LEGEND_STATES(:,3) = strpad('q_H_i in component environment (fmol)');
    LEGEND_STATES(:,4) = strpad('q_Pi in component environment (fmol)');
    LEGEND_STATES(:,5) = strpad('q_MgADP in component environment (fmol)');
    LEGEND_STATES(:,6) = strpad('q_MgATP in component environment (fmol)');
    LEGEND_STATES(:,7) = strpad('q_P1_SERCA in component environment (fmol)');
    LEGEND_STATES(:,8) = strpad('q_P2_SERCA in component environment (fmol)');
    LEGEND_STATES(:,9) = strpad('q_P2a_SERCA in component environment (fmol)');
    LEGEND_STATES(:,10) = strpad('q_P4_SERCA in component environment (fmol)');
    LEGEND_STATES(:,11) = strpad('q_P5_SERCA in component environment (fmol)');
    LEGEND_STATES(:,12) = strpad('q_P10_SERCA in component environment (fmol)');
    LEGEND_STATES(:,13) = strpad('q_P6_SERCA in component environment (fmol)');
    LEGEND_STATES(:,14) = strpad('q_P8_SERCA in component environment (fmol)');
    LEGEND_STATES(:,15) = strpad('q_P9_SERCA in component environment (fmol)');
    LEGEND_CONSTANTS(:,1) = strpad('q_PLBp in component environment (fmol)');
    LEGEND_CONSTANTS(:,2) = strpad('q_PLBp_baseline in component environment (fmol)');
    LEGEND_ALGEBRAIC(:,52) = strpad('v_Ca_i_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,58) = strpad('v_Ca_SR_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,63) = strpad('v_H_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,49) = strpad('v_MgADP_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,46) = strpad('v_MgATP_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,44) = strpad('v_Pi_SERCA in component SERCA (fmol_per_sec)');
    LEGEND_CONSTANTS(:,3) = strpad('kappa_SERCA_R1_2 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,4) = strpad('kappa_SERCA_R2_4 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,5) = strpad('kappa_SERCA_R2_2a in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,6) = strpad('kappa_SERCA_R4_5 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,7) = strpad('kappa_SERCA_R5_6 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,8) = strpad('kappa_SERCA_R6_8 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,9) = strpad('kappa_SERCA_R8_9 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,10) = strpad('kappa_SERCA_R9_10 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,11) = strpad('kappa_SERCA_R10_1 in component SERCA_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,12) = strpad('K_P1_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,13) = strpad('K_P2_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,14) = strpad('K_P2a_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,15) = strpad('K_P4_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,16) = strpad('K_P5_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,17) = strpad('K_P6_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,18) = strpad('K_P8_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,19) = strpad('K_P9_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,20) = strpad('K_P10_SERCA in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,21) = strpad('K_H in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,22) = strpad('K_Ca_i in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,23) = strpad('K_Ca_SR in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,24) = strpad('K_MgATP in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,25) = strpad('K_MgADP in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,26) = strpad('K_Pi in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,27) = strpad('K_PLBp in component SERCA_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,28) = strpad('R in component constants (J_per_K_per_mol)');
    LEGEND_CONSTANTS(:,29) = strpad('T in component constants (kelvin)');
    LEGEND_CONSTANTS(:,30) = strpad('F in component constants (C_per_mol)');
    LEGEND_CONSTANTS(:,31) = strpad('n_Ca_i in component SERCA (dimensionless)');
    LEGEND_CONSTANTS(:,32) = strpad('n_Ca_SR in component SERCA (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('n_H in component SERCA (dimensionless)');
    LEGEND_ALGEBRAIC(:,1) = strpad('q_SERCA_Ca_complexes in component SERCA (fmol)');
    LEGEND_ALGEBRAIC(:,2) = strpad('c_Ca_i in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,3) = strpad('c_Ca_SR in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,4) = strpad('c_H in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,5) = strpad('c_MgADP in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,6) = strpad('c_MgATP in component SERCA (mM)');
    LEGEND_ALGEBRAIC(:,7) = strpad('c_Pi in component SERCA (mM)');
    LEGEND_CONSTANTS(:,34) = strpad('vol_i in component SERCA (pL)');
    LEGEND_CONSTANTS(:,35) = strpad('vol_sr in component SERCA (pL)');
    LEGEND_CONSTANTS(:,37) = strpad('vol_isr in component SERCA (pL)');
    LEGEND_ALGEBRAIC(:,8) = strpad('mu_Ca_i in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,9) = strpad('mu_Ca_SR in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,10) = strpad('mu_H in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,11) = strpad('mu_MgADP in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,12) = strpad('mu_MgATP in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,14) = strpad('mu_P1 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,47) = strpad('v_P1 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,13) = strpad('mu_Pi in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,15) = strpad('mu_P2 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,54) = strpad('v_P2 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,16) = strpad('mu_P2a in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,51) = strpad('v_P2a in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,17) = strpad('mu_P4 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,56) = strpad('v_P4 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,18) = strpad('mu_P5 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,57) = strpad('v_P5 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,20) = strpad('mu_P6 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,60) = strpad('v_P6 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,22) = strpad('mu_P8 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,62) = strpad('v_P8 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,23) = strpad('mu_P9 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,64) = strpad('v_P9 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,19) = strpad('mu_P10 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,65) = strpad('v_P10 in component SERCA (fmol_per_sec)');
    LEGEND_CONSTANTS(:,36) = strpad('mu_PLBp_baseline in component SERCA (J_per_mol)');
    LEGEND_CONSTANTS(:,38) = strpad('mu_PLBp in component SERCA (J_per_mol)');
    LEGEND_CONSTANTS(:,39) = strpad('mu_PLBp_eff in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,26) = strpad('Af_R1_2 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,27) = strpad('Ar_R1_2 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,43) = strpad('v_SERCA_R1_2 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,28) = strpad('Af_R5_6 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,29) = strpad('Ar_R5_6 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,45) = strpad('v_SERCA_R5_6 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,30) = strpad('Af_R2_2a in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,31) = strpad('Ar_R2_2a in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,48) = strpad('v_SERCA_R2_2a in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,32) = strpad('Af_R2_4 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,33) = strpad('Ar_R2_4 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,50) = strpad('v_SERCA_R2_4 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,34) = strpad('Af_R4_5 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,35) = strpad('Ar_R4_5 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,53) = strpad('v_SERCA_R4_5 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,36) = strpad('Af_R6_8 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,37) = strpad('Ar_R6_8 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,55) = strpad('v_SERCA_R6_8 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,38) = strpad('Af_R8_9 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,39) = strpad('Ar_R8_9 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,59) = strpad('v_SERCA_R8_9 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,40) = strpad('Af_R9_10 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,41) = strpad('Ar_R9_10 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,61) = strpad('v_SERCA_R9_10 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,24) = strpad('Af_R10_1 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,25) = strpad('Ar_R10_1 in component SERCA (J_per_mol)');
    LEGEND_ALGEBRAIC(:,42) = strpad('v_SERCA_R10_1 in component SERCA (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,21) = strpad('v_SERCA_R10_1_noPLBp in component SERCA (fmol_per_sec)');
    LEGEND_RATES(:,1) = strpad('d/dt q_Ca_i in component environment (fmol)');
    LEGEND_RATES(:,2) = strpad('d/dt q_Ca_SR in component environment (fmol)');
    LEGEND_RATES(:,3) = strpad('d/dt q_H_i in component environment (fmol)');
    LEGEND_RATES(:,5) = strpad('d/dt q_MgADP in component environment (fmol)');
    LEGEND_RATES(:,6) = strpad('d/dt q_MgATP in component environment (fmol)');
    LEGEND_RATES(:,4) = strpad('d/dt q_Pi in component environment (fmol)');
    LEGEND_RATES(:,7) = strpad('d/dt q_P1_SERCA in component environment (fmol)');
    LEGEND_RATES(:,8) = strpad('d/dt q_P2_SERCA in component environment (fmol)');
    LEGEND_RATES(:,9) = strpad('d/dt q_P2a_SERCA in component environment (fmol)');
    LEGEND_RATES(:,10) = strpad('d/dt q_P4_SERCA in component environment (fmol)');
    LEGEND_RATES(:,11) = strpad('d/dt q_P5_SERCA in component environment (fmol)');
    LEGEND_RATES(:,12) = strpad('d/dt q_P10_SERCA in component environment (fmol)');
    LEGEND_RATES(:,13) = strpad('d/dt q_P6_SERCA in component environment (fmol)');
    LEGEND_RATES(:,14) = strpad('d/dt q_P8_SERCA in component environment (fmol)');
    LEGEND_RATES(:,15) = strpad('d/dt q_P9_SERCA in component environment (fmol)');
    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.0057;
    STATES(:,2) = 2.28;
    STATES(:,3) = 0.004028;
    STATES(:,4) = 570;
    STATES(:,5) = 1.3794;
    STATES(:,6) = 3.8;
    STATES(:,7) = 0.11111;
    STATES(:,8) = 0.11111;
    STATES(:,9) = 0.11111;
    STATES(:,10) = 0.11111;
    STATES(:,11) = 0.11111;
    STATES(:,12) = 0.11111;
    STATES(:,13) = 0.11111;
    STATES(:,14) = 0.11111;
    STATES(:,15) = 0.11111;
    CONSTANTS(:,1) = 4.028E+00;
    CONSTANTS(:,2) = 4.028E+00;
    CONSTANTS(:,3) = 6.91835e-08;
    CONSTANTS(:,4) = 7.55655;
    CONSTANTS(:,5) = 8506.72;
    CONSTANTS(:,6) = 7.55655;
    CONSTANTS(:,7) = 0.241033;
    CONSTANTS(:,8) = 45.2524;
    CONSTANTS(:,9) = 6662.34;
    CONSTANTS(:,10) = 6662.34;
    CONSTANTS(:,11) = 3.65954e-06;
    CONSTANTS(:,12) = 45.8697;
    CONSTANTS(:,13) = 2.31881;
    CONSTANTS(:,14) = 0.242269;
    CONSTANTS(:,15) = 272.733;
    CONSTANTS(:,16) = 0.000838529;
    CONSTANTS(:,17) = 228.515;
    CONSTANTS(:,18) = 0.320649;
    CONSTANTS(:,19) = 0.309339;
    CONSTANTS(:,20) = 0.445746;
    CONSTANTS(:,21) = 237.968;
    CONSTANTS(:,22) = 0.313625;
    CONSTANTS(:,23) = 5.22709;
    CONSTANTS(:,24) = 17.0902;
    CONSTANTS(:,25) = 2.55479e-06;
    CONSTANTS(:,26) = 0.00185871;
    CONSTANTS(:,27) = 93.2902;
    CONSTANTS(:,28) = 8.31;
    CONSTANTS(:,29) = 310;
    CONSTANTS(:,30) = 96485;
    CONSTANTS(:,31) = 2;
    CONSTANTS(:,32) = 2;
    CONSTANTS(:,33) = 2;
    CONSTANTS(:,34) = 34.0;
    CONSTANTS(:,35) =  CONSTANTS(:,34).*0.0350000;
    CONSTANTS(:,36) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,27).*CONSTANTS(:,1));
    CONSTANTS(:,37) = CONSTANTS(:,34)+CONSTANTS(:,35);
    CONSTANTS(:,38) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,27).*CONSTANTS(:,2));
    CONSTANTS(:,39) = CONSTANTS(:,36) - CONSTANTS(:,38);
    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(:,19) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,20).*STATES(:,12));
    ALGEBRAIC(:,24) = ALGEBRAIC(:,19)+CONSTANTS(:,39);
    ALGEBRAIC(:,14) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,12).*STATES(:,7));
    ALGEBRAIC(:,13) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,26).*STATES(:,4));
    ALGEBRAIC(:,25) = ALGEBRAIC(:,14)+ALGEBRAIC(:,13)+CONSTANTS(:,39);
    ALGEBRAIC(:,42) =  CONSTANTS(:,11).*(exp(ALGEBRAIC(:,24)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,25)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,44) = ALGEBRAIC(:,42);
    RATES(:,4) = ALGEBRAIC(:,44);
    ALGEBRAIC(:,12) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,24).*STATES(:,6));
    ALGEBRAIC(:,26) = ALGEBRAIC(:,14)+ALGEBRAIC(:,12)+CONSTANTS(:,39);
    ALGEBRAIC(:,15) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,13).*STATES(:,8));
    ALGEBRAIC(:,27) = ALGEBRAIC(:,15)+CONSTANTS(:,39);
    ALGEBRAIC(:,43) =  CONSTANTS(:,3).*(exp(ALGEBRAIC(:,26)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,27)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,46) =  - ALGEBRAIC(:,43);
    RATES(:,6) = ALGEBRAIC(:,46);
    ALGEBRAIC(:,47) = ALGEBRAIC(:,42) - ALGEBRAIC(:,43);
    RATES(:,7) = ALGEBRAIC(:,47);
    ALGEBRAIC(:,18) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,16).*STATES(:,11));
    ALGEBRAIC(:,28) = ALGEBRAIC(:,18)+CONSTANTS(:,39);
    ALGEBRAIC(:,11) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,25).*STATES(:,5));
    ALGEBRAIC(:,20) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,17).*STATES(:,13));
    ALGEBRAIC(:,29) = ALGEBRAIC(:,11)+ALGEBRAIC(:,20)+CONSTANTS(:,39);
    ALGEBRAIC(:,45) =  CONSTANTS(:,7).*(exp(ALGEBRAIC(:,28)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,29)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,49) = ALGEBRAIC(:,45);
    RATES(:,5) = ALGEBRAIC(:,49);
    ALGEBRAIC(:,10) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,21).*STATES(:,3));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,15)+ALGEBRAIC(:,10)+CONSTANTS(:,39);
    ALGEBRAIC(:,16) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,14).*STATES(:,9));
    ALGEBRAIC(:,31) = ALGEBRAIC(:,16)+CONSTANTS(:,39);
    ALGEBRAIC(:,48) =  CONSTANTS(:,5).*(exp(ALGEBRAIC(:,30)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,31)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,51) = ALGEBRAIC(:,48);
    RATES(:,9) = ALGEBRAIC(:,51);
    ALGEBRAIC(:,8) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,22).*STATES(:,1));
    ALGEBRAIC(:,32) = ALGEBRAIC(:,15)+ CONSTANTS(:,31).*ALGEBRAIC(:,8)+CONSTANTS(:,39);
    ALGEBRAIC(:,17) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,15).*STATES(:,10));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,17)+CONSTANTS(:,39);
    ALGEBRAIC(:,50) =  CONSTANTS(:,4).*(exp(ALGEBRAIC(:,32)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,33)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,52) =   - CONSTANTS(:,31).*ALGEBRAIC(:,50);
    RATES(:,1) = ALGEBRAIC(:,52);
    ALGEBRAIC(:,54) = ALGEBRAIC(:,43) - ALGEBRAIC(:,50);
    RATES(:,8) = ALGEBRAIC(:,54);
    ALGEBRAIC(:,34) = ALGEBRAIC(:,17)+CONSTANTS(:,39);
    ALGEBRAIC(:,35) = ALGEBRAIC(:,18)+ CONSTANTS(:,33).*ALGEBRAIC(:,10)+CONSTANTS(:,39);
    ALGEBRAIC(:,53) =  CONSTANTS(:,6).*(exp(ALGEBRAIC(:,34)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,35)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,56) = ALGEBRAIC(:,50) - ALGEBRAIC(:,53);
    RATES(:,10) = ALGEBRAIC(:,56);
    ALGEBRAIC(:,57) = ALGEBRAIC(:,53) - ALGEBRAIC(:,45);
    RATES(:,11) = ALGEBRAIC(:,57);
    ALGEBRAIC(:,36) = ALGEBRAIC(:,20)+CONSTANTS(:,39);
    ALGEBRAIC(:,9) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,23).*STATES(:,2));
    ALGEBRAIC(:,22) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,18).*STATES(:,14));
    ALGEBRAIC(:,37) = ALGEBRAIC(:,22)+ CONSTANTS(:,32).*ALGEBRAIC(:,9)+CONSTANTS(:,39);
    ALGEBRAIC(:,55) =  CONSTANTS(:,8).*(exp(ALGEBRAIC(:,36)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,37)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,58) =  CONSTANTS(:,32).*ALGEBRAIC(:,55);
    RATES(:,2) = ALGEBRAIC(:,58);
    ALGEBRAIC(:,60) = ALGEBRAIC(:,45) - ALGEBRAIC(:,55);
    RATES(:,13) = ALGEBRAIC(:,60);
    ALGEBRAIC(:,38) = ALGEBRAIC(:,22)+ CONSTANTS(:,33).*ALGEBRAIC(:,10)+CONSTANTS(:,39);
    ALGEBRAIC(:,23) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,19).*STATES(:,15));
    ALGEBRAIC(:,39) = ALGEBRAIC(:,23)+CONSTANTS(:,39);
    ALGEBRAIC(:,59) =  CONSTANTS(:,9).*(exp(ALGEBRAIC(:,38)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,39)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,62) = ALGEBRAIC(:,55) - ALGEBRAIC(:,59);
    RATES(:,14) = ALGEBRAIC(:,62);
    ALGEBRAIC(:,40) = ALGEBRAIC(:,23)+CONSTANTS(:,39);
    ALGEBRAIC(:,41) = ALGEBRAIC(:,10)+ALGEBRAIC(:,19)+CONSTANTS(:,39);
    ALGEBRAIC(:,61) =  CONSTANTS(:,10).*(exp(ALGEBRAIC(:,40)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,41)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,63) = (( CONSTANTS(:,33).*ALGEBRAIC(:,53) - ALGEBRAIC(:,48)) -  CONSTANTS(:,33).*ALGEBRAIC(:,59))+ALGEBRAIC(:,61);
    RATES(:,3) = ALGEBRAIC(:,63);
    ALGEBRAIC(:,65) = ALGEBRAIC(:,61) - ALGEBRAIC(:,42);
    RATES(:,12) = ALGEBRAIC(:,65);
    ALGEBRAIC(:,64) = ALGEBRAIC(:,59) - ALGEBRAIC(:,61);
    RATES(:,15) = ALGEBRAIC(:,64);
   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(:,19) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,20).*STATES(:,12));
    ALGEBRAIC(:,24) = ALGEBRAIC(:,19)+CONSTANTS(:,39);
    ALGEBRAIC(:,14) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,12).*STATES(:,7));
    ALGEBRAIC(:,13) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,26).*STATES(:,4));
    ALGEBRAIC(:,25) = ALGEBRAIC(:,14)+ALGEBRAIC(:,13)+CONSTANTS(:,39);
    ALGEBRAIC(:,42) =  CONSTANTS(:,11).*(exp(ALGEBRAIC(:,24)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,25)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,44) = ALGEBRAIC(:,42);
    ALGEBRAIC(:,12) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,24).*STATES(:,6));
    ALGEBRAIC(:,26) = ALGEBRAIC(:,14)+ALGEBRAIC(:,12)+CONSTANTS(:,39);
    ALGEBRAIC(:,15) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,13).*STATES(:,8));
    ALGEBRAIC(:,27) = ALGEBRAIC(:,15)+CONSTANTS(:,39);
    ALGEBRAIC(:,43) =  CONSTANTS(:,3).*(exp(ALGEBRAIC(:,26)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,27)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,46) =  - ALGEBRAIC(:,43);
    ALGEBRAIC(:,47) = ALGEBRAIC(:,42) - ALGEBRAIC(:,43);
    ALGEBRAIC(:,18) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,16).*STATES(:,11));
    ALGEBRAIC(:,28) = ALGEBRAIC(:,18)+CONSTANTS(:,39);
    ALGEBRAIC(:,11) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,25).*STATES(:,5));
    ALGEBRAIC(:,20) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,17).*STATES(:,13));
    ALGEBRAIC(:,29) = ALGEBRAIC(:,11)+ALGEBRAIC(:,20)+CONSTANTS(:,39);
    ALGEBRAIC(:,45) =  CONSTANTS(:,7).*(exp(ALGEBRAIC(:,28)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,29)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,49) = ALGEBRAIC(:,45);
    ALGEBRAIC(:,10) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,21).*STATES(:,3));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,15)+ALGEBRAIC(:,10)+CONSTANTS(:,39);
    ALGEBRAIC(:,16) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,14).*STATES(:,9));
    ALGEBRAIC(:,31) = ALGEBRAIC(:,16)+CONSTANTS(:,39);
    ALGEBRAIC(:,48) =  CONSTANTS(:,5).*(exp(ALGEBRAIC(:,30)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,31)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,51) = ALGEBRAIC(:,48);
    ALGEBRAIC(:,8) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,22).*STATES(:,1));
    ALGEBRAIC(:,32) = ALGEBRAIC(:,15)+ CONSTANTS(:,31).*ALGEBRAIC(:,8)+CONSTANTS(:,39);
    ALGEBRAIC(:,17) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,15).*STATES(:,10));
    ALGEBRAIC(:,33) = ALGEBRAIC(:,17)+CONSTANTS(:,39);
    ALGEBRAIC(:,50) =  CONSTANTS(:,4).*(exp(ALGEBRAIC(:,32)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,33)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,52) =   - CONSTANTS(:,31).*ALGEBRAIC(:,50);
    ALGEBRAIC(:,54) = ALGEBRAIC(:,43) - ALGEBRAIC(:,50);
    ALGEBRAIC(:,34) = ALGEBRAIC(:,17)+CONSTANTS(:,39);
    ALGEBRAIC(:,35) = ALGEBRAIC(:,18)+ CONSTANTS(:,33).*ALGEBRAIC(:,10)+CONSTANTS(:,39);
    ALGEBRAIC(:,53) =  CONSTANTS(:,6).*(exp(ALGEBRAIC(:,34)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,35)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,56) = ALGEBRAIC(:,50) - ALGEBRAIC(:,53);
    ALGEBRAIC(:,57) = ALGEBRAIC(:,53) - ALGEBRAIC(:,45);
    ALGEBRAIC(:,36) = ALGEBRAIC(:,20)+CONSTANTS(:,39);
    ALGEBRAIC(:,9) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,23).*STATES(:,2));
    ALGEBRAIC(:,22) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,18).*STATES(:,14));
    ALGEBRAIC(:,37) = ALGEBRAIC(:,22)+ CONSTANTS(:,32).*ALGEBRAIC(:,9)+CONSTANTS(:,39);
    ALGEBRAIC(:,55) =  CONSTANTS(:,8).*(exp(ALGEBRAIC(:,36)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,37)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,58) =  CONSTANTS(:,32).*ALGEBRAIC(:,55);
    ALGEBRAIC(:,60) = ALGEBRAIC(:,45) - ALGEBRAIC(:,55);
    ALGEBRAIC(:,38) = ALGEBRAIC(:,22)+ CONSTANTS(:,33).*ALGEBRAIC(:,10)+CONSTANTS(:,39);
    ALGEBRAIC(:,23) =  CONSTANTS(:,28).*CONSTANTS(:,29).*log( CONSTANTS(:,19).*STATES(:,15));
    ALGEBRAIC(:,39) = ALGEBRAIC(:,23)+CONSTANTS(:,39);
    ALGEBRAIC(:,59) =  CONSTANTS(:,9).*(exp(ALGEBRAIC(:,38)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,39)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,62) = ALGEBRAIC(:,55) - ALGEBRAIC(:,59);
    ALGEBRAIC(:,40) = ALGEBRAIC(:,23)+CONSTANTS(:,39);
    ALGEBRAIC(:,41) = ALGEBRAIC(:,10)+ALGEBRAIC(:,19)+CONSTANTS(:,39);
    ALGEBRAIC(:,61) =  CONSTANTS(:,10).*(exp(ALGEBRAIC(:,40)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp(ALGEBRAIC(:,41)./( CONSTANTS(:,28).*CONSTANTS(:,29))));
    ALGEBRAIC(:,63) = (( CONSTANTS(:,33).*ALGEBRAIC(:,53) - ALGEBRAIC(:,48)) -  CONSTANTS(:,33).*ALGEBRAIC(:,59))+ALGEBRAIC(:,61);
    ALGEBRAIC(:,65) = ALGEBRAIC(:,61) - ALGEBRAIC(:,42);
    ALGEBRAIC(:,64) = ALGEBRAIC(:,59) - ALGEBRAIC(:,61);
    ALGEBRAIC(:,1) =  CONSTANTS(:,31).*STATES(:,10)+ CONSTANTS(:,31).*STATES(:,11)+ CONSTANTS(:,32).*STATES(:,13);
    ALGEBRAIC(:,2) = STATES(:,1)./CONSTANTS(:,34);
    ALGEBRAIC(:,3) = STATES(:,2)./CONSTANTS(:,35);
    ALGEBRAIC(:,4) = STATES(:,3)./CONSTANTS(:,37);
    ALGEBRAIC(:,5) = STATES(:,5)./CONSTANTS(:,34);
    ALGEBRAIC(:,6) = STATES(:,6)./CONSTANTS(:,34);
    ALGEBRAIC(:,7) = STATES(:,4)./CONSTANTS(:,34);
    ALGEBRAIC(:,21) =  CONSTANTS(:,11).*(exp(ALGEBRAIC(:,19)./( CONSTANTS(:,28).*CONSTANTS(:,29))) - exp((ALGEBRAIC(:,14)+ALGEBRAIC(:,13))./( CONSTANTS(:,28).*CONSTANTS(:,29))));
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