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 =15;
end
% There are a total of 13 entries in each of the rate and state variable arrays.
% There are a total of 71 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('Cln2 in component Cln2 (dimensionless)');
    LEGEND_CONSTANTS(:,1) = strpad('ks_n2 in component Cln2 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,2) = strpad('ks_n2_ in component Cln2 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,3) = strpad('kd_n2 in component Cln2 (first_order_rate_constant)');
    LEGEND_STATES(:,2) = strpad('mass in component mass (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('SBF in component SBF (dimensionless)');
    LEGEND_STATES(:,3) = strpad('Clb2_T in component Clb2_T (dimensionless)');
    LEGEND_CONSTANTS(:,4) = strpad('Hct1_T in component Clb2_T (dimensionless)');
    LEGEND_CONSTANTS(:,5) = strpad('ks_b2 in component Clb2_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,6) = strpad('ks_b2_ in component Clb2_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,7) = strpad('kd_b2 in component Clb2_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,8) = strpad('kd_b2_ in component Clb2_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,9) = strpad('kd_b2__ in component Clb2_T (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,1) = strpad('Vd_b2 in component Clb2_T (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,4) = strpad('Mcm1 in component Mcm1 (dimensionless)');
    LEGEND_STATES(:,4) = strpad('Hct1 in component Hct1 (dimensionless)');
    LEGEND_STATES(:,5) = strpad('Cdc20 in component Cdc20 (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('Clb2 in component Clb2 (dimensionless)');
    LEGEND_STATES(:,6) = strpad('Clb2_Sic1 in component Clb2_Sic1 (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('Clb5 in component Clb5 (dimensionless)');
    LEGEND_STATES(:,7) = strpad('Clb5_Sic1 in component Clb5_Sic1 (dimensionless)');
    LEGEND_STATES(:,8) = strpad('Clb5_T in component Clb5_T (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('Sic1 in component Sic1 (dimensionless)');
    LEGEND_STATES(:,9) = strpad('Sic1_T in component Sic1_T (dimensionless)');
    LEGEND_CONSTANTS(:,10) = strpad('ks_b5 in component Clb5_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,11) = strpad('ks_b5_ in component Clb5_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,12) = strpad('kd_b5 in component Clb5_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,13) = strpad('kd_b5_ in component Clb5_T (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,7) = strpad('Vd_b5 in component Clb5_T (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,15) = strpad('MBF in component MBF (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('Bck2 in component Bck2 (dimensionless)');
    LEGEND_CONSTANTS(:,14) = strpad('Bck2_0 in component Bck2 (dimensionless)');
    LEGEND_ALGEBRAIC(:,9) = strpad('Cln3 in component Cln3 (dimensionless)');
    LEGEND_CONSTANTS(:,15) = strpad('Jn3 in component Cln3 (dimensionless)');
    LEGEND_CONSTANTS(:,16) = strpad('Dn3 in component Cln3 (dimensionless)');
    LEGEND_CONSTANTS(:,17) = strpad('Cln3_max in component Cln3 (dimensionless)');
    LEGEND_CONSTANTS(:,18) = strpad('ks_c1 in component Sic1_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,19) = strpad('ks_c1_ in component Sic1_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,20) = strpad('kd1_c1 in component parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,21) = strpad('Jd2_c1 in component parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,11) = strpad('Vd2_c1 in component Vd2_c1 (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,14) = strpad('Swi5 in component Swi5 (dimensionless)');
    LEGEND_CONSTANTS(:,22) = strpad('kas_b2 in component Clb2_Sic1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,23) = strpad('kdi_b2 in component Clb2_Sic1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,24) = strpad('kas_b5 in component Clb5_Sic1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,25) = strpad('kdi_b5 in component Clb5_Sic1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,26) = strpad('kd2_c1 in component Vd2_c1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,27) = strpad('epsilonc1_n3 in component Vd2_c1 (dimensionless)');
    LEGEND_CONSTANTS(:,28) = strpad('epsilonc1_k2 in component Vd2_c1 (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('epsilonc1_b5 in component Vd2_c1 (dimensionless)');
    LEGEND_CONSTANTS(:,30) = strpad('epsilonc1_b2 in component Vd2_c1 (dimensionless)');
    LEGEND_STATES(:,10) = strpad('Cdc20_T in component Cdc20_T (dimensionless)');
    LEGEND_CONSTANTS(:,31) = strpad('ks_20 in component Cdc20_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,32) = strpad('ks_20_ in component Cdc20_T (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,33) = strpad('kd_20 in component parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,34) = strpad('ka_20 in component Cdc20 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,35) = strpad('ki_20 in component Cdc20 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,36) = strpad('ki_20_ in component Cdc20 (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,2) = strpad('Vi_20 in component Cdc20 (first_order_rate_constant)');
    LEGEND_STATES(:,11) = strpad('ORI in component ORI (dimensionless)');
    LEGEND_STATES(:,12) = strpad('SPN in component SPN (dimensionless)');
    LEGEND_CONSTANTS(:,37) = strpad('ka_t1 in component Hct1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,38) = strpad('ka_t1_ in component Hct1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,39) = strpad('ki_t1 in component Hct1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,40) = strpad('ki_t1_ in component Hct1 (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,12) = strpad('Vi_t1 in component Hct1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,41) = strpad('Ji_t1 in component Hct1 (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('Ja_t1 in component Hct1 (dimensionless)');
    LEGEND_CONSTANTS(:,43) = strpad('epsiloni_t1_n2 in component Hct1 (dimensionless)');
    LEGEND_CONSTANTS(:,44) = strpad('epsiloni_t1_b5 in component Hct1 (dimensionless)');
    LEGEND_CONSTANTS(:,45) = strpad('epsiloni_t1_b2 in component Hct1 (dimensionless)');
    LEGEND_CONSTANTS(:,46) = strpad('mu in component mass (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,47) = strpad('ks_ori in component ORI (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,48) = strpad('kd_ori in component ORI (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,49) = strpad('epsilonori_b2 in component ORI (dimensionless)');
    LEGEND_STATES(:,13) = strpad('BUD in component BUD (dimensionless)');
    LEGEND_CONSTANTS(:,50) = strpad('ks_bud in component BUD (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,51) = strpad('kd_bud in component BUD (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,52) = strpad('epsilonbud_b5 in component BUD (dimensionless)');
    LEGEND_CONSTANTS(:,53) = strpad('ks_spn in component SPN (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,54) = strpad('kd_spn in component SPN (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,55) = strpad('J_spn in component SPN (dimensionless)');
    LEGEND_CONSTANTS(:,56) = strpad('ka_sbf in component SBF (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,57) = strpad('ki_sbf in component SBF (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,58) = strpad('ki_sbf_ in component SBF (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,10) = strpad('Va_sbf in component SBF (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,59) = strpad('Ji_sbf in component SBF (dimensionless)');
    LEGEND_CONSTANTS(:,60) = strpad('Ja_sbf in component SBF (dimensionless)');
    LEGEND_CONSTANTS(:,61) = strpad('epsilonsbf_n3 in component SBF (dimensionless)');
    LEGEND_CONSTANTS(:,62) = strpad('epsilonsbf_b5 in component SBF (dimensionless)');
    LEGEND_CONSTANTS(:,63) = strpad('ka_mcm in component Mcm1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,64) = strpad('ki_mcm in component Mcm1 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,65) = strpad('Ji_mcm in component Mcm1 (dimensionless)');
    LEGEND_CONSTANTS(:,66) = strpad('Ja_mcm in component Mcm1 (dimensionless)');
    LEGEND_CONSTANTS(:,67) = strpad('ka_swi in component Swi5 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,68) = strpad('ki_swi in component Swi5 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,69) = strpad('ki_swi_ in component Swi5 (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,70) = strpad('Ji_swi in component Swi5 (dimensionless)');
    LEGEND_CONSTANTS(:,71) = strpad('Ja_swi in component Swi5 (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt Cln2 in component Cln2 (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt Clb2_T in component Clb2_T (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt Clb5_T in component Clb5_T (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt Sic1_T in component Sic1_T (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt Clb2_Sic1 in component Clb2_Sic1 (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt Clb5_Sic1 in component Clb5_Sic1 (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt Cdc20_T in component Cdc20_T (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt Cdc20 in component Cdc20 (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt Hct1 in component Hct1 (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt mass in component mass (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt ORI in component ORI (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt BUD in component BUD (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt SPN in component SPN (dimensionless)');
    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.0078;
    CONSTANTS(:,1) = 0;
    CONSTANTS(:,2) = 0.05;
    CONSTANTS(:,3) = 0.1;
    STATES(:,2) = 0.6608;
    STATES(:,3) = 0.2342;
    CONSTANTS(:,4) = 1;
    CONSTANTS(:,5) = 0.002;
    CONSTANTS(:,6) = 0.05;
    CONSTANTS(:,7) = 0.01;
    CONSTANTS(:,8) = 2;
    CONSTANTS(:,9) = 0.05;
    STATES(:,4) = 0.9946;
    STATES(:,5) = 0.6848;
    STATES(:,6) = 0.079;
    STATES(:,7) = 0.0207;
    STATES(:,8) = 0.0614;
    STATES(:,9) = 0.1231;
    CONSTANTS(:,10) = 0.006;
    CONSTANTS(:,11) = 0.02;
    CONSTANTS(:,12) = 0.1;
    CONSTANTS(:,13) = 0.25;
    CONSTANTS(:,14) = 0.0027;
    CONSTANTS(:,15) = 6;
    CONSTANTS(:,16) = 1;
    CONSTANTS(:,17) = 0.02;
    CONSTANTS(:,18) = 0.02;
    CONSTANTS(:,19) = 0.1;
    CONSTANTS(:,20) = 0.01;
    CONSTANTS(:,21) = 0.05;
    CONSTANTS(:,22) = 50;
    CONSTANTS(:,23) = 0.05;
    CONSTANTS(:,24) = 50;
    CONSTANTS(:,25) = 0.05;
    CONSTANTS(:,26) = 0.3;
    CONSTANTS(:,27) = 20;
    CONSTANTS(:,28) = 2;
    CONSTANTS(:,29) = 1;
    CONSTANTS(:,30) = 0.067;
    STATES(:,10) = 0.8332;
    CONSTANTS(:,31) = 0.005;
    CONSTANTS(:,32) = 0.06;
    CONSTANTS(:,33) = 0.08;
    CONSTANTS(:,34) = 1;
    CONSTANTS(:,35) = 0.1;
    CONSTANTS(:,36) = 10;
    STATES(:,11) = 0;
    STATES(:,12) = 0;
    CONSTANTS(:,37) = 0.04;
    CONSTANTS(:,38) = 2;
    CONSTANTS(:,39) = 0;
    CONSTANTS(:,40) = 0.64;
    CONSTANTS(:,41) = 0.05;
    CONSTANTS(:,42) = 0.05;
    CONSTANTS(:,43) = 1;
    CONSTANTS(:,44) = 0.5;
    CONSTANTS(:,45) = 1;
    CONSTANTS(:,46) = 0.005776;
    CONSTANTS(:,47) = 2;
    CONSTANTS(:,48) = 0.06;
    CONSTANTS(:,49) = 0.4;
    STATES(:,13) = 0;
    CONSTANTS(:,50) = 0.3;
    CONSTANTS(:,51) = 0.06;
    CONSTANTS(:,52) = 1;
    CONSTANTS(:,53) = 0.08;
    CONSTANTS(:,54) = 0.06;
    CONSTANTS(:,55) = 0.2;
    CONSTANTS(:,56) = 1;
    CONSTANTS(:,57) = 0.5;
    CONSTANTS(:,58) = 6;
    CONSTANTS(:,59) = 0.01;
    CONSTANTS(:,60) = 0.01;
    CONSTANTS(:,61) = 75;
    CONSTANTS(:,62) = 0.5;
    CONSTANTS(:,63) = 1;
    CONSTANTS(:,64) = 0.15;
    CONSTANTS(:,65) = 1;
    CONSTANTS(:,66) = 1;
    CONSTANTS(:,67) = 1;
    CONSTANTS(:,68) = 0.3;
    CONSTANTS(:,69) = 0.2;
    CONSTANTS(:,70) = 0.1;
    CONSTANTS(:,71) = 0.1;
    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(:,2) =  CONSTANTS(:,46).*STATES(:,2);
    ALGEBRAIC(:,2) = piecewise({STATES(:,11)>=1.00000, CONSTANTS(:,36) , STATES(:,12)>=1.00000, CONSTANTS(:,35) }, 0.100000);
    RATES(:,5) =  CONSTANTS(:,34).*(STATES(:,10) - STATES(:,5)) -  STATES(:,5).*(ALGEBRAIC(:,2)+CONSTANTS(:,33));
    ALGEBRAIC(:,3) = STATES(:,3) - STATES(:,6);
    RATES(:,10) = (CONSTANTS(:,31)+ CONSTANTS(:,32).*ALGEBRAIC(:,3)) -  CONSTANTS(:,33).*STATES(:,10);
    RATES(:,12) = ( CONSTANTS(:,53).*ALGEBRAIC(:,3))./(CONSTANTS(:,55)+ALGEBRAIC(:,3)) -  CONSTANTS(:,54).*STATES(:,12);
    ALGEBRAIC(:,1) =  CONSTANTS(:,7).*(CONSTANTS(:,4) - STATES(:,4))+ CONSTANTS(:,8).*STATES(:,4)+ CONSTANTS(:,9).*STATES(:,5);
    ALGEBRAIC(:,4) = ( 2.00000.*CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65))./(((CONSTANTS(:,64)+ CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65)+ CONSTANTS(:,64).*CONSTANTS(:,66)) -  CONSTANTS(:,63).*ALGEBRAIC(:,3))+power((power((CONSTANTS(:,64)+ CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65)+ CONSTANTS(:,64).*CONSTANTS(:,66)) -  CONSTANTS(:,63).*ALGEBRAIC(:,3), 2.00000) -  4.00000.*(CONSTANTS(:,64) -  CONSTANTS(:,63).*ALGEBRAIC(:,3)).*CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65)), 1.0 ./ 2));
    RATES(:,3) =  STATES(:,2).*(CONSTANTS(:,5)+ CONSTANTS(:,6).*ALGEBRAIC(:,4)) -  ALGEBRAIC(:,1).*STATES(:,3);
    ALGEBRAIC(:,5) = STATES(:,8) - STATES(:,7);
    RATES(:,11) =  CONSTANTS(:,47).*(ALGEBRAIC(:,5)+ CONSTANTS(:,49).*ALGEBRAIC(:,3)) -  CONSTANTS(:,48).*STATES(:,11);
    ALGEBRAIC(:,9) = ( CONSTANTS(:,17).*CONSTANTS(:,16).*STATES(:,2))./(CONSTANTS(:,15)+ CONSTANTS(:,16).*STATES(:,2));
    RATES(:,13) =  CONSTANTS(:,50).*(STATES(:,1)+ALGEBRAIC(:,9)+ CONSTANTS(:,52).*ALGEBRAIC(:,5)) -  CONSTANTS(:,51).*STATES(:,13);
    ALGEBRAIC(:,6) = STATES(:,9) - (STATES(:,6)+STATES(:,7));
    ALGEBRAIC(:,8) =  CONSTANTS(:,14).*STATES(:,2);
    ALGEBRAIC(:,11) =  CONSTANTS(:,26).*( CONSTANTS(:,27).*ALGEBRAIC(:,9)+ CONSTANTS(:,28).*ALGEBRAIC(:,8)+STATES(:,1)+ CONSTANTS(:,29).*ALGEBRAIC(:,5)+ CONSTANTS(:,30).*ALGEBRAIC(:,3));
    RATES(:,6) =  CONSTANTS(:,22).*ALGEBRAIC(:,3).*ALGEBRAIC(:,6) -  STATES(:,6).*(CONSTANTS(:,23)+ALGEBRAIC(:,1)+CONSTANTS(:,20)+ALGEBRAIC(:,11)./(CONSTANTS(:,21)+STATES(:,9)));
    ALGEBRAIC(:,7) = CONSTANTS(:,12)+ CONSTANTS(:,13).*STATES(:,5);
    RATES(:,7) =  CONSTANTS(:,24).*ALGEBRAIC(:,5).*ALGEBRAIC(:,6) -  STATES(:,7).*(CONSTANTS(:,25)+ALGEBRAIC(:,7)+CONSTANTS(:,20)+ALGEBRAIC(:,11)./(CONSTANTS(:,21)+STATES(:,9)));
    ALGEBRAIC(:,12) = CONSTANTS(:,39)+ CONSTANTS(:,40).*(ALGEBRAIC(:,9)+ CONSTANTS(:,43).*STATES(:,1)+ CONSTANTS(:,44).*ALGEBRAIC(:,5)+ CONSTANTS(:,45).*ALGEBRAIC(:,3));
    RATES(:,4) = ( (CONSTANTS(:,37)+ CONSTANTS(:,38).*STATES(:,5)).*(CONSTANTS(:,4) - STATES(:,4)))./((CONSTANTS(:,42)+CONSTANTS(:,4)) - STATES(:,4)) - ( ALGEBRAIC(:,12).*STATES(:,4))./(CONSTANTS(:,41)+STATES(:,4));
    ALGEBRAIC(:,10) =  CONSTANTS(:,56).*(STATES(:,1)+ CONSTANTS(:,61).*(ALGEBRAIC(:,9)+ALGEBRAIC(:,8))+ CONSTANTS(:,62).*ALGEBRAIC(:,5));
    ALGEBRAIC(:,13) = ( 2.00000.*ALGEBRAIC(:,10).*CONSTANTS(:,59))./(((CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)+ ALGEBRAIC(:,10).*CONSTANTS(:,59)+ (CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)).*CONSTANTS(:,60)) - ALGEBRAIC(:,10))+power((power((CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)+ ALGEBRAIC(:,10).*CONSTANTS(:,59)+ (CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)).*CONSTANTS(:,60)) - ALGEBRAIC(:,10), 2.00000) -  4.00000.*ALGEBRAIC(:,10).*CONSTANTS(:,59).*((CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)) - ALGEBRAIC(:,10))), 1.0 ./ 2));
    RATES(:,1) =  STATES(:,2).*(CONSTANTS(:,1)+ CONSTANTS(:,2).*ALGEBRAIC(:,13)) -  CONSTANTS(:,3).*STATES(:,1);
    ALGEBRAIC(:,14) = ( 2.00000.*CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70))./(((CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)+ CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70)+ (CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)).*CONSTANTS(:,71)) -  CONSTANTS(:,67).*STATES(:,5))+power((power((CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)+ CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70)+ (CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)).*CONSTANTS(:,71)) -  CONSTANTS(:,67).*STATES(:,5), 2.00000) -  4.00000.*((CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)) -  CONSTANTS(:,67).*STATES(:,5)).*CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70)), 1.0 ./ 2));
    RATES(:,9) = (CONSTANTS(:,18)+ CONSTANTS(:,19).*ALGEBRAIC(:,14)) -  STATES(:,9).*(CONSTANTS(:,20)+ALGEBRAIC(:,11)./(CONSTANTS(:,21)+STATES(:,9)));
    ALGEBRAIC(:,15) = ALGEBRAIC(:,13);
    RATES(:,8) =  STATES(:,2).*(CONSTANTS(:,10)+ CONSTANTS(:,11).*ALGEBRAIC(:,15)) -  ALGEBRAIC(:,7).*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(:,2) = piecewise({STATES(:,11)>=1.00000, CONSTANTS(:,36) , STATES(:,12)>=1.00000, CONSTANTS(:,35) }, 0.100000);
    ALGEBRAIC(:,3) = STATES(:,3) - STATES(:,6);
    ALGEBRAIC(:,1) =  CONSTANTS(:,7).*(CONSTANTS(:,4) - STATES(:,4))+ CONSTANTS(:,8).*STATES(:,4)+ CONSTANTS(:,9).*STATES(:,5);
    ALGEBRAIC(:,4) = ( 2.00000.*CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65))./(((CONSTANTS(:,64)+ CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65)+ CONSTANTS(:,64).*CONSTANTS(:,66)) -  CONSTANTS(:,63).*ALGEBRAIC(:,3))+power((power((CONSTANTS(:,64)+ CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65)+ CONSTANTS(:,64).*CONSTANTS(:,66)) -  CONSTANTS(:,63).*ALGEBRAIC(:,3), 2.00000) -  4.00000.*(CONSTANTS(:,64) -  CONSTANTS(:,63).*ALGEBRAIC(:,3)).*CONSTANTS(:,63).*ALGEBRAIC(:,3).*CONSTANTS(:,65)), 1.0 ./ 2));
    ALGEBRAIC(:,5) = STATES(:,8) - STATES(:,7);
    ALGEBRAIC(:,9) = ( CONSTANTS(:,17).*CONSTANTS(:,16).*STATES(:,2))./(CONSTANTS(:,15)+ CONSTANTS(:,16).*STATES(:,2));
    ALGEBRAIC(:,6) = STATES(:,9) - (STATES(:,6)+STATES(:,7));
    ALGEBRAIC(:,8) =  CONSTANTS(:,14).*STATES(:,2);
    ALGEBRAIC(:,11) =  CONSTANTS(:,26).*( CONSTANTS(:,27).*ALGEBRAIC(:,9)+ CONSTANTS(:,28).*ALGEBRAIC(:,8)+STATES(:,1)+ CONSTANTS(:,29).*ALGEBRAIC(:,5)+ CONSTANTS(:,30).*ALGEBRAIC(:,3));
    ALGEBRAIC(:,7) = CONSTANTS(:,12)+ CONSTANTS(:,13).*STATES(:,5);
    ALGEBRAIC(:,12) = CONSTANTS(:,39)+ CONSTANTS(:,40).*(ALGEBRAIC(:,9)+ CONSTANTS(:,43).*STATES(:,1)+ CONSTANTS(:,44).*ALGEBRAIC(:,5)+ CONSTANTS(:,45).*ALGEBRAIC(:,3));
    ALGEBRAIC(:,10) =  CONSTANTS(:,56).*(STATES(:,1)+ CONSTANTS(:,61).*(ALGEBRAIC(:,9)+ALGEBRAIC(:,8))+ CONSTANTS(:,62).*ALGEBRAIC(:,5));
    ALGEBRAIC(:,13) = ( 2.00000.*ALGEBRAIC(:,10).*CONSTANTS(:,59))./(((CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)+ ALGEBRAIC(:,10).*CONSTANTS(:,59)+ (CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)).*CONSTANTS(:,60)) - ALGEBRAIC(:,10))+power((power((CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)+ ALGEBRAIC(:,10).*CONSTANTS(:,59)+ (CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)).*CONSTANTS(:,60)) - ALGEBRAIC(:,10), 2.00000) -  4.00000.*ALGEBRAIC(:,10).*CONSTANTS(:,59).*((CONSTANTS(:,57)+ CONSTANTS(:,58).*ALGEBRAIC(:,3)) - ALGEBRAIC(:,10))), 1.0 ./ 2));
    ALGEBRAIC(:,14) = ( 2.00000.*CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70))./(((CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)+ CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70)+ (CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)).*CONSTANTS(:,71)) -  CONSTANTS(:,67).*STATES(:,5))+power((power((CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)+ CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70)+ (CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)).*CONSTANTS(:,71)) -  CONSTANTS(:,67).*STATES(:,5), 2.00000) -  4.00000.*((CONSTANTS(:,68)+ CONSTANTS(:,69).*ALGEBRAIC(:,3)) -  CONSTANTS(:,67).*STATES(:,5)).*CONSTANTS(:,67).*STATES(:,5).*CONSTANTS(:,70)), 1.0 ./ 2));
    ALGEBRAIC(:,15) = ALGEBRAIC(:,13);
end

% Compute result of a piecewise function
function x = piecewise(cases, default)
    set = [0];
    for i = 1:2:length(cases)
        if (length(cases{i+1}) == 1)
            x(cases{i} & ~set,:) = cases{i+1};
        else
            x(cases{i} & ~set,:) = cases{i+1}(cases{i} & ~set);
        end
        set = set | cases{i};
        if(set), break, end
    end
    if (length(default) == 1)
        x(~set,:) = default;
    else
        x(~set,:) = default(~set);
    end
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