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 9 entries in each of the rate and state variable arrays.
% There are a total of 49 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_CONSTANTS(:,1) = strpad('Eta_b in component Parameters (mmHg_sec)');
    LEGEND_CONSTANTS(:,2) = strpad('Rho_b in component Parameters (gram_per_cubic_meter)');
    LEGEND_CONSTANTS(:,3) = strpad('E_p in component Parameters (mmHg)');
    LEGEND_CONSTANTS(:,4) = strpad('r_p in component Parameters (meter)');
    LEGEND_CONSTANTS(:,5) = strpad('l_p in component Parameters (meter)');
    LEGEND_CONSTANTS(:,6) = strpad('h_p in component Parameters (meter)');
    LEGEND_CONSTANTS(:,7) = strpad('r_a0 in component Parameters (meter)');
    LEGEND_CONSTANTS(:,8) = strpad('h_a0 in component Parameters (meter)');
    LEGEND_CONSTANTS(:,9) = strpad('sigma_ae0 in component Parameters (mmHg)');
    LEGEND_CONSTANTS(:,10) = strpad('K_a_sigma in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,11) = strpad('sigma_ac in component Parameters (mmHg)');
    LEGEND_CONSTANTS(:,12) = strpad('T_a_max0 in component Parameters (mmHg_m)');
    LEGEND_CONSTANTS(:,13) = strpad('r_am in component Parameters (meter)');
    LEGEND_CONSTANTS(:,14) = strpad('r_at in component Parameters (meter)');
    LEGEND_CONSTANTS(:,15) = strpad('n_am in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,16) = strpad('Eta_a in component Parameters (mmHg_sec)');
    LEGEND_CONSTANTS(:,17) = strpad('Q_bl in component Parameters (cubic_m_per_sec)');
    LEGEND_CONSTANTS(:,18) = strpad('P_ic in component Parameters (mmHg)');
    LEGEND_CONSTANTS(:,19) = strpad('R_v in component Parameters (mmHg_sec_per_cubic_m)');
    LEGEND_CONSTANTS(:,20) = strpad('C_v in component Parameters (cubic_m_per_mmHg)');
    LEGEND_CONSTANTS(:,21) = strpad('P_ai in component Parameters (mmHg)');
    LEGEND_CONSTANTS(:,22) = strpad('T_myo0 in component Parameters (mmHg_m)');
    LEGEND_CONSTANTS(:,23) = strpad('T_myo_s in component Parameters (mmHg_m)');
    LEGEND_CONSTANTS(:,24) = strpad('Tau_myo in component Parameters (second)');
    LEGEND_CONSTANTS(:,25) = strpad('Tau_shear in component Parameters (second)');
    LEGEND_CONSTANTS(:,26) = strpad('G_myo in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,27) = strpad('G_shear in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,28) = strpad('G_neuro in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('G_meta in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,30) = strpad('x_ini in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,31) = strpad('Tau_neuro in component Parameters (second)');
    LEGEND_CONSTANTS(:,32) = strpad('Tau_meta in component Parameters (second)');
    LEGEND_CONSTANTS(:,33) = strpad('conc_CO2_a in component Parameters (mol_per_m3)');
    LEGEND_CONSTANTS(:,34) = strpad('M_CO2_0 in component Parameters (mol_per_sec)');
    LEGEND_CONSTANTS(:,35) = strpad('alpha_tv in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('beta_tv in component Parameters (mol_per_m3)');
    LEGEND_CONSTANTS(:,37) = strpad('vol_PVC in component Parameters (cubic_m)');
    LEGEND_CONSTANTS(:,38) = strpad('K_shear in component Parameters (second)');
    LEGEND_CONSTANTS(:,39) = strpad('K_Ra in component Parameters (mmHg_sec_m)');
    LEGEND_CONSTANTS(:,40) = strpad('conc_CO2_t_sp in component Parameters (mol_per_m3)');
    LEGEND_CONSTANTS(:,41) = strpad('f_Q in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('n_QM in component Parameters (dimensionless)');
    LEGEND_CONSTANTS(:,43) = strpad('K_Va in component Parameters (meter)');
    LEGEND_CONSTANTS(:,44) = strpad('P_vo in component Parameters (mmHg)');
    LEGEND_STATES(:,1) = strpad('Q_Lp in component PCA (cubic_m_per_sec)');
    LEGEND_STATES(:,2) = strpad('P_p in component PCA (mmHg)');
    LEGEND_CONSTANTS(:,47) = strpad('C_p in component PCA_Components (cubic_m_per_mmHg)');
    LEGEND_CONSTANTS(:,48) = strpad('L_p in component PCA_Components (mmHg_sec2_per_m3)');
    LEGEND_CONSTANTS(:,49) = strpad('R_p in component PCA_Components (mmHg_sec_per_cubic_m)');
    LEGEND_ALGEBRAIC(:,1) = strpad('R_a in component AC_Components (mmHg_sec_per_cubic_m)');
    LEGEND_ALGEBRAIC(:,12) = strpad('P_a in component Arteriolar_Circulation (mmHg)');
    LEGEND_ALGEBRAIC(:,3) = strpad('C_a in component AC_Components (cubic_m_per_mmHg)');
    LEGEND_ALGEBRAIC(:,14) = strpad('Q_a in component AC_Flow (cubic_m_per_sec)');
    LEGEND_STATES(:,3) = strpad('P_v in component Venous_Circulation (mmHg)');
    LEGEND_STATES(:,4) = strpad('r_a in component Arteriolar_Circulation (meter)');
    LEGEND_ALGEBRAIC(:,5) = strpad('T_ae in component AC_Tension (mmHg_m)');
    LEGEND_ALGEBRAIC(:,9) = strpad('T_am in component AC_Tension (mmHg_m)');
    LEGEND_ALGEBRAIC(:,10) = strpad('T_av in component AC_Tension (mmHg_m)');
    LEGEND_ALGEBRAIC(:,11) = strpad('T_a in component AC_Tension (mmHg_m)');
    LEGEND_ALGEBRAIC(:,4) = strpad('h_a in component AC_Tension_Variables (meter)');
    LEGEND_ALGEBRAIC(:,8) = strpad('T_a_max in component AC_Tension_Variables (mmHg_m)');
    LEGEND_ALGEBRAIC(:,7) = strpad('M_s in component CBF_Regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('M_s1 in component CBF_Regulation (dimensionless)');
    LEGEND_STATES(:,5) = strpad('x_myo in component Myo_Regulation (dimensionless)');
    LEGEND_STATES(:,6) = strpad('x_shear in component Shear_Regulation (dimensionless)');
    LEGEND_STATES(:,7) = strpad('x_neuro in component Neuro_Regulation (dimensionless)');
    LEGEND_STATES(:,8) = strpad('x_meta in component Meta_Regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('A_myo in component Myo_Regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('A_shear in component Shear_Regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('A_neuro in component Neuro_Regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('A_Meta in component Meta_Regulation (dimensionless)');
    LEGEND_CONSTANTS(:,45) = strpad('G_a_Meta in component Meta_Regulation (m3_per_mol)');
    LEGEND_STATES(:,9) = strpad('conc_CO2_t in component Meta_CO2_Kinetics (mol_per_m3)');
    LEGEND_ALGEBRAIC(:,17) = strpad('conc_CO2_v in component Meta_CO2_Kinetics (mol_per_m3)');
    LEGEND_ALGEBRAIC(:,18) = strpad('M_CO2 in component VC_Meta_Stim (mol_per_sec)');
    LEGEND_CONSTANTS(:,46) = strpad('unity in component VC_Meta_Stim (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt P_p in component PCA (mmHg)');
    LEGEND_RATES(:,1) = strpad('d/dt Q_Lp in component PCA (cubic_m_per_sec)');
    LEGEND_RATES(:,4) = strpad('d/dt r_a in component Arteriolar_Circulation (meter)');
    LEGEND_RATES(:,3) = strpad('d/dt P_v in component Venous_Circulation (mmHg)');
    LEGEND_RATES(:,5) = strpad('d/dt x_myo in component Myo_Regulation (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt x_shear in component Shear_Regulation (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt x_neuro in component Neuro_Regulation (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt x_meta in component Meta_Regulation (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt conc_CO2_t in component Meta_CO2_Kinetics (mol_per_m3)');
    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 = [];
    CONSTANTS(:,1) = 3E-5;
    CONSTANTS(:,2) = 1.05E6;
    CONSTANTS(:,3) = 12E3;
    CONSTANTS(:,4) = 1.05E-3;
    CONSTANTS(:,5) = 8.6E-2;
    CONSTANTS(:,6) = 2.6E-4;
    CONSTANTS(:,7) = 7.5E-5;
    CONSTANTS(:,8) = 2.5E-5;
    CONSTANTS(:,9) = 11.19;
    CONSTANTS(:,10) = 4.5;
    CONSTANTS(:,11) = 41.32;
    CONSTANTS(:,12) = 1.50E-2;
    CONSTANTS(:,13) = 1.28E-4;
    CONSTANTS(:,14) = 1.74E-4;
    CONSTANTS(:,15) = 1.75;
    CONSTANTS(:,16) = 47.8;
    CONSTANTS(:,17) = 8.8E-7;
    CONSTANTS(:,18) = 10;
    CONSTANTS(:,19) = 1.6E7;
    CONSTANTS(:,20) = 2.5E-8;
    CONSTANTS(:,21) = 96.0;
    CONSTANTS(:,22) = 3.6E-3;
    CONSTANTS(:,23) = 3E-3;
    CONSTANTS(:,24) = 7;
    CONSTANTS(:,25) = 60;
    CONSTANTS(:,26) = 4;
    CONSTANTS(:,27) = 0;
    CONSTANTS(:,28) = -0.7;
    CONSTANTS(:,29) = 0;
    CONSTANTS(:,30) = 0;
    CONSTANTS(:,31) = 5;
    CONSTANTS(:,32) = 15;
    CONSTANTS(:,33) = 20.65;
    CONSTANTS(:,34) = 1.35E-7;
    CONSTANTS(:,35) = 0.96;
    CONSTANTS(:,36) = 8.9;
    CONSTANTS(:,37) = 5.99E-6;
    CONSTANTS(:,38) = 5.2E-7;
    CONSTANTS(:,39) = 2.5E-9;
    CONSTANTS(:,40) = 12.41;
    CONSTANTS(:,41) = 1.25;
    CONSTANTS(:,42) = 2.2;
    CONSTANTS(:,43) = 120;
    CONSTANTS(:,44) = 14;
    STATES(:,1) = 8.8E-7;
    STATES(:,2) = 91;
    STATES(:,3) = 21;
    STATES(:,4) = 7.7E-5;
    STATES(:,5) = 0;
    STATES(:,6) = 0;
    STATES(:,7) = 0;
    STATES(:,8) = 0;
    CONSTANTS(:,45) = 0.59;
    STATES(:,9) = 12.41;
    CONSTANTS(:,46) = 1;
    CONSTANTS(:,47) =  (( 3.00000.* pi.*power(CONSTANTS(:,4), 2.00000).*power(CONSTANTS(:,4)./CONSTANTS(:,6)+1.00000, 2.00000))./( CONSTANTS(:,3).*(( 2.00000.*CONSTANTS(:,4))./CONSTANTS(:,6)+1.00000))).*CONSTANTS(:,5);
    CONSTANTS(:,48) =  (CONSTANTS(:,2)./(  pi.*power(CONSTANTS(:,4), 2.00000))).*CONSTANTS(:,5).*7.50000e-06;
    CONSTANTS(:,49) =  (( 8.00000.*CONSTANTS(:,1))./(  pi.*power(CONSTANTS(:,4), 4.00000))).*CONSTANTS(:,5);
    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(:,21) - STATES(:,2)) -  STATES(:,1).*CONSTANTS(:,49))./CONSTANTS(:,48);
    ALGEBRAIC(:,2) =  CONSTANTS(:,45).*(STATES(:,9) - CONSTANTS(:,40));
    RATES(:,8) = (ALGEBRAIC(:,2) - STATES(:,8))./CONSTANTS(:,32);
    ALGEBRAIC(:,1) = CONSTANTS(:,39)./power(STATES(:,4), 4.00000);
    ALGEBRAIC(:,4) = power((power(STATES(:,4), 2.00000)+ 2.00000.*CONSTANTS(:,7).*CONSTANTS(:,8)+power(CONSTANTS(:,8), 2.00000)), 1.0 ./ 2) - STATES(:,4);
    ALGEBRAIC(:,5) =  ALGEBRAIC(:,4).*( CONSTANTS(:,9).*(exp(( CONSTANTS(:,10).*(STATES(:,4) - CONSTANTS(:,7)))./CONSTANTS(:,7)) - 1.00000) - CONSTANTS(:,11));
    ALGEBRAIC(:,6) =  CONSTANTS(:,26).*STATES(:,5)+ CONSTANTS(:,27).*STATES(:,6)+ CONSTANTS(:,28).*STATES(:,7)+ CONSTANTS(:,29).*STATES(:,8)+CONSTANTS(:,30);
    ALGEBRAIC(:,7) = (exp( 2.00000.*ALGEBRAIC(:,6)) - 1.00000)./(exp( 2.00000.*ALGEBRAIC(:,6))+1.00000);
    ALGEBRAIC(:,8) =  CONSTANTS(:,12).*(1.00000+ALGEBRAIC(:,7));
    ALGEBRAIC(:,9) =  ALGEBRAIC(:,8).*exp( - power(abs((STATES(:,4) - CONSTANTS(:,13))./(CONSTANTS(:,14) - CONSTANTS(:,13))), CONSTANTS(:,15)));
    RATES(:,4) = ( CONSTANTS(:,7).*(( STATES(:,2).*(ALGEBRAIC(:,1)+CONSTANTS(:,19)).*STATES(:,4)+ STATES(:,3).*ALGEBRAIC(:,1).*STATES(:,4)) -  (ALGEBRAIC(:,5)+ALGEBRAIC(:,9)+ CONSTANTS(:,18).*(STATES(:,4)+ALGEBRAIC(:,4))).*( 2.00000.*ALGEBRAIC(:,1)+CONSTANTS(:,19))))./( CONSTANTS(:,7).*power(STATES(:,4), 2.00000).*CONSTANTS(:,43).*ALGEBRAIC(:,1).*(ALGEBRAIC(:,1)+CONSTANTS(:,19))+ CONSTANTS(:,16).*ALGEBRAIC(:,4).*( 2.00000.*ALGEBRAIC(:,1)+CONSTANTS(:,19)));
    ALGEBRAIC(:,10) =  (CONSTANTS(:,16)./CONSTANTS(:,7)).*RATES(:,4).*ALGEBRAIC(:,4);
    ALGEBRAIC(:,11) = ALGEBRAIC(:,5)+ALGEBRAIC(:,9)+ALGEBRAIC(:,10);
    ALGEBRAIC(:,12) = (ALGEBRAIC(:,11)+ CONSTANTS(:,18).*(STATES(:,4)+ALGEBRAIC(:,4)))./STATES(:,4);
    RATES(:,2) = ( 2.00000.*(( STATES(:,1).*ALGEBRAIC(:,1) -  2.00000.*STATES(:,2))+ 2.00000.*ALGEBRAIC(:,12)))./( ALGEBRAIC(:,1).*CONSTANTS(:,47));
    RATES(:,3) =  (2.00000./CONSTANTS(:,20)).*((ALGEBRAIC(:,12) - STATES(:,3))./(ALGEBRAIC(:,1)+CONSTANTS(:,19)) - (STATES(:,3) - CONSTANTS(:,44))./CONSTANTS(:,19));
    ALGEBRAIC(:,13) = (ALGEBRAIC(:,11) - CONSTANTS(:,22))./CONSTANTS(:,23);
    RATES(:,5) = (ALGEBRAIC(:,13) - STATES(:,5))./CONSTANTS(:,24);
    ALGEBRAIC(:,14) = ( 2.00000.*(ALGEBRAIC(:,12) - STATES(:,3)))./(ALGEBRAIC(:,1)+CONSTANTS(:,19));
    ALGEBRAIC(:,15) = ( CONSTANTS(:,38).*ALGEBRAIC(:,14))./power(STATES(:,4), 3.00000) - 1.00000;
    RATES(:,6) = (ALGEBRAIC(:,15) - STATES(:,6))./CONSTANTS(:,25);
    ALGEBRAIC(:,16) = piecewise({VOI>=1.00000, 1.00000 }, 0.00000);
    RATES(:,7) = (ALGEBRAIC(:,16) - STATES(:,7))./CONSTANTS(:,31);
    ALGEBRAIC(:,17) =  CONSTANTS(:,35).*STATES(:,9)+CONSTANTS(:,36);
    ALGEBRAIC(:,18) =  CONSTANTS(:,34).*(CONSTANTS(:,46)+ ALGEBRAIC(:,16).*((CONSTANTS(:,41) - CONSTANTS(:,46))./CONSTANTS(:,42)));
    RATES(:,9) =  (1.00000./CONSTANTS(:,37)).*(ALGEBRAIC(:,18) -  ALGEBRAIC(:,14).*(ALGEBRAIC(:,17) - CONSTANTS(:,33)));
   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) =  CONSTANTS(:,45).*(STATES(:,9) - CONSTANTS(:,40));
    ALGEBRAIC(:,1) = CONSTANTS(:,39)./power(STATES(:,4), 4.00000);
    ALGEBRAIC(:,4) = power((power(STATES(:,4), 2.00000)+ 2.00000.*CONSTANTS(:,7).*CONSTANTS(:,8)+power(CONSTANTS(:,8), 2.00000)), 1.0 ./ 2) - STATES(:,4);
    ALGEBRAIC(:,5) =  ALGEBRAIC(:,4).*( CONSTANTS(:,9).*(exp(( CONSTANTS(:,10).*(STATES(:,4) - CONSTANTS(:,7)))./CONSTANTS(:,7)) - 1.00000) - CONSTANTS(:,11));
    ALGEBRAIC(:,6) =  CONSTANTS(:,26).*STATES(:,5)+ CONSTANTS(:,27).*STATES(:,6)+ CONSTANTS(:,28).*STATES(:,7)+ CONSTANTS(:,29).*STATES(:,8)+CONSTANTS(:,30);
    ALGEBRAIC(:,7) = (exp( 2.00000.*ALGEBRAIC(:,6)) - 1.00000)./(exp( 2.00000.*ALGEBRAIC(:,6))+1.00000);
    ALGEBRAIC(:,8) =  CONSTANTS(:,12).*(1.00000+ALGEBRAIC(:,7));
    ALGEBRAIC(:,9) =  ALGEBRAIC(:,8).*exp( - power(abs((STATES(:,4) - CONSTANTS(:,13))./(CONSTANTS(:,14) - CONSTANTS(:,13))), CONSTANTS(:,15)));
    ALGEBRAIC(:,10) =  (CONSTANTS(:,16)./CONSTANTS(:,7)).*RATES(:,4).*ALGEBRAIC(:,4);
    ALGEBRAIC(:,11) = ALGEBRAIC(:,5)+ALGEBRAIC(:,9)+ALGEBRAIC(:,10);
    ALGEBRAIC(:,12) = (ALGEBRAIC(:,11)+ CONSTANTS(:,18).*(STATES(:,4)+ALGEBRAIC(:,4)))./STATES(:,4);
    ALGEBRAIC(:,13) = (ALGEBRAIC(:,11) - CONSTANTS(:,22))./CONSTANTS(:,23);
    ALGEBRAIC(:,14) = ( 2.00000.*(ALGEBRAIC(:,12) - STATES(:,3)))./(ALGEBRAIC(:,1)+CONSTANTS(:,19));
    ALGEBRAIC(:,15) = ( CONSTANTS(:,38).*ALGEBRAIC(:,14))./power(STATES(:,4), 3.00000) - 1.00000;
    ALGEBRAIC(:,16) = piecewise({VOI>=1.00000, 1.00000 }, 0.00000);
    ALGEBRAIC(:,17) =  CONSTANTS(:,35).*STATES(:,9)+CONSTANTS(:,36);
    ALGEBRAIC(:,18) =  CONSTANTS(:,34).*(CONSTANTS(:,46)+ ALGEBRAIC(:,16).*((CONSTANTS(:,41) - CONSTANTS(:,46))./CONSTANTS(:,42)));
    ALGEBRAIC(:,3) = 1.03120./ALGEBRAIC(:,1);
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