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

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('t in component environment (second)');
    LEGEND_CONSTANTS(:,1) = strpad('R in component environment (J_per_K_per_mol)');
    LEGEND_CONSTANTS(:,2) = strpad('T in component environment (kelvin)');
    LEGEND_CONSTANTS(:,3) = strpad('F in component environment (C_per_mol)');
    LEGEND_CONSTANTS(:,4) = strpad('C_m in component environment (fF)');
    LEGEND_STATES(:,1) = strpad('q_Na_o in component environment (fmol)');
    LEGEND_STATES(:,2) = strpad('q_Na_i in component environment (fmol)');
    LEGEND_STATES(:,3) = strpad('q_S000_Na in component environment (fmol)');
    LEGEND_STATES(:,4) = strpad('q_S010_Na in component environment (fmol)');
    LEGEND_STATES(:,5) = strpad('q_S100_Na in component environment (fmol)');
    LEGEND_STATES(:,6) = strpad('q_S110_Na in component environment (fmol)');
    LEGEND_STATES(:,7) = strpad('q_S200_Na in component environment (fmol)');
    LEGEND_STATES(:,8) = strpad('q_S210_Na in component environment (fmol)');
    LEGEND_STATES(:,9) = strpad('q_S300_Na in component environment (fmol)');
    LEGEND_STATES(:,10) = strpad('q_S310_Na in component environment (fmol)');
    LEGEND_STATES(:,11) = strpad('q_S001_Na in component environment (fmol)');
    LEGEND_STATES(:,12) = strpad('q_S011_Na in component environment (fmol)');
    LEGEND_STATES(:,13) = strpad('q_S101_Na in component environment (fmol)');
    LEGEND_STATES(:,14) = strpad('q_S111_Na in component environment (fmol)');
    LEGEND_STATES(:,15) = strpad('q_S201_Na in component environment (fmol)');
    LEGEND_STATES(:,16) = strpad('q_S211_Na in component environment (fmol)');
    LEGEND_STATES(:,17) = strpad('q_S301_Na in component environment (fmol)');
    LEGEND_STATES(:,18) = strpad('q_S311_Na in component environment (fmol)');
    LEGEND_ALGEBRAIC(:,121) = strpad('v_Na in component fast_Na (fmol_per_sec)');
    LEGEND_STATES(:,19) = strpad('q_mem in component environment (fC)');
    LEGEND_ALGEBRAIC(:,123) = strpad('I_mem_Na in component fast_Na (fA)');
    LEGEND_CONSTANTS(:,5) = strpad('K_000_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,6) = strpad('K_001_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,7) = strpad('K_010_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,8) = strpad('K_011_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,9) = strpad('K_100_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,10) = strpad('K_101_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,11) = strpad('K_110_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,12) = strpad('K_111_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,13) = strpad('K_200_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,14) = strpad('K_201_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,15) = strpad('K_210_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,16) = strpad('K_211_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,17) = strpad('K_300_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,18) = strpad('K_301_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,19) = strpad('K_310_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,20) = strpad('K_311_Na in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,21) = strpad('K_Na_o in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,22) = strpad('K_Na_i in component Na_parameters (per_fmol)');
    LEGEND_CONSTANTS(:,23) = strpad('kappa_Na in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,24) = strpad('kappa_h000 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,25) = strpad('kappa_h001 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,26) = strpad('kappa_h100 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,27) = strpad('kappa_h101 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,28) = strpad('kappa_h200 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,29) = strpad('kappa_h201 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,30) = strpad('kappa_h300 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,31) = strpad('kappa_h301 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,32) = strpad('kappa_j000 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,33) = strpad('kappa_j010 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,34) = strpad('kappa_j100 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,35) = strpad('kappa_j110 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,36) = strpad('kappa_j200 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,37) = strpad('kappa_j210 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,38) = strpad('kappa_j300 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,39) = strpad('kappa_j310 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,40) = strpad('kappa_m000 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,41) = strpad('kappa_m001 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,42) = strpad('kappa_m010 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,43) = strpad('kappa_m011 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,44) = strpad('kappa_m100 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,45) = strpad('kappa_m101 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,46) = strpad('kappa_m110 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,47) = strpad('kappa_m111 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,48) = strpad('kappa_m200 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,49) = strpad('kappa_m201 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,50) = strpad('kappa_m210 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,51) = strpad('kappa_m211 in component Na_parameters (fmol_per_sec)');
    LEGEND_CONSTANTS(:,52) = strpad('zNa in component Na_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,53) = strpad('z_fh in component Na_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('z_fj in component Na_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,55) = strpad('z_fm in component Na_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,56) = strpad('z_rh in component Na_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,57) = strpad('z_rj in component Na_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,58) = strpad('z_rm in component Na_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('mu_Na_o in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,18) = strpad('mu_Na_i in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,2) = strpad('mu_S000_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,3) = strpad('mu_S010_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,4) = strpad('mu_S100_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,5) = strpad('mu_S110_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,6) = strpad('mu_S200_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,7) = strpad('mu_S210_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,8) = strpad('mu_S300_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,9) = strpad('mu_S310_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,10) = strpad('mu_S001_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,11) = strpad('mu_S011_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,12) = strpad('mu_S101_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,13) = strpad('mu_S111_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,14) = strpad('mu_S201_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,15) = strpad('mu_S211_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,16) = strpad('mu_S301_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,19) = strpad('mu_S311_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,49) = strpad('Am_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,20) = strpad('Af_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,50) = strpad('Ar_Na in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,21) = strpad('Af_h000 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,51) = strpad('Ar_h000 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,52) = strpad('v_h000 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,22) = strpad('Af_h001 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,53) = strpad('Ar_h001 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,54) = strpad('v_h001 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,23) = strpad('Af_h100 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,55) = strpad('Ar_h100 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,56) = strpad('v_h100 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,24) = strpad('Af_h101 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,57) = strpad('Ar_h101 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,58) = strpad('v_h101 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,25) = strpad('Af_h200 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,59) = strpad('Ar_h200 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,60) = strpad('v_h200 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,26) = strpad('Af_h201 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,61) = strpad('Ar_h201 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,62) = strpad('v_h201 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,27) = strpad('Af_h300 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,63) = strpad('Ar_h300 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,64) = strpad('v_h300 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,28) = strpad('Af_h301 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,65) = strpad('Ar_h301 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,66) = strpad('v_h301 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,29) = strpad('Af_j000 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,67) = strpad('Ar_j000 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,68) = strpad('v_j000 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,30) = strpad('Af_j010 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,69) = strpad('Ar_j010 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,70) = strpad('v_j010 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,31) = strpad('Af_j100 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,71) = strpad('Ar_j100 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,72) = strpad('v_j100 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,32) = strpad('Af_j110 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,73) = strpad('Ar_j110 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,74) = strpad('v_j110 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,33) = strpad('Af_j200 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,75) = strpad('Ar_j200 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,76) = strpad('v_j200 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,34) = strpad('Af_j210 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,77) = strpad('Ar_j210 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,78) = strpad('v_j210 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,35) = strpad('Af_j300 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,79) = strpad('Ar_j300 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,80) = strpad('v_j300 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,36) = strpad('Af_j310 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,81) = strpad('Ar_j310 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,82) = strpad('v_j310 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,37) = strpad('Af_m000 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,83) = strpad('Ar_m000 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,84) = strpad('v_m000 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,38) = strpad('Af_m001 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,85) = strpad('Ar_m001 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,87) = strpad('v_m001 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,39) = strpad('Af_m010 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,88) = strpad('Ar_m010 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,90) = strpad('v_m010 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,40) = strpad('Af_m011 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,91) = strpad('Ar_m011 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,93) = strpad('v_m011 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,41) = strpad('Af_m100 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,94) = strpad('Ar_m100 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,96) = strpad('v_m100 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,42) = strpad('Af_m101 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,97) = strpad('Ar_m101 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,99) = strpad('v_m101 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,43) = strpad('Af_m110 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,100) = strpad('Ar_m110 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,102) = strpad('v_m110 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,44) = strpad('Af_m111 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,103) = strpad('Ar_m111 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,105) = strpad('v_m111 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,45) = strpad('Af_m200 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,106) = strpad('Ar_m200 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,108) = strpad('v_m200 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,46) = strpad('Af_m201 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,109) = strpad('Ar_m201 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,112) = strpad('v_m201 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,47) = strpad('Af_m210 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,113) = strpad('Ar_m210 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,116) = strpad('v_m210 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,48) = strpad('Af_m211 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,117) = strpad('Ar_m211 in component fast_Na (J_per_mol)');
    LEGEND_ALGEBRAIC(:,120) = strpad('v_m211 in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,86) = strpad('v_S000_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,92) = strpad('v_S010_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,98) = strpad('v_S100_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,104) = strpad('v_S110_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,110) = strpad('v_S200_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,118) = strpad('v_S210_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,111) = strpad('v_S300_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,119) = strpad('v_S310_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,89) = strpad('v_S001_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,95) = strpad('v_S011_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,101) = strpad('v_S101_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,107) = strpad('v_S111_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,114) = strpad('v_S201_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,122) = strpad('v_S211_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,115) = strpad('v_S301_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,124) = strpad('v_S311_Na in component fast_Na (fmol_per_sec)');
    LEGEND_ALGEBRAIC(:,1) = strpad('V_mem in component fast_Na (volt)');
    LEGEND_RATES(:,1) = strpad('d/dt q_Na_o in component environment (fmol)');
    LEGEND_RATES(:,2) = strpad('d/dt q_Na_i in component environment (fmol)');
    LEGEND_RATES(:,19) = strpad('d/dt q_mem in component environment (fC)');
    LEGEND_RATES(:,3) = strpad('d/dt q_S000_Na in component environment (fmol)');
    LEGEND_RATES(:,4) = strpad('d/dt q_S010_Na in component environment (fmol)');
    LEGEND_RATES(:,5) = strpad('d/dt q_S100_Na in component environment (fmol)');
    LEGEND_RATES(:,6) = strpad('d/dt q_S110_Na in component environment (fmol)');
    LEGEND_RATES(:,7) = strpad('d/dt q_S200_Na in component environment (fmol)');
    LEGEND_RATES(:,8) = strpad('d/dt q_S210_Na in component environment (fmol)');
    LEGEND_RATES(:,9) = strpad('d/dt q_S300_Na in component environment (fmol)');
    LEGEND_RATES(:,10) = strpad('d/dt q_S310_Na in component environment (fmol)');
    LEGEND_RATES(:,11) = strpad('d/dt q_S001_Na in component environment (fmol)');
    LEGEND_RATES(:,12) = strpad('d/dt q_S011_Na in component environment (fmol)');
    LEGEND_RATES(:,13) = strpad('d/dt q_S101_Na in component environment (fmol)');
    LEGEND_RATES(:,14) = strpad('d/dt q_S111_Na in component environment (fmol)');
    LEGEND_RATES(:,15) = strpad('d/dt q_S201_Na in component environment (fmol)');
    LEGEND_RATES(:,16) = strpad('d/dt q_S211_Na in component environment (fmol)');
    LEGEND_RATES(:,17) = strpad('d/dt q_S301_Na in component environment (fmol)');
    LEGEND_RATES(:,18) = strpad('d/dt q_S311_Na in component environment (fmol)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    CONSTANTS(:,1) = 8.314;
    CONSTANTS(:,2) = 310;
    CONSTANTS(:,3) = 96485;
    CONSTANTS(:,4) = 153400;
    STATES(:,1) = 725.48;
    STATES(:,2) = 380;
    STATES(:,3) = 1.72572E-05;
    STATES(:,4) = 1.91747E-06;
    STATES(:,5) = 5.75256E-06;
    STATES(:,6) = 6.39176E-07;
    STATES(:,7) = 6.39176E-07;
    STATES(:,8) = 7.10196E-08;
    STATES(:,9) = 2.36737E-08;
    STATES(:,10) = 2.63039E-09;
    STATES(:,11) = 1.91747E-06;
    STATES(:,12) = 2.13059E-07;
    STATES(:,13) = 6.39176E-07;
    STATES(:,14) = 7.10196E-08;
    STATES(:,15) = 7.10196E-08;
    STATES(:,16) = 7.89103E-09;
    STATES(:,17) = 2.63039E-09;
    STATES(:,18) = 2.92267E-10;
    STATES(:,19) = -13039;
    CONSTANTS(:,5) = 0.0073376;
    CONSTANTS(:,6) = 23718.0222;
    CONSTANTS(:,7) = 17499.8767;
    CONSTANTS(:,8) = 56566767727.4036;
    CONSTANTS(:,9) = 1.5633e-05;
    CONSTANTS(:,10) = 50.5317;
    CONSTANTS(:,11) = 37.2839;
    CONSTANTS(:,12) = 120516694.0958;
    CONSTANTS(:,13) = 9.9918e-08;
    CONSTANTS(:,14) = 0.32298;
    CONSTANTS(:,15) = 0.2383;
    CONSTANTS(:,16) = 770290.0911;
    CONSTANTS(:,17) = 1.9159e-09;
    CONSTANTS(:,18) = 0.006193;
    CONSTANTS(:,19) = 0.0045694;
    CONSTANTS(:,20) = 14770.0739;
    CONSTANTS(:,21) = 0.017678;
    CONSTANTS(:,22) = 0.0024108;
    CONSTANTS(:,23) = 32.858;
    CONSTANTS(:,24) = 0.045709;
    CONSTANTS(:,25) = 1.4141e-08;
    CONSTANTS(:,26) = 21.4544;
    CONSTANTS(:,27) = 6.6373e-06;
    CONSTANTS(:,28) = 3356.675;
    CONSTANTS(:,29) = 0.0010384;
    CONSTANTS(:,30) = 175057.5863;
    CONSTANTS(:,31) = 0.054157;
    CONSTANTS(:,32) = 0.017824;
    CONSTANTS(:,33) = 7.4736e-09;
    CONSTANTS(:,34) = 8.3662;
    CONSTANTS(:,35) = 3.5079e-06;
    CONSTANTS(:,36) = 1308.9427;
    CONSTANTS(:,37) = 0.00054883;
    CONSTANTS(:,38) = 68264.0876;
    CONSTANTS(:,39) = 0.028623;
    CONSTANTS(:,40) = 5117405.6443;
    CONSTANTS(:,41) = 1.5832;
    CONSTANTS(:,42) = 2.1457;
    CONSTANTS(:,43) = 6.6381e-07;
    CONSTANTS(:,44) = 1601300127.6001;
    CONSTANTS(:,45) = 495.389;
    CONSTANTS(:,46) = 671.4132;
    CONSTANTS(:,47) = 0.00020771;
    CONSTANTS(:,48) = 125266701374.7363;
    CONSTANTS(:,49) = 38753.3515;
    CONSTANTS(:,50) = 52523.3901;
    CONSTANTS(:,51) = 0.016249;
    CONSTANTS(:,52) = 1;
    CONSTANTS(:,53) = -4.1892;
    CONSTANTS(:,54) = -4.0381;
    CONSTANTS(:,55) = 0.49541;
    CONSTANTS(:,56) = 1.2995;
    CONSTANTS(:,57) = 1.4281;
    CONSTANTS(:,58) = -2.4284;
    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(:,1) = STATES(:,19)./CONSTANTS(:,4);
    ALGEBRAIC(:,21) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,5).*STATES(:,3))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,51) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,7).*STATES(:,4))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,52) =  CONSTANTS(:,24).*(exp(ALGEBRAIC(:,21)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,51)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,29) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,5).*STATES(:,3))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,67) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,6).*STATES(:,11))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,68) =  CONSTANTS(:,32).*(exp(ALGEBRAIC(:,29)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,67)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,37) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,5).*STATES(:,3))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,83) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,84) =  CONSTANTS(:,40).*(exp(ALGEBRAIC(:,37)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,83)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,86) = ( - ALGEBRAIC(:,84) - ALGEBRAIC(:,52)) - ALGEBRAIC(:,68);
    RATES(:,3) = ALGEBRAIC(:,86);
    ALGEBRAIC(:,22) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,6).*STATES(:,11))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,53) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,8).*STATES(:,12))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,54) =  CONSTANTS(:,25).*(exp(ALGEBRAIC(:,22)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,53)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,38) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,6).*STATES(:,11))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,85) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,87) =  CONSTANTS(:,41).*(exp(ALGEBRAIC(:,38)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,85)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,89) = ( - ALGEBRAIC(:,87) - ALGEBRAIC(:,54)) -  - ALGEBRAIC(:,68);
    RATES(:,11) = ALGEBRAIC(:,89);
    ALGEBRAIC(:,30) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,7).*STATES(:,4))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,69) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,8).*STATES(:,12))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,70) =  CONSTANTS(:,33).*(exp(ALGEBRAIC(:,30)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,69)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,39) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,7).*STATES(:,4))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,88) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,90) =  CONSTANTS(:,42).*(exp(ALGEBRAIC(:,39)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,88)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,92) = ( - ALGEBRAIC(:,90)+ALGEBRAIC(:,52)) - ALGEBRAIC(:,70);
    RATES(:,4) = ALGEBRAIC(:,92);
    ALGEBRAIC(:,40) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,8).*STATES(:,12))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,91) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,93) =  CONSTANTS(:,43).*(exp(ALGEBRAIC(:,40)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,91)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,95) = ( - ALGEBRAIC(:,93)+ALGEBRAIC(:,54)) -  - ALGEBRAIC(:,70);
    RATES(:,12) = ALGEBRAIC(:,95);
    ALGEBRAIC(:,23) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,55) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,56) =  CONSTANTS(:,26).*(exp(ALGEBRAIC(:,23)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,55)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,31) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,71) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,72) =  CONSTANTS(:,34).*(exp(ALGEBRAIC(:,31)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,71)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,41) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,94) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,96) =  CONSTANTS(:,44).*(exp(ALGEBRAIC(:,41)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,94)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,98) = ((ALGEBRAIC(:,84) - ALGEBRAIC(:,96)) - ALGEBRAIC(:,56)) - ALGEBRAIC(:,72);
    RATES(:,5) = ALGEBRAIC(:,98);
    ALGEBRAIC(:,24) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,57) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,58) =  CONSTANTS(:,27).*(exp(ALGEBRAIC(:,24)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,57)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,42) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,97) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,99) =  CONSTANTS(:,45).*(exp(ALGEBRAIC(:,42)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,97)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,101) = ((ALGEBRAIC(:,87) - ALGEBRAIC(:,99)) - ALGEBRAIC(:,58)) -  - ALGEBRAIC(:,72);
    RATES(:,13) = ALGEBRAIC(:,101);
    ALGEBRAIC(:,32) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,73) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,74) =  CONSTANTS(:,35).*(exp(ALGEBRAIC(:,32)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,73)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,43) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,100) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,102) =  CONSTANTS(:,46).*(exp(ALGEBRAIC(:,43)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,100)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,104) = ((ALGEBRAIC(:,90) - ALGEBRAIC(:,102))+ALGEBRAIC(:,56)) - ALGEBRAIC(:,74);
    RATES(:,6) = ALGEBRAIC(:,104);
    ALGEBRAIC(:,44) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,103) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,105) =  CONSTANTS(:,47).*(exp(ALGEBRAIC(:,44)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,103)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,107) = ((ALGEBRAIC(:,93) - ALGEBRAIC(:,105))+ALGEBRAIC(:,58)) -  - ALGEBRAIC(:,74);
    RATES(:,14) = ALGEBRAIC(:,107);
    ALGEBRAIC(:,25) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,59) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,60) =  CONSTANTS(:,28).*(exp(ALGEBRAIC(:,25)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,59)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,33) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,75) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,76) =  CONSTANTS(:,36).*(exp(ALGEBRAIC(:,33)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,75)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,45) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,106) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,17).*STATES(:,9))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,108) =  CONSTANTS(:,48).*(exp(ALGEBRAIC(:,45)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,106)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,110) = ((ALGEBRAIC(:,96) - ALGEBRAIC(:,108)) - ALGEBRAIC(:,60)) - ALGEBRAIC(:,76);
    RATES(:,7) = ALGEBRAIC(:,110);
    ALGEBRAIC(:,27) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,17).*STATES(:,9))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,63) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,19).*STATES(:,10))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,64) =  CONSTANTS(:,30).*(exp(ALGEBRAIC(:,27)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,63)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,35) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,17).*STATES(:,9))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,79) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,18).*STATES(:,17))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,80) =  CONSTANTS(:,38).*(exp(ALGEBRAIC(:,35)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,79)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,111) = (ALGEBRAIC(:,108) - ALGEBRAIC(:,64)) - ALGEBRAIC(:,80);
    RATES(:,9) = ALGEBRAIC(:,111);
    ALGEBRAIC(:,26) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,61) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,62) =  CONSTANTS(:,29).*(exp(ALGEBRAIC(:,26)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,61)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,46) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,109) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,18).*STATES(:,17))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,112) =  CONSTANTS(:,49).*(exp(ALGEBRAIC(:,46)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,109)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,114) = ((ALGEBRAIC(:,99) - ALGEBRAIC(:,112)) - ALGEBRAIC(:,62)) -  - ALGEBRAIC(:,76);
    RATES(:,15) = ALGEBRAIC(:,114);
    ALGEBRAIC(:,28) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,18).*STATES(:,17))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,65) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,66) =  CONSTANTS(:,31).*(exp(ALGEBRAIC(:,28)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,65)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,115) = (ALGEBRAIC(:,112) - ALGEBRAIC(:,66)) -  - ALGEBRAIC(:,80);
    RATES(:,17) = ALGEBRAIC(:,115);
    ALGEBRAIC(:,34) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,77) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,78) =  CONSTANTS(:,37).*(exp(ALGEBRAIC(:,34)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,77)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,47) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,113) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,19).*STATES(:,10))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,116) =  CONSTANTS(:,50).*(exp(ALGEBRAIC(:,47)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,113)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,118) = ((ALGEBRAIC(:,102) - ALGEBRAIC(:,116))+ALGEBRAIC(:,60)) - ALGEBRAIC(:,78);
    RATES(:,8) = ALGEBRAIC(:,118);
    ALGEBRAIC(:,36) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,19).*STATES(:,10))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,81) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,82) =  CONSTANTS(:,39).*(exp(ALGEBRAIC(:,36)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,81)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,119) = (ALGEBRAIC(:,116)+ALGEBRAIC(:,64)) - ALGEBRAIC(:,82);
    RATES(:,10) = ALGEBRAIC(:,119);
    ALGEBRAIC(:,49) =  CONSTANTS(:,52).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,18) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,22).*STATES(:,2));
    ALGEBRAIC(:,19) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18));
    ALGEBRAIC(:,20) = ALGEBRAIC(:,18)+ CONSTANTS(:,52).*CONSTANTS(:,3).*ALGEBRAIC(:,1)+ALGEBRAIC(:,19);
    ALGEBRAIC(:,17) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,21).*STATES(:,1));
    ALGEBRAIC(:,50) = ALGEBRAIC(:,17)+ALGEBRAIC(:,19);
    ALGEBRAIC(:,121) = piecewise({ALGEBRAIC(:,49)==0.00000,  CONSTANTS(:,23).*(exp(ALGEBRAIC(:,20)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,50)./( CONSTANTS(:,1).*CONSTANTS(:,2)))) },  ((( CONSTANTS(:,23).*ALGEBRAIC(:,49))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(exp(ALGEBRAIC(:,49)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*(exp(ALGEBRAIC(:,20)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,50)./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    RATES(:,1) = ALGEBRAIC(:,121);
    RATES(:,2) =  - ALGEBRAIC(:,121);
    ALGEBRAIC(:,48) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,117) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,120) =  CONSTANTS(:,51).*(exp(ALGEBRAIC(:,48)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,117)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,122) = ((ALGEBRAIC(:,105) - ALGEBRAIC(:,120))+ALGEBRAIC(:,62)) -  - ALGEBRAIC(:,78);
    RATES(:,16) = ALGEBRAIC(:,122);
    ALGEBRAIC(:,123) =  CONSTANTS(:,3).*((((((((((((((((((((((((((((((((((((((((((((((((((((((((  - CONSTANTS(:,52).*ALGEBRAIC(:,121)+ CONSTANTS(:,58).*ALGEBRAIC(:,84)) -  CONSTANTS(:,55).*ALGEBRAIC(:,84))+ CONSTANTS(:,58).*ALGEBRAIC(:,96)) -  CONSTANTS(:,55).*ALGEBRAIC(:,96))+ CONSTANTS(:,58).*ALGEBRAIC(:,90)) -  CONSTANTS(:,55).*ALGEBRAIC(:,90))+ CONSTANTS(:,58).*ALGEBRAIC(:,102)) -  CONSTANTS(:,55).*ALGEBRAIC(:,102))+ CONSTANTS(:,58).*ALGEBRAIC(:,116)) -  CONSTANTS(:,55).*ALGEBRAIC(:,116))+ CONSTANTS(:,56).*ALGEBRAIC(:,52)) -  CONSTANTS(:,53).*ALGEBRAIC(:,52))+ CONSTANTS(:,56).*ALGEBRAIC(:,60)) -  CONSTANTS(:,53).*ALGEBRAIC(:,60))+ CONSTANTS(:,57).*ALGEBRAIC(:,72)) -  CONSTANTS(:,54).*ALGEBRAIC(:,72))+ CONSTANTS(:,57).*ALGEBRAIC(:,76)) -  CONSTANTS(:,54).*ALGEBRAIC(:,76))+ CONSTANTS(:,57).*ALGEBRAIC(:,80)) -  CONSTANTS(:,54).*ALGEBRAIC(:,80))+ CONSTANTS(:,58).*ALGEBRAIC(:,108)) -  CONSTANTS(:,55).*ALGEBRAIC(:,108))+ CONSTANTS(:,56).*ALGEBRAIC(:,56)) -  CONSTANTS(:,53).*ALGEBRAIC(:,56))+ CONSTANTS(:,56).*ALGEBRAIC(:,64)) -  CONSTANTS(:,53).*ALGEBRAIC(:,64))+ CONSTANTS(:,57).*ALGEBRAIC(:,68)) -  CONSTANTS(:,54).*ALGEBRAIC(:,68))+ CONSTANTS(:,58).*ALGEBRAIC(:,87)) -  CONSTANTS(:,55).*ALGEBRAIC(:,87))+ CONSTANTS(:,58).*ALGEBRAIC(:,99)) -  CONSTANTS(:,55).*ALGEBRAIC(:,99))+ CONSTANTS(:,58).*ALGEBRAIC(:,93)) -  CONSTANTS(:,55).*ALGEBRAIC(:,93))+ CONSTANTS(:,58).*ALGEBRAIC(:,105)) -  CONSTANTS(:,55).*ALGEBRAIC(:,105))+ CONSTANTS(:,58).*ALGEBRAIC(:,120)) -  CONSTANTS(:,55).*ALGEBRAIC(:,120))+ CONSTANTS(:,56).*ALGEBRAIC(:,54)) -  CONSTANTS(:,53).*ALGEBRAIC(:,54))+ CONSTANTS(:,56).*ALGEBRAIC(:,62)) -  CONSTANTS(:,53).*ALGEBRAIC(:,62))+ CONSTANTS(:,57).*ALGEBRAIC(:,70)) -  CONSTANTS(:,54).*ALGEBRAIC(:,70))+ CONSTANTS(:,57).*ALGEBRAIC(:,74)) -  CONSTANTS(:,54).*ALGEBRAIC(:,74))+ CONSTANTS(:,57).*ALGEBRAIC(:,78)) -  CONSTANTS(:,54).*ALGEBRAIC(:,78))+ CONSTANTS(:,57).*ALGEBRAIC(:,82)) -  CONSTANTS(:,54).*ALGEBRAIC(:,82))+ CONSTANTS(:,58).*ALGEBRAIC(:,112)) -  CONSTANTS(:,55).*ALGEBRAIC(:,112))+ CONSTANTS(:,56).*ALGEBRAIC(:,58)) -  CONSTANTS(:,53).*ALGEBRAIC(:,58))+ CONSTANTS(:,56).*ALGEBRAIC(:,66)) -  CONSTANTS(:,53).*ALGEBRAIC(:,66));
    RATES(:,19) = ALGEBRAIC(:,123);
    ALGEBRAIC(:,124) = (ALGEBRAIC(:,120)+ALGEBRAIC(:,66)) - (( - ALGEBRAIC(:,82)+ALGEBRAIC(:,121)) - ALGEBRAIC(:,121));
    RATES(:,18) = ALGEBRAIC(:,124);
   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(:,1) = STATES(:,19)./CONSTANTS(:,4);
    ALGEBRAIC(:,21) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,5).*STATES(:,3))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,51) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,7).*STATES(:,4))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,52) =  CONSTANTS(:,24).*(exp(ALGEBRAIC(:,21)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,51)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,29) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,5).*STATES(:,3))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,67) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,6).*STATES(:,11))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,68) =  CONSTANTS(:,32).*(exp(ALGEBRAIC(:,29)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,67)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,37) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,5).*STATES(:,3))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,83) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,84) =  CONSTANTS(:,40).*(exp(ALGEBRAIC(:,37)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,83)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,86) = ( - ALGEBRAIC(:,84) - ALGEBRAIC(:,52)) - ALGEBRAIC(:,68);
    ALGEBRAIC(:,22) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,6).*STATES(:,11))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,53) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,8).*STATES(:,12))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,54) =  CONSTANTS(:,25).*(exp(ALGEBRAIC(:,22)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,53)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,38) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,6).*STATES(:,11))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,85) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,87) =  CONSTANTS(:,41).*(exp(ALGEBRAIC(:,38)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,85)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,89) = ( - ALGEBRAIC(:,87) - ALGEBRAIC(:,54)) -  - ALGEBRAIC(:,68);
    ALGEBRAIC(:,30) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,7).*STATES(:,4))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,69) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,8).*STATES(:,12))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,70) =  CONSTANTS(:,33).*(exp(ALGEBRAIC(:,30)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,69)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,39) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,7).*STATES(:,4))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,88) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,90) =  CONSTANTS(:,42).*(exp(ALGEBRAIC(:,39)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,88)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,92) = ( - ALGEBRAIC(:,90)+ALGEBRAIC(:,52)) - ALGEBRAIC(:,70);
    ALGEBRAIC(:,40) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,8).*STATES(:,12))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,91) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,93) =  CONSTANTS(:,43).*(exp(ALGEBRAIC(:,40)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,91)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,95) = ( - ALGEBRAIC(:,93)+ALGEBRAIC(:,54)) -  - ALGEBRAIC(:,70);
    ALGEBRAIC(:,23) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,55) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,56) =  CONSTANTS(:,26).*(exp(ALGEBRAIC(:,23)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,55)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,31) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,71) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,72) =  CONSTANTS(:,34).*(exp(ALGEBRAIC(:,31)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,71)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,41) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,94) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,96) =  CONSTANTS(:,44).*(exp(ALGEBRAIC(:,41)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,94)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,98) = ((ALGEBRAIC(:,84) - ALGEBRAIC(:,96)) - ALGEBRAIC(:,56)) - ALGEBRAIC(:,72);
    ALGEBRAIC(:,24) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,57) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,58) =  CONSTANTS(:,27).*(exp(ALGEBRAIC(:,24)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,57)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,42) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,97) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,99) =  CONSTANTS(:,45).*(exp(ALGEBRAIC(:,42)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,97)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,101) = ((ALGEBRAIC(:,87) - ALGEBRAIC(:,99)) - ALGEBRAIC(:,58)) -  - ALGEBRAIC(:,72);
    ALGEBRAIC(:,32) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,73) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,74) =  CONSTANTS(:,35).*(exp(ALGEBRAIC(:,32)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,73)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,43) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,100) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,102) =  CONSTANTS(:,46).*(exp(ALGEBRAIC(:,43)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,100)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,104) = ((ALGEBRAIC(:,90) - ALGEBRAIC(:,102))+ALGEBRAIC(:,56)) - ALGEBRAIC(:,74);
    ALGEBRAIC(:,44) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,103) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,105) =  CONSTANTS(:,47).*(exp(ALGEBRAIC(:,44)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,103)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,107) = ((ALGEBRAIC(:,93) - ALGEBRAIC(:,105))+ALGEBRAIC(:,58)) -  - ALGEBRAIC(:,74);
    ALGEBRAIC(:,25) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,59) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,60) =  CONSTANTS(:,28).*(exp(ALGEBRAIC(:,25)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,59)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,33) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,75) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,76) =  CONSTANTS(:,36).*(exp(ALGEBRAIC(:,33)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,75)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,45) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,106) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,17).*STATES(:,9))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,108) =  CONSTANTS(:,48).*(exp(ALGEBRAIC(:,45)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,106)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,110) = ((ALGEBRAIC(:,96) - ALGEBRAIC(:,108)) - ALGEBRAIC(:,60)) - ALGEBRAIC(:,76);
    ALGEBRAIC(:,27) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,17).*STATES(:,9))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,63) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,19).*STATES(:,10))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,64) =  CONSTANTS(:,30).*(exp(ALGEBRAIC(:,27)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,63)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,35) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,17).*STATES(:,9))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,79) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,18).*STATES(:,17))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,80) =  CONSTANTS(:,38).*(exp(ALGEBRAIC(:,35)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,79)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,111) = (ALGEBRAIC(:,108) - ALGEBRAIC(:,64)) - ALGEBRAIC(:,80);
    ALGEBRAIC(:,26) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,61) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,62) =  CONSTANTS(:,29).*(exp(ALGEBRAIC(:,26)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,61)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,46) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,109) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,18).*STATES(:,17))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,112) =  CONSTANTS(:,49).*(exp(ALGEBRAIC(:,46)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,109)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,114) = ((ALGEBRAIC(:,99) - ALGEBRAIC(:,112)) - ALGEBRAIC(:,62)) -  - ALGEBRAIC(:,76);
    ALGEBRAIC(:,28) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,18).*STATES(:,17))+ CONSTANTS(:,53).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,65) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18))+ CONSTANTS(:,56).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,66) =  CONSTANTS(:,31).*(exp(ALGEBRAIC(:,28)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,65)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,115) = (ALGEBRAIC(:,112) - ALGEBRAIC(:,66)) -  - ALGEBRAIC(:,80);
    ALGEBRAIC(:,34) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,77) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,78) =  CONSTANTS(:,37).*(exp(ALGEBRAIC(:,34)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,77)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,47) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,113) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,19).*STATES(:,10))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,116) =  CONSTANTS(:,50).*(exp(ALGEBRAIC(:,47)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,113)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,118) = ((ALGEBRAIC(:,102) - ALGEBRAIC(:,116))+ALGEBRAIC(:,60)) - ALGEBRAIC(:,78);
    ALGEBRAIC(:,36) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,19).*STATES(:,10))+ CONSTANTS(:,54).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,81) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18))+ CONSTANTS(:,57).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,82) =  CONSTANTS(:,39).*(exp(ALGEBRAIC(:,36)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,81)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,119) = (ALGEBRAIC(:,116)+ALGEBRAIC(:,64)) - ALGEBRAIC(:,82);
    ALGEBRAIC(:,49) =  CONSTANTS(:,52).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,18) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,22).*STATES(:,2));
    ALGEBRAIC(:,19) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18));
    ALGEBRAIC(:,20) = ALGEBRAIC(:,18)+ CONSTANTS(:,52).*CONSTANTS(:,3).*ALGEBRAIC(:,1)+ALGEBRAIC(:,19);
    ALGEBRAIC(:,17) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,21).*STATES(:,1));
    ALGEBRAIC(:,50) = ALGEBRAIC(:,17)+ALGEBRAIC(:,19);
    ALGEBRAIC(:,121) = piecewise({ALGEBRAIC(:,49)==0.00000,  CONSTANTS(:,23).*(exp(ALGEBRAIC(:,20)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,50)./( CONSTANTS(:,1).*CONSTANTS(:,2)))) },  ((( CONSTANTS(:,23).*ALGEBRAIC(:,49))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(exp(ALGEBRAIC(:,49)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000)).*(exp(ALGEBRAIC(:,20)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,50)./( CONSTANTS(:,1).*CONSTANTS(:,2)))));
    ALGEBRAIC(:,48) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16))+ CONSTANTS(:,55).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,117) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,20).*STATES(:,18))+ CONSTANTS(:,58).*CONSTANTS(:,3).*ALGEBRAIC(:,1);
    ALGEBRAIC(:,120) =  CONSTANTS(:,51).*(exp(ALGEBRAIC(:,48)./( CONSTANTS(:,1).*CONSTANTS(:,2))) - exp(ALGEBRAIC(:,117)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
    ALGEBRAIC(:,122) = ((ALGEBRAIC(:,105) - ALGEBRAIC(:,120))+ALGEBRAIC(:,62)) -  - ALGEBRAIC(:,78);
    ALGEBRAIC(:,123) =  CONSTANTS(:,3).*((((((((((((((((((((((((((((((((((((((((((((((((((((((((  - CONSTANTS(:,52).*ALGEBRAIC(:,121)+ CONSTANTS(:,58).*ALGEBRAIC(:,84)) -  CONSTANTS(:,55).*ALGEBRAIC(:,84))+ CONSTANTS(:,58).*ALGEBRAIC(:,96)) -  CONSTANTS(:,55).*ALGEBRAIC(:,96))+ CONSTANTS(:,58).*ALGEBRAIC(:,90)) -  CONSTANTS(:,55).*ALGEBRAIC(:,90))+ CONSTANTS(:,58).*ALGEBRAIC(:,102)) -  CONSTANTS(:,55).*ALGEBRAIC(:,102))+ CONSTANTS(:,58).*ALGEBRAIC(:,116)) -  CONSTANTS(:,55).*ALGEBRAIC(:,116))+ CONSTANTS(:,56).*ALGEBRAIC(:,52)) -  CONSTANTS(:,53).*ALGEBRAIC(:,52))+ CONSTANTS(:,56).*ALGEBRAIC(:,60)) -  CONSTANTS(:,53).*ALGEBRAIC(:,60))+ CONSTANTS(:,57).*ALGEBRAIC(:,72)) -  CONSTANTS(:,54).*ALGEBRAIC(:,72))+ CONSTANTS(:,57).*ALGEBRAIC(:,76)) -  CONSTANTS(:,54).*ALGEBRAIC(:,76))+ CONSTANTS(:,57).*ALGEBRAIC(:,80)) -  CONSTANTS(:,54).*ALGEBRAIC(:,80))+ CONSTANTS(:,58).*ALGEBRAIC(:,108)) -  CONSTANTS(:,55).*ALGEBRAIC(:,108))+ CONSTANTS(:,56).*ALGEBRAIC(:,56)) -  CONSTANTS(:,53).*ALGEBRAIC(:,56))+ CONSTANTS(:,56).*ALGEBRAIC(:,64)) -  CONSTANTS(:,53).*ALGEBRAIC(:,64))+ CONSTANTS(:,57).*ALGEBRAIC(:,68)) -  CONSTANTS(:,54).*ALGEBRAIC(:,68))+ CONSTANTS(:,58).*ALGEBRAIC(:,87)) -  CONSTANTS(:,55).*ALGEBRAIC(:,87))+ CONSTANTS(:,58).*ALGEBRAIC(:,99)) -  CONSTANTS(:,55).*ALGEBRAIC(:,99))+ CONSTANTS(:,58).*ALGEBRAIC(:,93)) -  CONSTANTS(:,55).*ALGEBRAIC(:,93))+ CONSTANTS(:,58).*ALGEBRAIC(:,105)) -  CONSTANTS(:,55).*ALGEBRAIC(:,105))+ CONSTANTS(:,58).*ALGEBRAIC(:,120)) -  CONSTANTS(:,55).*ALGEBRAIC(:,120))+ CONSTANTS(:,56).*ALGEBRAIC(:,54)) -  CONSTANTS(:,53).*ALGEBRAIC(:,54))+ CONSTANTS(:,56).*ALGEBRAIC(:,62)) -  CONSTANTS(:,53).*ALGEBRAIC(:,62))+ CONSTANTS(:,57).*ALGEBRAIC(:,70)) -  CONSTANTS(:,54).*ALGEBRAIC(:,70))+ CONSTANTS(:,57).*ALGEBRAIC(:,74)) -  CONSTANTS(:,54).*ALGEBRAIC(:,74))+ CONSTANTS(:,57).*ALGEBRAIC(:,78)) -  CONSTANTS(:,54).*ALGEBRAIC(:,78))+ CONSTANTS(:,57).*ALGEBRAIC(:,82)) -  CONSTANTS(:,54).*ALGEBRAIC(:,82))+ CONSTANTS(:,58).*ALGEBRAIC(:,112)) -  CONSTANTS(:,55).*ALGEBRAIC(:,112))+ CONSTANTS(:,56).*ALGEBRAIC(:,58)) -  CONSTANTS(:,53).*ALGEBRAIC(:,58))+ CONSTANTS(:,56).*ALGEBRAIC(:,66)) -  CONSTANTS(:,53).*ALGEBRAIC(:,66));
    ALGEBRAIC(:,124) = (ALGEBRAIC(:,120)+ALGEBRAIC(:,66)) - (( - ALGEBRAIC(:,82)+ALGEBRAIC(:,121)) - ALGEBRAIC(:,121));
    ALGEBRAIC(:,2) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,5).*STATES(:,3));
    ALGEBRAIC(:,3) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,7).*STATES(:,4));
    ALGEBRAIC(:,4) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,9).*STATES(:,5));
    ALGEBRAIC(:,5) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,11).*STATES(:,6));
    ALGEBRAIC(:,6) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,13).*STATES(:,7));
    ALGEBRAIC(:,7) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,15).*STATES(:,8));
    ALGEBRAIC(:,8) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,17).*STATES(:,9));
    ALGEBRAIC(:,9) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,19).*STATES(:,10));
    ALGEBRAIC(:,10) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,6).*STATES(:,11));
    ALGEBRAIC(:,11) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,8).*STATES(:,12));
    ALGEBRAIC(:,12) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,10).*STATES(:,13));
    ALGEBRAIC(:,13) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,12).*STATES(:,14));
    ALGEBRAIC(:,14) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,14).*STATES(:,15));
    ALGEBRAIC(:,15) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,16).*STATES(:,16));
    ALGEBRAIC(:,16) =  CONSTANTS(:,1).*CONSTANTS(:,2).*log( CONSTANTS(:,18).*STATES(:,17));
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