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 =28;
end
% There are a total of 8 entries in each of the rate and state variable arrays.
% There are a total of 31 entries in the constant variable array.
%

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel()
    % Create ALGEBRAIC of correct size
    global algebraicVariableCount;  algebraicVariableCount = getAlgebraicVariableCount();
    % Initialise constants and state variables
    [INIT_STATES, CONSTANTS] = initConsts;

    % Set timespan to solve over 
    tspan = [0, 10];

    % Set numerical accuracy options for ODE solver
    options = odeset('RelTol', 1e-06, 'AbsTol', 1e-06, 'MaxStep', 1);

    % Solve model with ODE solver
    [VOI, STATES] = ode15s(@(VOI, STATES)computeRates(VOI, STATES, CONSTANTS), tspan, INIT_STATES, options);

    % Compute algebraic variables
    [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS);
    ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI);

    % Plot state variables against variable of integration
    [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends();
    figure();
    plot(VOI, STATES);
    xlabel(LEGEND_VOI);
    l = legend(LEGEND_STATES);
    set(l,'Interpreter','none');
end

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_STATES(:,1) = strpad('wi in component wi (micrometre)');
    LEGEND_CONSTANTS(:,1) = strpad('Lp in component model_parameters (cm_per_millimolar_second)');
    LEGEND_CONSTANTS(:,2) = strpad('Xi in component model_parameters (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,11) = strpad('Nao in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,7) = strpad('Ko in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,14) = strpad('Clo in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,19) = strpad('HCO3o in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,9) = strpad('Nai in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,6) = strpad('Ki in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,13) = strpad('Cli in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,18) = strpad('HCO3i in component model_parameters (millimolar)');
    LEGEND_ALGEBRAIC(:,1) = strpad('wo in component wo (micrometre)');
    LEGEND_CONSTANTS(:,3) = strpad('w_tot in component wo (micrometre)');
    LEGEND_STATES(:,2) = strpad('N_Nai in component N_Nai (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,26) = strpad('dN_Nai_dt in component N_Nai (millimolar_micrometre_per_second)');
    LEGEND_CONSTANTS(:,4) = strpad('gNa in component model_parameters (per_ohm_cm2)');
    LEGEND_ALGEBRAIC(:,12) = strpad('ENa in component Nernst_potentials (volt)');
    LEGEND_ALGEBRAIC(:,21) = strpad('Vm in component membrane (volt)');
    LEGEND_ALGEBRAIC(:,10) = strpad('J_NaKATPase in component J_NaKATPase (mole_per_cm2_second)');
    LEGEND_CONSTANTS(:,5) = strpad('F in component model_parameters (C_per_mol)');
    LEGEND_CONSTANTS(:,6) = strpad('theta_NKCC1 in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('J_NKCC1 in component J_NKCC1 (millimolar_micrometre_per_second)');
    LEGEND_CONSTANTS(:,7) = strpad('theta_NBC in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,25) = strpad('J_NBC in component J_NBC (millimolar_micrometre_per_second)');
    LEGEND_STATES(:,3) = strpad('N_Ki in component N_Ki (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,22) = strpad('dN_Ki_dt in component N_Ki (millimolar_micrometre_per_second)');
    LEGEND_CONSTANTS(:,8) = strpad('gK in component model_parameters (per_ohm_cm2)');
    LEGEND_ALGEBRAIC(:,8) = strpad('EK in component Nernst_potentials (volt)');
    LEGEND_CONSTANTS(:,9) = strpad('theta_KCC1 in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('J_KCC1 in component J_KCC1 (millimolar_micrometre_per_second)');
    LEGEND_STATES(:,4) = strpad('N_HCO3i in component N_HCO3i (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,28) = strpad('dN_HCO3i_dt in component N_HCO3i (millimolar_micrometre_per_second)');
    LEGEND_STATES(:,5) = strpad('N_Cli in component N_Cli (millimolar_micrometre)');
    LEGEND_STATES(:,6) = strpad('N_Nao in component N_Nao (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,5) = strpad('y in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,10) = strpad('kc in component model_parameters (micrometre_millimolar_per_second)');
    LEGEND_STATES(:,7) = strpad('N_Ko in component N_Ko (millimolar_micrometre)');
    LEGEND_STATES(:,8) = strpad('N_HCO3o in component N_HCO3o (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,2) = strpad('N_Clo in component N_Clo (millimolar_micrometre)');
    LEGEND_ALGEBRAIC(:,15) = strpad('ECl in component Nernst_potentials (volt)');
    LEGEND_CONSTANTS(:,11) = strpad('T in component model_parameters (kelvin)');
    LEGEND_CONSTANTS(:,12) = strpad('R in component model_parameters (J_per_mol_K)');
    LEGEND_CONSTANTS(:,13) = strpad('gKCC1 in component J_KCC1 (per_ohm_cm2)');
    LEGEND_ALGEBRAIC(:,3) = strpad('ft in component J_KCC1 (dimensionless)');
    LEGEND_CONSTANTS(:,14) = strpad('gNBC in component J_NBC (per_ohm_cm2)');
    LEGEND_ALGEBRAIC(:,20) = strpad('ENBC in component ENBC (volt)');
    LEGEND_CONSTANTS(:,15) = strpad('gNKCC1 in component J_NKCC1 (per_ohm_cm2)');
    LEGEND_ALGEBRAIC(:,4) = strpad('ft in component J_NKCC1 (dimensionless)');
    LEGEND_CONSTANTS(:,16) = strpad('zNBC in component ENBC (dimensionless)');
    LEGEND_CONSTANTS(:,17) = strpad('gCl in component model_parameters (per_ohm_cm2)');
    LEGEND_CONSTANTS(:,18) = strpad('Pmax in component J_NaKATPase (mole_per_cm2_second)');
    LEGEND_CONSTANTS(:,19) = strpad('K_Nai in component J_NaKATPase (millimolar)');
    LEGEND_CONSTANTS(:,20) = strpad('K_Ko in component J_NaKATPase (millimolar)');
    LEGEND_ALGEBRAIC(:,23) = strpad('I_K in component I_K (millimolar_micrometre_per_second)');
    LEGEND_CONSTANTS(:,21) = strpad('nA in component model_parameters (per_mole)');
    LEGEND_CONSTANTS(:,22) = strpad('elementary_charge in component model_parameters (C)');
    LEGEND_ALGEBRAIC(:,24) = strpad('I_Cl in component I_Cl (millimolar_micrometre_per_second)');
    LEGEND_ALGEBRAIC(:,27) = strpad('I_Na in component I_Na (millimolar_micrometre_per_second)');
    LEGEND_CONSTANTS(:,23) = strpad('t0 in component model_parameters (second)');
    LEGEND_CONSTANTS(:,24) = strpad('t1 in component model_parameters (second)');
    LEGEND_CONSTANTS(:,25) = strpad('t2 in component model_parameters (second)');
    LEGEND_CONSTANTS(:,26) = strpad('alpha in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,27) = strpad('beta in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,28) = strpad('deltaT in component model_parameters (second)');
    LEGEND_CONSTANTS(:,29) = strpad('gamma_alpha_beta in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,30) = strpad('gamma_alpha in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,31) = strpad('gamma_beta in component model_parameters (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt wi in component wi (micrometre)');
    LEGEND_RATES(:,2) = strpad('d/dt N_Nai in component N_Nai (millimolar_micrometre)');
    LEGEND_RATES(:,3) = strpad('d/dt N_Ki in component N_Ki (millimolar_micrometre)');
    LEGEND_RATES(:,4) = strpad('d/dt N_HCO3i in component N_HCO3i (millimolar_micrometre)');
    LEGEND_RATES(:,5) = strpad('d/dt N_Cli in component N_Cli (millimolar_micrometre)');
    LEGEND_RATES(:,6) = strpad('d/dt N_Nao in component N_Nao (millimolar_micrometre)');
    LEGEND_RATES(:,7) = strpad('d/dt N_Ko in component N_Ko (millimolar_micrometre)');
    LEGEND_RATES(:,8) = strpad('d/dt N_HCO3o in component N_HCO3o (millimolar_micrometre)');
    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.061;
    CONSTANTS(:,1) = 2.1e-4;
    CONSTANTS(:,2) = 12.41;
    CONSTANTS(:,3) = 0.0879;
    STATES(:,2) = 0.99796;
    CONSTANTS(:,4) = 1.314e-4;
    CONSTANTS(:,5) = 9.649e4;
    CONSTANTS(:,6) = 1;
    CONSTANTS(:,7) = 1;
    STATES(:,3) = 5.52782;
    CONSTANTS(:,8) = 0.004;
    CONSTANTS(:,9) = 1;
    STATES(:,4) = 0.58804;
    STATES(:,5) = 0.32879;
    STATES(:,6) = 4.301041;
    CONSTANTS(:,10) = 7.35e-2;
    STATES(:,7) = 0.0807;
    STATES(:,8) = 0.432552;
    CONSTANTS(:,11) = 300;
    CONSTANTS(:,12) = 8.315;
    CONSTANTS(:,13) = 1e-6;
    CONSTANTS(:,14) = 9.03e-5;
    CONSTANTS(:,15) = 5.54e-6;
    CONSTANTS(:,16) = -1;
    CONSTANTS(:,17) = 8.797e-5;
    CONSTANTS(:,18) = 1.4207e-10;
    CONSTANTS(:,19) = 10;
    CONSTANTS(:,20) = 1.5;
    CONSTANTS(:,21) = 6.0221415e23;
    CONSTANTS(:,22) = 1.6e-19;
    CONSTANTS(:,23) = 10;
    CONSTANTS(:,24) = 20;
    CONSTANTS(:,25) = 30;
    CONSTANTS(:,26) = 2;
    CONSTANTS(:,27) = 14;
    CONSTANTS(:,28) = CONSTANTS(:,24) - CONSTANTS(:,23);
    CONSTANTS(:,29) = factorial((CONSTANTS(:,26)+CONSTANTS(:,27)) - 1.00000);
    CONSTANTS(:,30) = factorial(CONSTANTS(:,26) - 1.00000);
    CONSTANTS(:,31) = factorial(CONSTANTS(:,27) - 1.00000);
    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);
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
    end
    ALGEBRAIC(:,1) = CONSTANTS(:,3) - STATES(:,1);
    ALGEBRAIC(:,11) = piecewise({STATES(:,6)./ALGEBRAIC(:,1)>0.00000, STATES(:,6)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,7) = piecewise({STATES(:,7)./ALGEBRAIC(:,1)>0.00000, STATES(:,7)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,2) = (STATES(:,6)+STATES(:,7)) - STATES(:,8);
    ALGEBRAIC(:,14) = piecewise({ALGEBRAIC(:,2)./ALGEBRAIC(:,1)>0.00000, ALGEBRAIC(:,2)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,19) = piecewise({STATES(:,8)./ALGEBRAIC(:,1)>0.00000, STATES(:,8)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,9) = piecewise({STATES(:,2)./STATES(:,1)>0.00000, STATES(:,2)./STATES(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,6) = piecewise({STATES(:,3)./STATES(:,1)>0.00000, STATES(:,3)./STATES(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,13) = piecewise({STATES(:,5)./STATES(:,1)>0.00000, STATES(:,5)./STATES(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,18) = piecewise({STATES(:,4)./STATES(:,1)>0.00000, STATES(:,4)./STATES(:,1) }, 1.00000e-180);
    RATES(:,1) =  1.00000.*CONSTANTS(:,1).*((ALGEBRAIC(:,9)+ALGEBRAIC(:,6)+ALGEBRAIC(:,13)+ALGEBRAIC(:,18)+CONSTANTS(:,2)./STATES(:,1)) - (ALGEBRAIC(:,11)+ALGEBRAIC(:,7)+ALGEBRAIC(:,14)+ALGEBRAIC(:,19)));
    ALGEBRAIC(:,12) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./( 1.00000.*CONSTANTS(:,5))).*log(ALGEBRAIC(:,11)./ALGEBRAIC(:,9));
    ALGEBRAIC(:,10) = ( (( CONSTANTS(:,18).*power(ALGEBRAIC(:,9), 1.50000))./(power(ALGEBRAIC(:,9), 1.50000)+power(CONSTANTS(:,19), 1.50000))).*ALGEBRAIC(:,7))./(ALGEBRAIC(:,7)+CONSTANTS(:,20));
    ALGEBRAIC(:,8) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./( 1.00000.*CONSTANTS(:,5))).*log(ALGEBRAIC(:,7)./ALGEBRAIC(:,6));
    ALGEBRAIC(:,15) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./(  - 1.00000.*CONSTANTS(:,5))).*log(ALGEBRAIC(:,14)./ALGEBRAIC(:,13));
    ALGEBRAIC(:,20) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./( CONSTANTS(:,16).*CONSTANTS(:,5))).*log(( (ALGEBRAIC(:,11)./ALGEBRAIC(:,9)).*power(ALGEBRAIC(:,19), 2.00000))./power(ALGEBRAIC(:,18), 2.00000));
    ALGEBRAIC(:,21) = (( CONSTANTS(:,4).*ALGEBRAIC(:,12)+ CONSTANTS(:,8).*ALGEBRAIC(:,8)+ CONSTANTS(:,17).*ALGEBRAIC(:,15)+ CONSTANTS(:,7).*CONSTANTS(:,14).*ALGEBRAIC(:,20)) -  ALGEBRAIC(:,10).*CONSTANTS(:,5))./(CONSTANTS(:,4)+CONSTANTS(:,8)+CONSTANTS(:,17)+ CONSTANTS(:,7).*CONSTANTS(:,14));
    ALGEBRAIC(:,4) = piecewise({VOI>=10.0000&VOI<20.0000, 1.00000 }, 0.00000);
    ALGEBRAIC(:,17) =  (( (( 1.00000e+10.*CONSTANTS(:,15).*ALGEBRAIC(:,4))./CONSTANTS(:,5)).*CONSTANTS(:,12).*CONSTANTS(:,11))./CONSTANTS(:,5)).*log( (( (ALGEBRAIC(:,11)./ALGEBRAIC(:,9)).*ALGEBRAIC(:,7))./ALGEBRAIC(:,6)).*power(ALGEBRAIC(:,14)./ALGEBRAIC(:,13), 2.00000));
    ALGEBRAIC(:,3) = piecewise({VOI>=10.0000&VOI<20.0000, 1.00000 }, 0.00000);
    ALGEBRAIC(:,16) =  (( (( 1.00000e+10.*CONSTANTS(:,13).*ALGEBRAIC(:,3))./CONSTANTS(:,5)).*CONSTANTS(:,12).*CONSTANTS(:,11))./CONSTANTS(:,5)).*log(( ALGEBRAIC(:,7).*ALGEBRAIC(:,14))./( ALGEBRAIC(:,6).*ALGEBRAIC(:,13)));
    ALGEBRAIC(:,5) = piecewise({VOI>=CONSTANTS(:,23)&VOI<=CONSTANTS(:,24),  (CONSTANTS(:,29)./( CONSTANTS(:,30).*CONSTANTS(:,31))).*power(1.00000 - (VOI - CONSTANTS(:,23))./CONSTANTS(:,28), CONSTANTS(:,27) - 1.00000).*power((VOI - CONSTANTS(:,23))./CONSTANTS(:,28), CONSTANTS(:,26) - 1.00000) , VOI>CONSTANTS(:,24)&VOI<CONSTANTS(:,25), -1.00000 }, 0.00000);
    RATES(:,7) = ( (( 1.00000e+10.*CONSTANTS(:,8))./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,8))+ CONSTANTS(:,10).*ALGEBRAIC(:,5)) - ( CONSTANTS(:,6).*ALGEBRAIC(:,17)+ CONSTANTS(:,9).*ALGEBRAIC(:,16)+ 1.00000e+10.*2.00000.*ALGEBRAIC(:,10));
    ALGEBRAIC(:,22) = ( CONSTANTS(:,6).*ALGEBRAIC(:,17)+ CONSTANTS(:,9).*ALGEBRAIC(:,16)+ 1.00000e+10.*2.00000.*ALGEBRAIC(:,10)) -  (( 1.00000e+10.*CONSTANTS(:,8))./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,8));
    RATES(:,3) = ALGEBRAIC(:,22);
    ALGEBRAIC(:,25) =  (( 1.00000e+10.*CONSTANTS(:,14))./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,20));
    RATES(:,6) =  1.00000e+10.*( (CONSTANTS(:,4)./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,12))+ 3.00000.*ALGEBRAIC(:,10)) - ( CONSTANTS(:,6).*ALGEBRAIC(:,17)+ CONSTANTS(:,7).*ALGEBRAIC(:,25)+ CONSTANTS(:,10).*ALGEBRAIC(:,5));
    RATES(:,8) =   - 2.00000.*CONSTANTS(:,7).*ALGEBRAIC(:,25);
    ALGEBRAIC(:,26) = ( CONSTANTS(:,6).*ALGEBRAIC(:,17)+ CONSTANTS(:,7).*ALGEBRAIC(:,25)) -  1.00000e+10.*( (CONSTANTS(:,4)./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,12))+ 3.00000.*ALGEBRAIC(:,10));
    RATES(:,2) = ALGEBRAIC(:,26);
    ALGEBRAIC(:,28) =  2.00000.*CONSTANTS(:,7).*ALGEBRAIC(:,25);
    RATES(:,4) = ALGEBRAIC(:,28);
    RATES(:,5) = ALGEBRAIC(:,22)+ALGEBRAIC(:,26)+ALGEBRAIC(:,28);
   RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
    ALGEBRAIC(:,1) = CONSTANTS(:,3) - STATES(:,1);
    ALGEBRAIC(:,11) = piecewise({STATES(:,6)./ALGEBRAIC(:,1)>0.00000, STATES(:,6)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,7) = piecewise({STATES(:,7)./ALGEBRAIC(:,1)>0.00000, STATES(:,7)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,2) = (STATES(:,6)+STATES(:,7)) - STATES(:,8);
    ALGEBRAIC(:,14) = piecewise({ALGEBRAIC(:,2)./ALGEBRAIC(:,1)>0.00000, ALGEBRAIC(:,2)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,19) = piecewise({STATES(:,8)./ALGEBRAIC(:,1)>0.00000, STATES(:,8)./ALGEBRAIC(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,9) = piecewise({STATES(:,2)./STATES(:,1)>0.00000, STATES(:,2)./STATES(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,6) = piecewise({STATES(:,3)./STATES(:,1)>0.00000, STATES(:,3)./STATES(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,13) = piecewise({STATES(:,5)./STATES(:,1)>0.00000, STATES(:,5)./STATES(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,18) = piecewise({STATES(:,4)./STATES(:,1)>0.00000, STATES(:,4)./STATES(:,1) }, 1.00000e-180);
    ALGEBRAIC(:,12) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./( 1.00000.*CONSTANTS(:,5))).*log(ALGEBRAIC(:,11)./ALGEBRAIC(:,9));
    ALGEBRAIC(:,10) = ( (( CONSTANTS(:,18).*power(ALGEBRAIC(:,9), 1.50000))./(power(ALGEBRAIC(:,9), 1.50000)+power(CONSTANTS(:,19), 1.50000))).*ALGEBRAIC(:,7))./(ALGEBRAIC(:,7)+CONSTANTS(:,20));
    ALGEBRAIC(:,8) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./( 1.00000.*CONSTANTS(:,5))).*log(ALGEBRAIC(:,7)./ALGEBRAIC(:,6));
    ALGEBRAIC(:,15) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./(  - 1.00000.*CONSTANTS(:,5))).*log(ALGEBRAIC(:,14)./ALGEBRAIC(:,13));
    ALGEBRAIC(:,20) =  (( CONSTANTS(:,12).*CONSTANTS(:,11))./( CONSTANTS(:,16).*CONSTANTS(:,5))).*log(( (ALGEBRAIC(:,11)./ALGEBRAIC(:,9)).*power(ALGEBRAIC(:,19), 2.00000))./power(ALGEBRAIC(:,18), 2.00000));
    ALGEBRAIC(:,21) = (( CONSTANTS(:,4).*ALGEBRAIC(:,12)+ CONSTANTS(:,8).*ALGEBRAIC(:,8)+ CONSTANTS(:,17).*ALGEBRAIC(:,15)+ CONSTANTS(:,7).*CONSTANTS(:,14).*ALGEBRAIC(:,20)) -  ALGEBRAIC(:,10).*CONSTANTS(:,5))./(CONSTANTS(:,4)+CONSTANTS(:,8)+CONSTANTS(:,17)+ CONSTANTS(:,7).*CONSTANTS(:,14));
    ALGEBRAIC(:,4) = piecewise({VOI>=10.0000&VOI<20.0000, 1.00000 }, 0.00000);
    ALGEBRAIC(:,17) =  (( (( 1.00000e+10.*CONSTANTS(:,15).*ALGEBRAIC(:,4))./CONSTANTS(:,5)).*CONSTANTS(:,12).*CONSTANTS(:,11))./CONSTANTS(:,5)).*log( (( (ALGEBRAIC(:,11)./ALGEBRAIC(:,9)).*ALGEBRAIC(:,7))./ALGEBRAIC(:,6)).*power(ALGEBRAIC(:,14)./ALGEBRAIC(:,13), 2.00000));
    ALGEBRAIC(:,3) = piecewise({VOI>=10.0000&VOI<20.0000, 1.00000 }, 0.00000);
    ALGEBRAIC(:,16) =  (( (( 1.00000e+10.*CONSTANTS(:,13).*ALGEBRAIC(:,3))./CONSTANTS(:,5)).*CONSTANTS(:,12).*CONSTANTS(:,11))./CONSTANTS(:,5)).*log(( ALGEBRAIC(:,7).*ALGEBRAIC(:,14))./( ALGEBRAIC(:,6).*ALGEBRAIC(:,13)));
    ALGEBRAIC(:,5) = piecewise({VOI>=CONSTANTS(:,23)&VOI<=CONSTANTS(:,24),  (CONSTANTS(:,29)./( CONSTANTS(:,30).*CONSTANTS(:,31))).*power(1.00000 - (VOI - CONSTANTS(:,23))./CONSTANTS(:,28), CONSTANTS(:,27) - 1.00000).*power((VOI - CONSTANTS(:,23))./CONSTANTS(:,28), CONSTANTS(:,26) - 1.00000) , VOI>CONSTANTS(:,24)&VOI<CONSTANTS(:,25), -1.00000 }, 0.00000);
    ALGEBRAIC(:,22) = ( CONSTANTS(:,6).*ALGEBRAIC(:,17)+ CONSTANTS(:,9).*ALGEBRAIC(:,16)+ 1.00000e+10.*2.00000.*ALGEBRAIC(:,10)) -  (( 1.00000e+10.*CONSTANTS(:,8))./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,8));
    ALGEBRAIC(:,25) =  (( 1.00000e+10.*CONSTANTS(:,14))./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,20));
    ALGEBRAIC(:,26) = ( CONSTANTS(:,6).*ALGEBRAIC(:,17)+ CONSTANTS(:,7).*ALGEBRAIC(:,25)) -  1.00000e+10.*( (CONSTANTS(:,4)./CONSTANTS(:,5)).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,12))+ 3.00000.*ALGEBRAIC(:,10));
    ALGEBRAIC(:,28) =  2.00000.*CONSTANTS(:,7).*ALGEBRAIC(:,25);
    ALGEBRAIC(:,23) = ( 1.00000e+10.*2.00000.*ALGEBRAIC(:,10).*CONSTANTS(:,5))./( CONSTANTS(:,22).*CONSTANTS(:,21)) -  (( 1.00000e+10.*CONSTANTS(:,8))./( CONSTANTS(:,22).*CONSTANTS(:,21))).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,8));
    ALGEBRAIC(:,24) =  (( 1.00000e+10.*CONSTANTS(:,17))./( CONSTANTS(:,22).*CONSTANTS(:,21))).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,15));
    ALGEBRAIC(:,27) = ALGEBRAIC(:,25) - ( (( 1.00000e+10.*CONSTANTS(:,4))./( CONSTANTS(:,22).*CONSTANTS(:,21))).*(ALGEBRAIC(:,21) - ALGEBRAIC(:,12))+( 1.00000e+10.*3.00000.*ALGEBRAIC(:,10).*CONSTANTS(:,5))./( CONSTANTS(:,22).*CONSTANTS(:,21)));
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