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 =56;
end
% There are a total of 14 entries in each of the rate and state variable arrays.
% There are a total of 43 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 (millisecond)');
    LEGEND_STATES(:,1) = strpad('Vm_n in component Vm_n (millivolt)');
    LEGEND_ALGEBRAIC(:,1) = strpad('i_app in component Vm_n (nanoA_per_cm2)');
    LEGEND_CONSTANTS(:,1) = strpad('Cm in component Vm_n (microF_per_cm2)');
    LEGEND_CONSTANTS(:,2) = strpad('t0 in component Vm_n (millisecond)');
    LEGEND_CONSTANTS(:,3) = strpad('t1 in component Vm_n (millisecond)');
    LEGEND_ALGEBRAIC(:,37) = strpad('i_NaT in component i_NaT (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,39) = strpad('i_NaP in component i_NaP (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,41) = strpad('i_leakNa in component i_leakNa (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,26) = strpad('i_KDR in component i_KDR (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,27) = strpad('i_KA in component i_KA (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,28) = strpad('i_leakK in component i_leakK (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,9) = strpad('i_leakf in component i_leakf (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,35) = strpad('i_NaKATPase_n in component i_NaKATPase_n (nanoA_per_cm2)');
    LEGEND_ALGEBRAIC(:,38) = strpad('J_NaT in component i_NaT (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,4) = strpad('gNaT in component i_NaT (microS_per_cm2)');
    LEGEND_CONSTANTS(:,5) = strpad('F in component model_parameters (coulomb_per_mole)');
    LEGEND_ALGEBRAIC(:,36) = strpad('ENa_n in component electric_potentials (millivolt)');
    LEGEND_STATES(:,2) = strpad('m in component i_NaT_m_gate (dimensionless)');
    LEGEND_STATES(:,3) = strpad('h in component i_NaT_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('alpha_m in component i_NaT_m_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,10) = strpad('beta_m in component i_NaT_m_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,3) = strpad('alpha_h in component i_NaT_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,11) = strpad('beta_h in component i_NaT_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,40) = strpad('J_NaP in component i_NaP (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,6) = strpad('gNaP in component i_NaP (microS_per_cm2)');
    LEGEND_STATES(:,4) = strpad('m in component i_NaP_m_gate (dimensionless)');
    LEGEND_STATES(:,5) = strpad('h in component i_NaP_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,4) = strpad('alpha_m in component i_NaP_m_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,12) = strpad('beta_m in component i_NaP_m_gate (per_millisecond)');
    LEGEND_CONSTANTS(:,7) = strpad('tau_activation in component i_NaP_m_gate (millisecond)');
    LEGEND_ALGEBRAIC(:,5) = strpad('alpha_h in component i_NaP_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,13) = strpad('beta_h in component i_NaP_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,23) = strpad('J_KDR in component i_KDR (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,8) = strpad('gKDR in component i_KDR (microS_per_cm2)');
    LEGEND_ALGEBRAIC(:,22) = strpad('EK_n in component electric_potentials (millivolt)');
    LEGEND_STATES(:,6) = strpad('n in component i_KDR_n_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('alpha_n in component i_KDR_n_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,14) = strpad('beta_n in component i_KDR_n_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,24) = strpad('J_KA in component i_KA (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,9) = strpad('gKA in component i_KA (microS_per_cm2)');
    LEGEND_STATES(:,7) = strpad('m in component i_KA_m_gate (dimensionless)');
    LEGEND_STATES(:,8) = strpad('h in component i_KA_h_gate (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('alpha_m in component i_KA_m_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,15) = strpad('beta_m in component i_KA_m_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,8) = strpad('alpha_h in component i_KA_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,16) = strpad('beta_h in component i_KA_h_gate (per_millisecond)');
    LEGEND_ALGEBRAIC(:,34) = strpad('J_NaKATPase_n in component i_NaKATPase_n (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,10) = strpad('I_NaKATPase_n_max in component i_NaKATPase_n (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,11) = strpad('KmNa in component model_parameters (millimolar)');
    LEGEND_CONSTANTS(:,12) = strpad('KmK in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,33) = strpad('Nan in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,19) = strpad('Ko in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,42) = strpad('J_leakNa in component i_leakNa (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,13) = strpad('gleakNa in component i_leakNa (microS_per_cm2)');
    LEGEND_ALGEBRAIC(:,25) = strpad('J_leakK in component i_leakK (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,14) = strpad('gleakK in component i_leakK (microS_per_cm2)');
    LEGEND_CONSTANTS(:,15) = strpad('gleakf in component i_leakf (microS_per_cm2)');
    LEGEND_CONSTANTS(:,16) = strpad('Ef_n in component electric_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,51) = strpad('Vm_g in component Vm_g (millivolt)');
    LEGEND_ALGEBRAIC(:,32) = strpad('ENa_g in component electric_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,20) = strpad('EK_g in component electric_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,50) = strpad('ECl_g in component electric_potentials (millivolt)');
    LEGEND_ALGEBRAIC(:,46) = strpad('ENBC_g in component electric_potentials (millivolt)');
    LEGEND_CONSTANTS(:,17) = strpad('gNa in component J_Na (microS_per_cm2)');
    LEGEND_CONSTANTS(:,18) = strpad('gK in component J_K (microS_per_cm2)');
    LEGEND_CONSTANTS(:,19) = strpad('gCl in component model_parameters (microS_per_cm2)');
    LEGEND_CONSTANTS(:,20) = strpad('gNBC in component J_NBC (microS_per_cm2)');
    LEGEND_ALGEBRAIC(:,30) = strpad('J_NaKATPase_g in component J_NaKATPase_g (picomole_per_cm2_millisecond)');
    LEGEND_ALGEBRAIC(:,52) = strpad('J_Na in component J_Na (picomole_per_cm2_millisecond)');
    LEGEND_ALGEBRAIC(:,53) = strpad('J_K in component J_K (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,21) = strpad('I_NaKATPase_g_max in component J_NaKATPase_g (picomole_per_cm2_millisecond)');
    LEGEND_ALGEBRAIC(:,29) = strpad('Nag in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,54) = strpad('J_NBC in component J_NBC (picomole_per_cm2_millisecond)');
    LEGEND_ALGEBRAIC(:,49) = strpad('J_NKCC1 in component J_NKCC1 (picomole_per_cm2_millisecond)');
    LEGEND_CONSTANTS(:,22) = strpad('gNKCC1 in component J_NKCC1 (microS_per_cm2)');
    LEGEND_CONSTANTS(:,41) = strpad('Psi in component model_parameters (millivolt)');
    LEGEND_ALGEBRAIC(:,31) = strpad('Nao in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,23) = strpad('P_Ko in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,18) = strpad('Kg in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,48) = strpad('Clo in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,47) = strpad('Clg in component ion_concentrations (millimolar)');
    LEGEND_STATES(:,9) = strpad('N_Nag in component N_Nag (nanomole_per_cm2)');
    LEGEND_ALGEBRAIC(:,56) = strpad('dN_Nag_dt in component N_Nag (nanomole_per_cm2_millisecond)');
    LEGEND_STATES(:,10) = strpad('N_Kg in component N_Kg (nanomole_per_cm2)');
    LEGEND_ALGEBRAIC(:,55) = strpad('dN_Kg_dt in component N_Kg (nanomole_per_cm2_millisecond)');
    LEGEND_STATES(:,11) = strpad('wg in component wg (micrometre)');
    LEGEND_CONSTANTS(:,24) = strpad('Lp in component model_parameters (cm_per_second_millimolar)');
    LEGEND_CONSTANTS(:,25) = strpad('Xg in component model_parameters (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,44) = strpad('HCO3o in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,45) = strpad('HCO3g in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,17) = strpad('wo in component wo (micrometre)');
    LEGEND_CONSTANTS(:,26) = strpad('P_wo in component model_parameters (micrometre)');
    LEGEND_CONSTANTS(:,27) = strpad('P_wg in component model_parameters (micrometre)');
    LEGEND_STATES(:,12) = strpad('N_Nao in component N_Nao (nanomole_per_cm2)');
    LEGEND_STATES(:,13) = strpad('N_Ko in component N_Ko (nanomole_per_cm2)');
    LEGEND_STATES(:,14) = strpad('N_HCO3o in component N_HCO3o (nanomole_per_cm2)');
    LEGEND_ALGEBRAIC(:,21) = strpad('Kn in component ion_concentrations (millimolar)');
    LEGEND_ALGEBRAIC(:,43) = strpad('Cln in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,28) = strpad('P_Vm_g in component ion_concentrations (millivolt)');
    LEGEND_CONSTANTS(:,40) = strpad('P_Clo in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,29) = strpad('P_Cln in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,42) = strpad('P_Clg in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,30) = strpad('P_Nan in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,31) = strpad('P_Nao in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,32) = strpad('P_Nag in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,33) = strpad('P_Kn in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,34) = strpad('P_Kg in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,43) = strpad('P_HCO3g in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,35) = strpad('P_HCO3o in component ion_concentrations (millimolar)');
    LEGEND_CONSTANTS(:,36) = strpad('P_wn in component ion_concentrations (micrometre)');
    LEGEND_CONSTANTS(:,37) = strpad('rho in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('R in component model_parameters (joule_per_mole_kelvin)');
    LEGEND_CONSTANTS(:,39) = strpad('T in component model_parameters (kelvin)');
    LEGEND_RATES(:,1) = strpad('d/dt Vm_n in component Vm_n (millivolt)');
    LEGEND_RATES(:,2) = strpad('d/dt m in component i_NaT_m_gate (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt h in component i_NaT_h_gate (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt m in component i_NaP_m_gate (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt h in component i_NaP_h_gate (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt n in component i_KDR_n_gate (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt m in component i_KA_m_gate (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt h in component i_KA_h_gate (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt N_Nag in component N_Nag (nanomole_per_cm2)');
    LEGEND_RATES(:,10) = strpad('d/dt N_Kg in component N_Kg (nanomole_per_cm2)');
    LEGEND_RATES(:,11) = strpad('d/dt wg in component wg (micrometre)');
    LEGEND_RATES(:,12) = strpad('d/dt N_Nao in component N_Nao (nanomole_per_cm2)');
    LEGEND_RATES(:,13) = strpad('d/dt N_Ko in component N_Ko (nanomole_per_cm2)');
    LEGEND_RATES(:,14) = strpad('d/dt N_HCO3o in component N_HCO3o (nanomole_per_cm2)');
    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) = -70;
    CONSTANTS(:,1) = 1;
    CONSTANTS(:,2) = 100;
    CONSTANTS(:,3) = 700;
    CONSTANTS(:,4) = 5000;
    CONSTANTS(:,5) = 9.649e4;
    STATES(:,2) = 0.005;
    STATES(:,3) = 0.9961;
    CONSTANTS(:,6) = 150;
    STATES(:,4) = 0.0129;
    STATES(:,5) = 0.9718;
    CONSTANTS(:,7) = 6;
    CONSTANTS(:,8) = 5000;
    STATES(:,6) = 0.0012;
    CONSTANTS(:,9) = 1000;
    STATES(:,7) = 0.1193;
    STATES(:,8) = 0.1205;
    CONSTANTS(:,10) = 0.0289;
    CONSTANTS(:,11) = 10;
    CONSTANTS(:,12) = 1.5;
    CONSTANTS(:,13) = 20;
    CONSTANTS(:,14) = 66.06;
    CONSTANTS(:,15) = 10;
    CONSTANTS(:,16) = -70;
    CONSTANTS(:,17) = 100.0;
    CONSTANTS(:,18) = 1696.0;
    CONSTANTS(:,19) = 50;
    CONSTANTS(:,20) = 80;
    CONSTANTS(:,21) = 0.1151;
    CONSTANTS(:,22) = 2;
    CONSTANTS(:,23) = 3;
    STATES(:,9) = 0.75;
    STATES(:,10) = 5;
    STATES(:,11) = 0.05;
    CONSTANTS(:,24) = 2e-8;
    CONSTANTS(:,25) = 8.45;
    CONSTANTS(:,26) = 0.025;
    CONSTANTS(:,27) = 0.05;
    STATES(:,12) = 3.65;
    STATES(:,13) = 0.075;
    STATES(:,14) = 0.375;
    CONSTANTS(:,28) = -85;
    CONSTANTS(:,29) = 50;
    CONSTANTS(:,30) = 10;
    CONSTANTS(:,31) = 146;
    CONSTANTS(:,32) = 15;
    CONSTANTS(:,33) = 130;
    CONSTANTS(:,34) = 100;
    CONSTANTS(:,35) = 15;
    CONSTANTS(:,36) = 0.05;
    CONSTANTS(:,37) = 0.5975;
    CONSTANTS(:,38) = 8.315;
    CONSTANTS(:,39) = 300;
    CONSTANTS(:,40) = (CONSTANTS(:,31)+CONSTANTS(:,23)) - CONSTANTS(:,35);
    CONSTANTS(:,41) = ( 1000.00.*CONSTANTS(:,38).*CONSTANTS(:,39))./CONSTANTS(:,5);
    CONSTANTS(:,42) =  CONSTANTS(:,40).*exp(CONSTANTS(:,28)./CONSTANTS(:,41));
    CONSTANTS(:,43) =  CONSTANTS(:,35).*power(( (CONSTANTS(:,31)./CONSTANTS(:,32)).*exp(CONSTANTS(:,28)./CONSTANTS(:,41))), 1.0 ./ 2);
    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(:,2) = ( 0.320000.*( - STATES(:,1) - 51.9000))./(exp( - ( 0.250000.*STATES(:,1)+12.9750)) - 1.00000);
    ALGEBRAIC(:,10) = ( 0.280000.*(STATES(:,1)+24.8900))./(exp( 0.200000.*STATES(:,1)+4.97800) - 1.00000);
    RATES(:,2) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,2)) -  ALGEBRAIC(:,10).*STATES(:,2);
    ALGEBRAIC(:,3) =  0.128000.*exp( - ( 0.0560000.*STATES(:,1)+2.94000));
    ALGEBRAIC(:,11) = 4.00000./(exp( - ( 0.200000.*STATES(:,1)+6.00000))+1.00000);
    RATES(:,3) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,3)) -  ALGEBRAIC(:,11).*STATES(:,3);
    ALGEBRAIC(:,4) = ( (1.00000./CONSTANTS(:,7)).*1.00000)./(exp( - ( 0.143000.*STATES(:,1)+5.67000))+1.00000);
    ALGEBRAIC(:,12) = ( (1.00000./CONSTANTS(:,7)).*exp( - ( 0.143000.*STATES(:,1)+5.67000)))./(exp( - ( 0.143000.*STATES(:,1)+5.67000))+1.00000);
    RATES(:,4) =  ALGEBRAIC(:,4).*(1.00000 - STATES(:,4)) -  ALGEBRAIC(:,12).*STATES(:,4);
    ALGEBRAIC(:,5) =  5.12000e-08.*exp( - ( 0.0560000.*STATES(:,1)+2.94000));
    ALGEBRAIC(:,13) = 1.60000e-06./(exp( - ( 0.200000.*STATES(:,1)+8.00000))+1.00000);
    RATES(:,5) =  ALGEBRAIC(:,5).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,13).*STATES(:,5);
    ALGEBRAIC(:,6) = ( 0.0160000.*( - STATES(:,1) - 34.9000))./(exp( - ( 0.200000.*STATES(:,1)+6.98000)) - 1.00000);
    ALGEBRAIC(:,14) =  0.250000.*exp( - ( 0.0250000.*STATES(:,1)+1.25000));
    RATES(:,6) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,6)) -  ALGEBRAIC(:,14).*STATES(:,6);
    ALGEBRAIC(:,7) = ( 0.0200000.*( - STATES(:,1) - 56.9000))./(exp( - ( 0.100000.*STATES(:,1)+5.69000)) - 1.00000);
    ALGEBRAIC(:,15) = ( 0.0175000.*(STATES(:,1)+29.9000))./(exp( 0.100000.*STATES(:,1)+2.99000) - 1.00000);
    RATES(:,7) =  ALGEBRAIC(:,7).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,15).*STATES(:,7);
    ALGEBRAIC(:,8) =  0.0160000.*exp( - ( 0.0560000.*STATES(:,1)+4.61000));
    ALGEBRAIC(:,16) = 0.500000./(exp( - ( 0.200000.*STATES(:,1)+11.9800))+1.00000);
    RATES(:,8) =  ALGEBRAIC(:,8).*(1.00000 - STATES(:,8)) -  ALGEBRAIC(:,16).*STATES(:,8);
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,2)&VOI<=CONSTANTS(:,3), 3500.00 }, 0.00000);
    ALGEBRAIC(:,33) = (( CONSTANTS(:,36).*CONSTANTS(:,30)+ CONSTANTS(:,27).*CONSTANTS(:,32)+ CONSTANTS(:,26).*CONSTANTS(:,31)) - (STATES(:,12)+STATES(:,9)))./CONSTANTS(:,36);
    ALGEBRAIC(:,17) = (CONSTANTS(:,27)+CONSTANTS(:,26)) - STATES(:,11);
    ALGEBRAIC(:,31) = STATES(:,12)./ALGEBRAIC(:,17);
    ALGEBRAIC(:,36) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,31)./ALGEBRAIC(:,33));
    ALGEBRAIC(:,37) =  CONSTANTS(:,4).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,39) =  CONSTANTS(:,6).*power(STATES(:,4), 2.00000).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,41) =  CONSTANTS(:,13).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,19) = STATES(:,13)./ALGEBRAIC(:,17);
    ALGEBRAIC(:,21) = (( CONSTANTS(:,36).*CONSTANTS(:,33)+ CONSTANTS(:,27).*CONSTANTS(:,34)+ CONSTANTS(:,26).*CONSTANTS(:,23)) - (STATES(:,13)+STATES(:,10)))./CONSTANTS(:,36);
    ALGEBRAIC(:,22) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,19)./ALGEBRAIC(:,21));
    ALGEBRAIC(:,26) =  CONSTANTS(:,8).*power(STATES(:,6), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,27) =  CONSTANTS(:,9).*power(STATES(:,7), 2.00000).*STATES(:,8).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,28) =  CONSTANTS(:,14).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,9) =  CONSTANTS(:,15).*(STATES(:,1) - CONSTANTS(:,16));
    ALGEBRAIC(:,34) = ( (( CONSTANTS(:,10).*power(ALGEBRAIC(:,33), 1.50000))./(power(ALGEBRAIC(:,33), 1.50000)+power(CONSTANTS(:,11), 1.50000))).*ALGEBRAIC(:,19))./(ALGEBRAIC(:,19)+CONSTANTS(:,12));
    ALGEBRAIC(:,35) =  ALGEBRAIC(:,34).*CONSTANTS(:,5);
    RATES(:,1) = ( 0.00100000.*( - (ALGEBRAIC(:,37)+ALGEBRAIC(:,39)+ALGEBRAIC(:,41)+ALGEBRAIC(:,26)+ALGEBRAIC(:,27)+ALGEBRAIC(:,28)+ALGEBRAIC(:,9)+ALGEBRAIC(:,35))+ALGEBRAIC(:,1)))./CONSTANTS(:,1);
    ALGEBRAIC(:,29) = STATES(:,9)./STATES(:,11);
    ALGEBRAIC(:,18) = STATES(:,10)./STATES(:,11);
    ALGEBRAIC(:,45) = (( CONSTANTS(:,27).*CONSTANTS(:,43)+ CONSTANTS(:,26).*CONSTANTS(:,35)) - STATES(:,14))./STATES(:,11);
    ALGEBRAIC(:,47) = (ALGEBRAIC(:,29)+ALGEBRAIC(:,18)) - (ALGEBRAIC(:,45)+( CONSTANTS(:,37).*CONSTANTS(:,25))./STATES(:,11));
    ALGEBRAIC(:,43) = ((CONSTANTS(:,29)+ALGEBRAIC(:,33)) - CONSTANTS(:,30))+(ALGEBRAIC(:,21) - CONSTANTS(:,33));
    ALGEBRAIC(:,48) = (( CONSTANTS(:,27).*CONSTANTS(:,42)+ CONSTANTS(:,26).*CONSTANTS(:,40)+ CONSTANTS(:,36).*CONSTANTS(:,29)) - ( STATES(:,11).*ALGEBRAIC(:,47)+ CONSTANTS(:,36).*ALGEBRAIC(:,43)))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,44) = STATES(:,14)./ALGEBRAIC(:,17);
    RATES(:,11) =  10.0000.*CONSTANTS(:,24).*((ALGEBRAIC(:,29)+ALGEBRAIC(:,18)+ALGEBRAIC(:,47)+ALGEBRAIC(:,45)+CONSTANTS(:,25)./STATES(:,11)) - (ALGEBRAIC(:,31)+ALGEBRAIC(:,19)+ALGEBRAIC(:,48)+ALGEBRAIC(:,44)));
    ALGEBRAIC(:,30) = ( (( CONSTANTS(:,21).*power(ALGEBRAIC(:,29), 1.50000))./(power(ALGEBRAIC(:,29), 1.50000)+power(CONSTANTS(:,11), 1.50000))).*ALGEBRAIC(:,19))./(ALGEBRAIC(:,19)+CONSTANTS(:,12));
    ALGEBRAIC(:,32) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,31)./ALGEBRAIC(:,29));
    ALGEBRAIC(:,20) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,19)./ALGEBRAIC(:,18));
    ALGEBRAIC(:,50) =   - 1.00000.*CONSTANTS(:,41).*log(ALGEBRAIC(:,48)./ALGEBRAIC(:,47));
    ALGEBRAIC(:,46) =   - CONSTANTS(:,41).*log( (ALGEBRAIC(:,31)./ALGEBRAIC(:,29)).*power(ALGEBRAIC(:,44)./ALGEBRAIC(:,45), 2.00000));
    ALGEBRAIC(:,51) = ( CONSTANTS(:,17).*ALGEBRAIC(:,32)+ CONSTANTS(:,18).*ALGEBRAIC(:,20)+ CONSTANTS(:,19).*ALGEBRAIC(:,50)+ CONSTANTS(:,20).*ALGEBRAIC(:,46))./(CONSTANTS(:,17)+CONSTANTS(:,18)+CONSTANTS(:,19)+CONSTANTS(:,20)) - ( CONSTANTS(:,5).*ALGEBRAIC(:,30))./(CONSTANTS(:,17)+CONSTANTS(:,18)+CONSTANTS(:,19)+CONSTANTS(:,20));
    ALGEBRAIC(:,53) = ( CONSTANTS(:,18).*(ALGEBRAIC(:,51) - ALGEBRAIC(:,20)))./CONSTANTS(:,5);
    ALGEBRAIC(:,49) = piecewise({ALGEBRAIC(:,19)>CONSTANTS(:,23), ( (power(ALGEBRAIC(:,19) - CONSTANTS(:,23), 10.0000)./(power(ALGEBRAIC(:,19) - CONSTANTS(:,23), 10.0000)+power(0.0300000, 10.0000))).*CONSTANTS(:,41).*CONSTANTS(:,22).*log( (( (ALGEBRAIC(:,19)./ALGEBRAIC(:,18)).*ALGEBRAIC(:,31))./ALGEBRAIC(:,29)).*power(ALGEBRAIC(:,48)./ALGEBRAIC(:,47), 2.00000)))./CONSTANTS(:,5) }, 0.00000);
    ALGEBRAIC(:,55) =  0.0100000.*( - ALGEBRAIC(:,53)+ 2.00000.*ALGEBRAIC(:,30)+ALGEBRAIC(:,49));
    RATES(:,10) = ALGEBRAIC(:,55);
    ALGEBRAIC(:,38) = ( CONSTANTS(:,4).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - ALGEBRAIC(:,36)))./CONSTANTS(:,5);
    ALGEBRAIC(:,40) = ( CONSTANTS(:,6).*power(STATES(:,4), 2.00000).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,36)))./CONSTANTS(:,5);
    ALGEBRAIC(:,42) = ( CONSTANTS(:,13).*(STATES(:,1) - ALGEBRAIC(:,36)))./CONSTANTS(:,5);
    RATES(:,13) =  -0.0100000.*(ALGEBRAIC(:,38)+ALGEBRAIC(:,40)+ALGEBRAIC(:,42)+ 3.00000.*ALGEBRAIC(:,34)) - ALGEBRAIC(:,55);
    ALGEBRAIC(:,54) = ( CONSTANTS(:,20).*(ALGEBRAIC(:,51) - ALGEBRAIC(:,46)))./CONSTANTS(:,5);
    RATES(:,14) =   - 0.0100000.*2.00000.*ALGEBRAIC(:,54);
    ALGEBRAIC(:,52) = ( CONSTANTS(:,17).*(ALGEBRAIC(:,51) - ALGEBRAIC(:,32)))./CONSTANTS(:,5);
    ALGEBRAIC(:,56) =  0.0100000.*(( - ALGEBRAIC(:,52) -  3.00000.*ALGEBRAIC(:,30))+ALGEBRAIC(:,49)+ALGEBRAIC(:,54));
    RATES(:,9) = ALGEBRAIC(:,56);
    RATES(:,12) =  0.0100000.*(( 3.00000.*ALGEBRAIC(:,34)+ALGEBRAIC(:,38)+ALGEBRAIC(:,40)+ALGEBRAIC(:,42)) -  100.000.*ALGEBRAIC(:,56));
   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) = ( 0.320000.*( - STATES(:,1) - 51.9000))./(exp( - ( 0.250000.*STATES(:,1)+12.9750)) - 1.00000);
    ALGEBRAIC(:,10) = ( 0.280000.*(STATES(:,1)+24.8900))./(exp( 0.200000.*STATES(:,1)+4.97800) - 1.00000);
    ALGEBRAIC(:,3) =  0.128000.*exp( - ( 0.0560000.*STATES(:,1)+2.94000));
    ALGEBRAIC(:,11) = 4.00000./(exp( - ( 0.200000.*STATES(:,1)+6.00000))+1.00000);
    ALGEBRAIC(:,4) = ( (1.00000./CONSTANTS(:,7)).*1.00000)./(exp( - ( 0.143000.*STATES(:,1)+5.67000))+1.00000);
    ALGEBRAIC(:,12) = ( (1.00000./CONSTANTS(:,7)).*exp( - ( 0.143000.*STATES(:,1)+5.67000)))./(exp( - ( 0.143000.*STATES(:,1)+5.67000))+1.00000);
    ALGEBRAIC(:,5) =  5.12000e-08.*exp( - ( 0.0560000.*STATES(:,1)+2.94000));
    ALGEBRAIC(:,13) = 1.60000e-06./(exp( - ( 0.200000.*STATES(:,1)+8.00000))+1.00000);
    ALGEBRAIC(:,6) = ( 0.0160000.*( - STATES(:,1) - 34.9000))./(exp( - ( 0.200000.*STATES(:,1)+6.98000)) - 1.00000);
    ALGEBRAIC(:,14) =  0.250000.*exp( - ( 0.0250000.*STATES(:,1)+1.25000));
    ALGEBRAIC(:,7) = ( 0.0200000.*( - STATES(:,1) - 56.9000))./(exp( - ( 0.100000.*STATES(:,1)+5.69000)) - 1.00000);
    ALGEBRAIC(:,15) = ( 0.0175000.*(STATES(:,1)+29.9000))./(exp( 0.100000.*STATES(:,1)+2.99000) - 1.00000);
    ALGEBRAIC(:,8) =  0.0160000.*exp( - ( 0.0560000.*STATES(:,1)+4.61000));
    ALGEBRAIC(:,16) = 0.500000./(exp( - ( 0.200000.*STATES(:,1)+11.9800))+1.00000);
    ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,2)&VOI<=CONSTANTS(:,3), 3500.00 }, 0.00000);
    ALGEBRAIC(:,33) = (( CONSTANTS(:,36).*CONSTANTS(:,30)+ CONSTANTS(:,27).*CONSTANTS(:,32)+ CONSTANTS(:,26).*CONSTANTS(:,31)) - (STATES(:,12)+STATES(:,9)))./CONSTANTS(:,36);
    ALGEBRAIC(:,17) = (CONSTANTS(:,27)+CONSTANTS(:,26)) - STATES(:,11);
    ALGEBRAIC(:,31) = STATES(:,12)./ALGEBRAIC(:,17);
    ALGEBRAIC(:,36) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,31)./ALGEBRAIC(:,33));
    ALGEBRAIC(:,37) =  CONSTANTS(:,4).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,39) =  CONSTANTS(:,6).*power(STATES(:,4), 2.00000).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,41) =  CONSTANTS(:,13).*(STATES(:,1) - ALGEBRAIC(:,36));
    ALGEBRAIC(:,19) = STATES(:,13)./ALGEBRAIC(:,17);
    ALGEBRAIC(:,21) = (( CONSTANTS(:,36).*CONSTANTS(:,33)+ CONSTANTS(:,27).*CONSTANTS(:,34)+ CONSTANTS(:,26).*CONSTANTS(:,23)) - (STATES(:,13)+STATES(:,10)))./CONSTANTS(:,36);
    ALGEBRAIC(:,22) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,19)./ALGEBRAIC(:,21));
    ALGEBRAIC(:,26) =  CONSTANTS(:,8).*power(STATES(:,6), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,27) =  CONSTANTS(:,9).*power(STATES(:,7), 2.00000).*STATES(:,8).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,28) =  CONSTANTS(:,14).*(STATES(:,1) - ALGEBRAIC(:,22));
    ALGEBRAIC(:,9) =  CONSTANTS(:,15).*(STATES(:,1) - CONSTANTS(:,16));
    ALGEBRAIC(:,34) = ( (( CONSTANTS(:,10).*power(ALGEBRAIC(:,33), 1.50000))./(power(ALGEBRAIC(:,33), 1.50000)+power(CONSTANTS(:,11), 1.50000))).*ALGEBRAIC(:,19))./(ALGEBRAIC(:,19)+CONSTANTS(:,12));
    ALGEBRAIC(:,35) =  ALGEBRAIC(:,34).*CONSTANTS(:,5);
    ALGEBRAIC(:,29) = STATES(:,9)./STATES(:,11);
    ALGEBRAIC(:,18) = STATES(:,10)./STATES(:,11);
    ALGEBRAIC(:,45) = (( CONSTANTS(:,27).*CONSTANTS(:,43)+ CONSTANTS(:,26).*CONSTANTS(:,35)) - STATES(:,14))./STATES(:,11);
    ALGEBRAIC(:,47) = (ALGEBRAIC(:,29)+ALGEBRAIC(:,18)) - (ALGEBRAIC(:,45)+( CONSTANTS(:,37).*CONSTANTS(:,25))./STATES(:,11));
    ALGEBRAIC(:,43) = ((CONSTANTS(:,29)+ALGEBRAIC(:,33)) - CONSTANTS(:,30))+(ALGEBRAIC(:,21) - CONSTANTS(:,33));
    ALGEBRAIC(:,48) = (( CONSTANTS(:,27).*CONSTANTS(:,42)+ CONSTANTS(:,26).*CONSTANTS(:,40)+ CONSTANTS(:,36).*CONSTANTS(:,29)) - ( STATES(:,11).*ALGEBRAIC(:,47)+ CONSTANTS(:,36).*ALGEBRAIC(:,43)))./ALGEBRAIC(:,17);
    ALGEBRAIC(:,44) = STATES(:,14)./ALGEBRAIC(:,17);
    ALGEBRAIC(:,30) = ( (( CONSTANTS(:,21).*power(ALGEBRAIC(:,29), 1.50000))./(power(ALGEBRAIC(:,29), 1.50000)+power(CONSTANTS(:,11), 1.50000))).*ALGEBRAIC(:,19))./(ALGEBRAIC(:,19)+CONSTANTS(:,12));
    ALGEBRAIC(:,32) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,31)./ALGEBRAIC(:,29));
    ALGEBRAIC(:,20) =  CONSTANTS(:,41).*log(ALGEBRAIC(:,19)./ALGEBRAIC(:,18));
    ALGEBRAIC(:,50) =   - 1.00000.*CONSTANTS(:,41).*log(ALGEBRAIC(:,48)./ALGEBRAIC(:,47));
    ALGEBRAIC(:,46) =   - CONSTANTS(:,41).*log( (ALGEBRAIC(:,31)./ALGEBRAIC(:,29)).*power(ALGEBRAIC(:,44)./ALGEBRAIC(:,45), 2.00000));
    ALGEBRAIC(:,51) = ( CONSTANTS(:,17).*ALGEBRAIC(:,32)+ CONSTANTS(:,18).*ALGEBRAIC(:,20)+ CONSTANTS(:,19).*ALGEBRAIC(:,50)+ CONSTANTS(:,20).*ALGEBRAIC(:,46))./(CONSTANTS(:,17)+CONSTANTS(:,18)+CONSTANTS(:,19)+CONSTANTS(:,20)) - ( CONSTANTS(:,5).*ALGEBRAIC(:,30))./(CONSTANTS(:,17)+CONSTANTS(:,18)+CONSTANTS(:,19)+CONSTANTS(:,20));
    ALGEBRAIC(:,53) = ( CONSTANTS(:,18).*(ALGEBRAIC(:,51) - ALGEBRAIC(:,20)))./CONSTANTS(:,5);
    ALGEBRAIC(:,49) = piecewise({ALGEBRAIC(:,19)>CONSTANTS(:,23), ( (power(ALGEBRAIC(:,19) - CONSTANTS(:,23), 10.0000)./(power(ALGEBRAIC(:,19) - CONSTANTS(:,23), 10.0000)+power(0.0300000, 10.0000))).*CONSTANTS(:,41).*CONSTANTS(:,22).*log( (( (ALGEBRAIC(:,19)./ALGEBRAIC(:,18)).*ALGEBRAIC(:,31))./ALGEBRAIC(:,29)).*power(ALGEBRAIC(:,48)./ALGEBRAIC(:,47), 2.00000)))./CONSTANTS(:,5) }, 0.00000);
    ALGEBRAIC(:,55) =  0.0100000.*( - ALGEBRAIC(:,53)+ 2.00000.*ALGEBRAIC(:,30)+ALGEBRAIC(:,49));
    ALGEBRAIC(:,38) = ( CONSTANTS(:,4).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - ALGEBRAIC(:,36)))./CONSTANTS(:,5);
    ALGEBRAIC(:,40) = ( CONSTANTS(:,6).*power(STATES(:,4), 2.00000).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,36)))./CONSTANTS(:,5);
    ALGEBRAIC(:,42) = ( CONSTANTS(:,13).*(STATES(:,1) - ALGEBRAIC(:,36)))./CONSTANTS(:,5);
    ALGEBRAIC(:,54) = ( CONSTANTS(:,20).*(ALGEBRAIC(:,51) - ALGEBRAIC(:,46)))./CONSTANTS(:,5);
    ALGEBRAIC(:,52) = ( CONSTANTS(:,17).*(ALGEBRAIC(:,51) - ALGEBRAIC(:,32)))./CONSTANTS(:,5);
    ALGEBRAIC(:,56) =  0.0100000.*(( - ALGEBRAIC(:,52) -  3.00000.*ALGEBRAIC(:,30))+ALGEBRAIC(:,49)+ALGEBRAIC(:,54));
    ALGEBRAIC(:,23) = ( CONSTANTS(:,8).*power(STATES(:,6), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,22)))./CONSTANTS(:,5);
    ALGEBRAIC(:,24) = ( CONSTANTS(:,9).*power(STATES(:,7), 2.00000).*STATES(:,8).*(STATES(:,1) - ALGEBRAIC(:,22)))./CONSTANTS(:,5);
    ALGEBRAIC(:,25) = ( CONSTANTS(:,14).*(STATES(:,1) - ALGEBRAIC(:,22)))./CONSTANTS(:,5);
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