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 =44;
end
% There are a total of 11 entries in each of the rate and state variable arrays.
% There are a total of 72 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_ALGEBRAIC(:,4) = strpad('SOVFThick in component sarcomere_geometry (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('SOVFThin in component sarcomere_geometry (dimensionless)');
    LEGEND_ALGEBRAIC(:,1) = strpad('sovr_ze in component sarcomere_geometry (micrometre)');
    LEGEND_ALGEBRAIC(:,2) = strpad('sovr_cle in component sarcomere_geometry (micrometre)');
    LEGEND_ALGEBRAIC(:,3) = strpad('len_sovr in component sarcomere_geometry (micrometre)');
    LEGEND_CONSTANTS(:,1) = strpad('len_thin in component model_parameters (micrometre)');
    LEGEND_CONSTANTS(:,2) = strpad('len_thick in component model_parameters (micrometre)');
    LEGEND_CONSTANTS(:,3) = strpad('len_hbare in component model_parameters (micrometre)');
    LEGEND_STATES(:,1) = strpad('SL in component normalised_active_and_passive_force (micrometre)');
    LEGEND_STATES(:,2) = strpad('TRPNCaL in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_STATES(:,3) = strpad('TRPNCaH in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,8) = strpad('dTRPNCaL in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,11) = strpad('dTRPNCaH in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,13) = strpad('kn_pT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,19) = strpad('kp_nT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,59) = strpad('H in component Ca_binding_to_troponin_to_thin_filament_regulation (micromolar)');
    LEGEND_CONSTANTS(:,62) = strpad('H_cons in component Ca_binding_to_troponin_to_thin_filament_regulation (micromolar)');
    LEGEND_CONSTANTS(:,63) = strpad('konT in component Ca_binding_to_troponin_to_thin_filament_regulation (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,57) = strpad('koffLT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,58) = strpad('koffHT in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,4) = strpad('Qkon in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,5) = strpad('Qkoff in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,6) = strpad('Qkn_p in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,7) = strpad('Qkp_n in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,8) = strpad('kon in component Ca_binding_to_troponin_to_thin_filament_regulation (second_order_rate_constant)');
    LEGEND_CONSTANTS(:,9) = strpad('koffL in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,10) = strpad('koffH in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,11) = strpad('perm50 in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,12) = strpad('nperm in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,13) = strpad('kn_p in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,14) = strpad('kp_n in component Ca_binding_to_troponin_to_thin_filament_regulation (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,15) = strpad('koffmod in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,7) = strpad('Tropreg in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('permtot in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('inprmt in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,16) = strpad('pH in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,17) = strpad('m in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_CONSTANTS(:,18) = strpad('kdHCa in component Ca_binding_to_troponin_to_thin_filament_regulation (micromolar)');
    LEGEND_CONSTANTS(:,19) = strpad('TmpC in component model_parameters (kelvin)');
    LEGEND_CONSTANTS(:,20) = strpad('Cai in component model_parameters (micromolar)');
    LEGEND_CONSTANTS(:,64) = strpad('fappT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,17) = strpad('gappT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,21) = strpad('hfT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,66) = strpad('hbT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,24) = strpad('gxbT in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,21) = strpad('fapp in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,22) = strpad('gapp in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,23) = strpad('hf in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,24) = strpad('hb in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,25) = strpad('gxb in component thin_filament_regulation_and_crossbridge_cycling_rates (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,26) = strpad('gslmod in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('hfmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,65) = strpad('hbmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,27) = strpad('hfmdc in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,28) = strpad('hbmdc in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,29) = strpad('sigmap in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,30) = strpad('sigman in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,31) = strpad('xbmodsp in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,32) = strpad('Qfapp in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,33) = strpad('Qgapp in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,34) = strpad('Qhf in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,35) = strpad('Qhb in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,36) = strpad('Qgxb in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_ALGEBRAIC(:,23) = strpad('gxbmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('gapslmd in component thin_filament_regulation_and_crossbridge_cycling_rates (dimensionless)');
    LEGEND_CONSTANTS(:,37) = strpad('x_0 in component model_parameters (micrometre)');
    LEGEND_STATES(:,4) = strpad('xXBpostr in component mean_strain_of_strongly_bound_states (micrometre)');
    LEGEND_STATES(:,5) = strpad('xXBprer in component mean_strain_of_strongly_bound_states (micrometre)');
    LEGEND_STATES(:,6) = strpad('XBpostr in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_STATES(:,7) = strpad('XBprer in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_ALGEBRAIC(:,33) = strpad('dXBpostr in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,28) = strpad('dXBprer in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,67) = strpad('alpha1_plus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,25) = strpad('alpha2_plus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,26) = strpad('alpha3_plus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,27) = strpad('alpha1_minus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,69) = strpad('alpha2_minus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,30) = strpad('alpha3_minus in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,38) = strpad('kMgATP in component regulation_and_crossbridge_cycling_state_equations (micromolar2)');
    LEGEND_CONSTANTS(:,39) = strpad('kdADP in component regulation_and_crossbridge_cycling_state_equations (micromolar)');
    LEGEND_CONSTANTS(:,40) = strpad('xPi_cons in component regulation_and_crossbridge_cycling_state_equations (micromolar)');
    LEGEND_CONSTANTS(:,41) = strpad('MgATP_cons in component regulation_and_crossbridge_cycling_state_equations (micromolar)');
    LEGEND_ALGEBRAIC(:,29) = strpad('fxbT in component regulation_and_crossbridge_cycling_state_equations (first_order_rate_constant)');
    LEGEND_STATES(:,8) = strpad('N_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_STATES(:,9) = strpad('P_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_STATES(:,10) = strpad('P in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_ALGEBRAIC(:,22) = strpad('N in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_CONSTANTS(:,42) = strpad('MgADP_cons in component regulation_and_crossbridge_cycling_state_equations (micromolar)');
    LEGEND_CONSTANTS(:,43) = strpad('xPi in component regulation_and_crossbridge_cycling_state_equations (micromolar)');
    LEGEND_CONSTANTS(:,44) = strpad('MgATP in component regulation_and_crossbridge_cycling_state_equations (micromolar)');
    LEGEND_CONSTANTS(:,45) = strpad('MgADP in component regulation_and_crossbridge_cycling_state_equations (micromolar)');
    LEGEND_ALGEBRAIC(:,34) = strpad('dxXBpostr in component mean_strain_of_strongly_bound_states (micrometre_per_millisecond)');
    LEGEND_ALGEBRAIC(:,35) = strpad('dxXBprer in component mean_strain_of_strongly_bound_states (micrometre_per_millisecond)');
    LEGEND_CONSTANTS(:,46) = strpad('xPsi in component mean_strain_of_strongly_bound_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,32) = strpad('dutyprer in component mean_strain_of_strongly_bound_states (dimensionless)');
    LEGEND_ALGEBRAIC(:,31) = strpad('dutypostr in component mean_strain_of_strongly_bound_states (dimensionless)');
    LEGEND_CONSTANTS(:,60) = strpad('dSL in component normalised_active_and_passive_force (micrometre_per_millisecond)');
    LEGEND_CONSTANTS(:,71) = strpad('SSXBpostr in component normalised_active_and_passive_force (dimensionless)');
    LEGEND_CONSTANTS(:,70) = strpad('SSXBprer in component normalised_active_and_passive_force (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('ppforce in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_ALGEBRAIC(:,9) = strpad('ppforce_t in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_ALGEBRAIC(:,12) = strpad('ppforce_c in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_CONSTANTS(:,61) = strpad('preload in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_ALGEBRAIC(:,18) = strpad('afterload in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_STATES(:,11) = strpad('intf in component normalised_active_and_passive_force (unit_normalised_force_millisecond)');
    LEGEND_CONSTANTS(:,47) = strpad('SL_c in component normalised_active_and_passive_force (micrometre)');
    LEGEND_CONSTANTS(:,48) = strpad('SLrest in component normalised_active_and_passive_force (micrometre)');
    LEGEND_CONSTANTS(:,49) = strpad('SLset in component normalised_active_and_passive_force (micrometre)');
    LEGEND_CONSTANTS(:,50) = strpad('PCon_t in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_CONSTANTS(:,51) = strpad('PExp_t in component normalised_active_and_passive_force (per_micrometre)');
    LEGEND_CONSTANTS(:,52) = strpad('PCon_c in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_CONSTANTS(:,53) = strpad('PExp_c in component normalised_active_and_passive_force (per_micrometre)');
    LEGEND_CONSTANTS(:,54) = strpad('KSE in component normalised_active_and_passive_force (unit_normalised_force_per_micrometre)');
    LEGEND_CONSTANTS(:,68) = strpad('fxb in component normalised_active_and_passive_force (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,55) = strpad('SEon in component normalised_active_and_passive_force (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('F_active in component normalised_active_and_passive_force (unit_normalised_force)');
    LEGEND_ALGEBRAIC(:,36) = strpad('FrSBXB in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (dimensionless)');
    LEGEND_ALGEBRAIC(:,37) = strpad('dFrSBXB in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,39) = strpad('dsovr_ze in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micrometre_per_millisecond)');
    LEGEND_ALGEBRAIC(:,40) = strpad('dsovr_cle in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micrometre_per_millisecond)');
    LEGEND_ALGEBRAIC(:,41) = strpad('dlen_sovr in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micrometre_per_millisecond)');
    LEGEND_ALGEBRAIC(:,42) = strpad('dSOVFThick in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,43) = strpad('dSOVFThin in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,56) = strpad('Trop_conc in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micromolar)');
    LEGEND_ALGEBRAIC(:,38) = strpad('TropTot in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micromolar)');
    LEGEND_ALGEBRAIC(:,44) = strpad('dTropTot in component calculation_of_micromolar_per_millisecondes_of_Ca_for_apparent_Ca_binding (micromolar_per_millisecond)');
    LEGEND_RATES(:,2) = strpad('d/dt TRPNCaL in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt TRPNCaH in component Ca_binding_to_troponin_to_thin_filament_regulation (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt N_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt P_NoXB in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt P in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt XBprer in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt XBpostr in component regulation_and_crossbridge_cycling_state_equations (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt xXBprer in component mean_strain_of_strongly_bound_states (micrometre)');
    LEGEND_RATES(:,4) = strpad('d/dt xXBpostr in component mean_strain_of_strongly_bound_states (micrometre)');
    LEGEND_RATES(:,1) = strpad('d/dt SL in component normalised_active_and_passive_force (micrometre)');
    LEGEND_RATES(:,11) = strpad('d/dt intf in component normalised_active_and_passive_force (unit_normalised_force_millisecond)');
    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) = 1.2;
    CONSTANTS(:,2) = 1.65;
    CONSTANTS(:,3) = 0.1;
    STATES(:,1) = 2.2;
    STATES(:,2) = 0.0147730085063734;
    STATES(:,3) = 0.13066096561522;
    CONSTANTS(:,4) = 1.5;
    CONSTANTS(:,5) = 1.3;
    CONSTANTS(:,6) = 1.6;
    CONSTANTS(:,7) = 1.6;
    CONSTANTS(:,8) = 0.05;
    CONSTANTS(:,9) = 0.25;
    CONSTANTS(:,10) = 0.025;
    CONSTANTS(:,11) = 0.5;
    CONSTANTS(:,12) = 15;
    CONSTANTS(:,13) = 0.5;
    CONSTANTS(:,14) = 0.05;
    CONSTANTS(:,15) = 1;
    CONSTANTS(:,16) = 7.15;
    CONSTANTS(:,17) = 1;
    CONSTANTS(:,18) = 2e-2;
    CONSTANTS(:,19) = 299;
    CONSTANTS(:,20) = 200.0;
    CONSTANTS(:,21) = 0.5;
    CONSTANTS(:,22) = 0.07;
    CONSTANTS(:,23) = 2;
    CONSTANTS(:,24) = 0.4;
    CONSTANTS(:,25) = 0.07;
    CONSTANTS(:,26) = 6;
    CONSTANTS(:,27) = 5;
    CONSTANTS(:,28) = 0;
    CONSTANTS(:,29) = 8;
    CONSTANTS(:,30) = 1;
    CONSTANTS(:,31) = 0.2;
    CONSTANTS(:,32) = 6.25;
    CONSTANTS(:,33) = 2.5;
    CONSTANTS(:,34) = 6.25;
    CONSTANTS(:,35) = 6.25;
    CONSTANTS(:,36) = 6.25;
    CONSTANTS(:,37) = 0.007;
    STATES(:,4) = 0.00700005394873882;
    STATES(:,5) = 3.41212828972468e-8;
    STATES(:,6) = 1.81017564383744e-6;
    STATES(:,7) = 3.0494964880038e-7;
    CONSTANTS(:,38) = 15400e6;
    CONSTANTS(:,39) = 4;
    CONSTANTS(:,40) = 2e3;
    CONSTANTS(:,41) = 5e3;
    STATES(:,8) = 0.999999959256274;
    STATES(:,9) = 4.07437173988636e-8;
    STATES(:,10) = 0.999997834540066;
    CONSTANTS(:,42) = 36;
    CONSTANTS(:,43) = 2e3;
    CONSTANTS(:,44) = 5e3;
    CONSTANTS(:,45) = 36.3;
    CONSTANTS(:,46) = 2;
    STATES(:,11) = -4.5113452510363e-6;
    CONSTANTS(:,47) = 2.25;
    CONSTANTS(:,48) = 1.85;
    CONSTANTS(:,49) = 1.9;
    CONSTANTS(:,50) = 0.002;
    CONSTANTS(:,51) = 10;
    CONSTANTS(:,52) = 0.02;
    CONSTANTS(:,53) = 70;
    CONSTANTS(:,54) = 1;
    CONSTANTS(:,55) = 1;
    CONSTANTS(:,56) = 70;
    CONSTANTS(:,57) =  CONSTANTS(:,9).*CONSTANTS(:,15).*power(CONSTANTS(:,5), (CONSTANTS(:,19) - 310.000)./10.0000);
    CONSTANTS(:,58) =  CONSTANTS(:,10).*CONSTANTS(:,15).*power(CONSTANTS(:,5), (CONSTANTS(:,19) - 310.000)./10.0000);
    CONSTANTS(:,59) =  1.00000e+07.*power(10.0000,  - CONSTANTS(:,16));
    CONSTANTS(:,60) = 0.00000;
    CONSTANTS(:,61) =  (abs(CONSTANTS(:,49) - CONSTANTS(:,48))./(CONSTANTS(:,49) - CONSTANTS(:,48))).*CONSTANTS(:,50).*(exp( CONSTANTS(:,51).*abs(CONSTANTS(:,49) - CONSTANTS(:,48))) - 1.00000);
    CONSTANTS(:,62) =  1.00000e+07.*power(10.0000,  - 7.15000);
    CONSTANTS(:,71) = CONSTANTS(:,60);
    CONSTANTS(:,63) =  ((power(CONSTANTS(:,18), CONSTANTS(:,17))+power(CONSTANTS(:,62), CONSTANTS(:,17)))./(power(CONSTANTS(:,18), CONSTANTS(:,17))+power(CONSTANTS(:,59), CONSTANTS(:,17)))).*CONSTANTS(:,8).*power(CONSTANTS(:,4), (CONSTANTS(:,19) - 310.000)./10.0000);
    CONSTANTS(:,64) =  CONSTANTS(:,21).*CONSTANTS(:,31).*power(CONSTANTS(:,32), (CONSTANTS(:,19) - 310.000)./10.0000);
    CONSTANTS(:,65) = 1.00000;
    CONSTANTS(:,66) =  CONSTANTS(:,24).*CONSTANTS(:,65).*CONSTANTS(:,31).*power(CONSTANTS(:,35), (CONSTANTS(:,19) - 310.000)./10.0000);
    CONSTANTS(:,67) = CONSTANTS(:,64);
    CONSTANTS(:,68) = (( CONSTANTS(:,39).*CONSTANTS(:,21).*CONSTANTS(:,23).*CONSTANTS(:,25))./CONSTANTS(:,41))./( (( (CONSTANTS(:,22)./CONSTANTS(:,40)).*CONSTANTS(:,24))./CONSTANTS(:,62)).*CONSTANTS(:,38));
    CONSTANTS(:,69) = ( (( (( CONSTANTS(:,59).*CONSTANTS(:,66))./CONSTANTS(:,62)).*(CONSTANTS(:,39)+CONSTANTS(:,42)))./CONSTANTS(:,42)).*CONSTANTS(:,45))./(CONSTANTS(:,39)+CONSTANTS(:,45));
    CONSTANTS(:,70) = ( CONSTANTS(:,68).*CONSTANTS(:,24)+ CONSTANTS(:,25).*CONSTANTS(:,21)+ CONSTANTS(:,66).*CONSTANTS(:,21))./( CONSTANTS(:,23).*CONSTANTS(:,25)+ CONSTANTS(:,24).*CONSTANTS(:,22)+ CONSTANTS(:,25).*CONSTANTS(:,22)+ CONSTANTS(:,68).*CONSTANTS(:,24)+ CONSTANTS(:,25).*CONSTANTS(:,21)+ CONSTANTS(:,24).*CONSTANTS(:,21)+ CONSTANTS(:,68).*CONSTANTS(:,22)+ CONSTANTS(:,21).*CONSTANTS(:,23)+ CONSTANTS(:,68).*CONSTANTS(:,24));
    CONSTANTS(:,71) = ( CONSTANTS(:,21).*CONSTANTS(:,23)+ CONSTANTS(:,68).*CONSTANTS(:,22)+ CONSTANTS(:,68).*CONSTANTS(:,24))./( CONSTANTS(:,23).*CONSTANTS(:,25)+ CONSTANTS(:,24).*CONSTANTS(:,22)+ CONSTANTS(:,25).*CONSTANTS(:,22)+ CONSTANTS(:,68).*CONSTANTS(:,24)+ CONSTANTS(:,25).*CONSTANTS(:,21)+ CONSTANTS(:,24).*CONSTANTS(:,21)+ CONSTANTS(:,68).*CONSTANTS(:,22)+ CONSTANTS(:,21).*CONSTANTS(:,23)+ CONSTANTS(:,68).*CONSTANTS(:,24));
    if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
    global algebraicVariableCount;
    statesSize = size(STATES);
    statesColumnCount = statesSize(2);
    if ( statesColumnCount == 1)
        STATES = STATES';
        ALGEBRAIC = zeros(1, algebraicVariableCount);
        utilOnes = 1;
    else
        statesRowCount = statesSize(1);
        ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
        RATES = zeros(statesRowCount, statesColumnCount);
        utilOnes = ones(statesRowCount, 1);
    end
    RATES(:,1) = CONSTANTS(:,71);
    ALGEBRAIC(:,8) =  CONSTANTS(:,63).*CONSTANTS(:,20).*(1.00000 - STATES(:,2)) -  CONSTANTS(:,57).*STATES(:,2);
    RATES(:,2) = ALGEBRAIC(:,8);
    ALGEBRAIC(:,11) =  CONSTANTS(:,63).*CONSTANTS(:,20).*(1.00000 - STATES(:,3)) -  CONSTANTS(:,58).*STATES(:,3);
    RATES(:,3) = ALGEBRAIC(:,11);
    ALGEBRAIC(:,9) =  ((STATES(:,1) - CONSTANTS(:,48))./abs(STATES(:,1) - CONSTANTS(:,48))).*CONSTANTS(:,50).*(exp( CONSTANTS(:,51).*abs(STATES(:,1) - CONSTANTS(:,48))) - 1.00000);
    ALGEBRAIC(:,12) = piecewise({STATES(:,1)>CONSTANTS(:,47),  CONSTANTS(:,52).*(exp( CONSTANTS(:,53).*abs(STATES(:,1) - CONSTANTS(:,47))) - 1.00000) }, 0.00000);
    ALGEBRAIC(:,15) = ALGEBRAIC(:,9)+ALGEBRAIC(:,12);
    ALGEBRAIC(:,18) = piecewise({CONSTANTS(:,55)==1.00000,  CONSTANTS(:,54).*(CONSTANTS(:,49) - STATES(:,1)) }, 0.00000);
    ALGEBRAIC(:,1) = piecewise({CONSTANTS(:,2)./2.00000<STATES(:,1)./2.00000, CONSTANTS(:,2)./2.00000 }, STATES(:,1)./2.00000);
    ALGEBRAIC(:,2) = piecewise({STATES(:,1)./2.00000 - (STATES(:,1) - CONSTANTS(:,1))>CONSTANTS(:,3)./2.00000, STATES(:,1)./2.00000 - (STATES(:,1) - CONSTANTS(:,1)) }, CONSTANTS(:,3)./2.00000);
    ALGEBRAIC(:,3) = ALGEBRAIC(:,1) - ALGEBRAIC(:,2);
    ALGEBRAIC(:,4) = ( ALGEBRAIC(:,3).*2.00000)./(CONSTANTS(:,2) - CONSTANTS(:,3));
    ALGEBRAIC(:,6) = ( ALGEBRAIC(:,4).*( STATES(:,4).*STATES(:,6)+ STATES(:,5).*STATES(:,7)))./( CONSTANTS(:,37).*CONSTANTS(:,71));
    RATES(:,11) = (CONSTANTS(:,61)+ALGEBRAIC(:,18)) - (ALGEBRAIC(:,15)+ALGEBRAIC(:,6));
    ALGEBRAIC(:,5) = ALGEBRAIC(:,3)./CONSTANTS(:,1);
    ALGEBRAIC(:,7) =  (1.00000 - ALGEBRAIC(:,5)).*STATES(:,2)+ ALGEBRAIC(:,5).*STATES(:,3);
    ALGEBRAIC(:,10) = power(abs(1.00000./(1.00000+power(CONSTANTS(:,11)./ALGEBRAIC(:,7), CONSTANTS(:,12)))), 1.0 ./ 2);
    ALGEBRAIC(:,13) =  CONSTANTS(:,13).*ALGEBRAIC(:,10).*power(CONSTANTS(:,6), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,16) = piecewise({1.00000./ALGEBRAIC(:,10)<100.000, 1.00000./ALGEBRAIC(:,10) }, 100.000);
    ALGEBRAIC(:,19) =  CONSTANTS(:,14).*ALGEBRAIC(:,16).*power(CONSTANTS(:,7), (CONSTANTS(:,19) - 310.000)./10.0000);
    RATES(:,8) =  ALGEBRAIC(:,19).*STATES(:,9) -  ALGEBRAIC(:,13).*STATES(:,8);
    RATES(:,9) =  ALGEBRAIC(:,13).*STATES(:,8) -  ALGEBRAIC(:,19).*STATES(:,9);
    ALGEBRAIC(:,22) = 1.00000 - (STATES(:,10)+STATES(:,7)+STATES(:,6));
    RATES(:,10) =  ALGEBRAIC(:,13).*ALGEBRAIC(:,22) -  (ALGEBRAIC(:,19)+CONSTANTS(:,67)).*STATES(:,10);
    ALGEBRAIC(:,20) = exp( ( - STATES(:,5)./abs(STATES(:,5))).*CONSTANTS(:,27).*power(STATES(:,5)./CONSTANTS(:,37), 2.00000));
    ALGEBRAIC(:,21) =  CONSTANTS(:,23).*ALGEBRAIC(:,20).*CONSTANTS(:,31).*power(CONSTANTS(:,34), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,25) = ALGEBRAIC(:,21);
    ALGEBRAIC(:,14) = 1.00000+ (1.00000 - ALGEBRAIC(:,4)).*CONSTANTS(:,26);
    ALGEBRAIC(:,17) =  CONSTANTS(:,22).*ALGEBRAIC(:,14).*CONSTANTS(:,31).*power(CONSTANTS(:,33), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,27) = ( CONSTANTS(:,43).*ALGEBRAIC(:,17))./CONSTANTS(:,40);
    ALGEBRAIC(:,28) = ( CONSTANTS(:,67).*STATES(:,10)+ CONSTANTS(:,69).*STATES(:,6)) -  (ALGEBRAIC(:,27)+ALGEBRAIC(:,25)).*STATES(:,7);
    RATES(:,7) = ALGEBRAIC(:,28);
    ALGEBRAIC(:,23) = piecewise({STATES(:,4)<CONSTANTS(:,37), exp( CONSTANTS(:,29).*power((CONSTANTS(:,37) - STATES(:,4))./CONSTANTS(:,37), 2.00000)) }, exp( CONSTANTS(:,30).*power((STATES(:,4) - CONSTANTS(:,37))./CONSTANTS(:,37), 2.00000)));
    ALGEBRAIC(:,24) =  CONSTANTS(:,25).*ALGEBRAIC(:,23).*CONSTANTS(:,31).*power(CONSTANTS(:,36), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,26) = ( (( CONSTANTS(:,44).*ALGEBRAIC(:,24))./CONSTANTS(:,41)).*(CONSTANTS(:,39)+CONSTANTS(:,42)))./(CONSTANTS(:,39)+CONSTANTS(:,45));
    ALGEBRAIC(:,29) = (( CONSTANTS(:,39).*CONSTANTS(:,64).*ALGEBRAIC(:,21).*ALGEBRAIC(:,24))./CONSTANTS(:,41))./( (( (ALGEBRAIC(:,17)./CONSTANTS(:,40)).*CONSTANTS(:,66))./CONSTANTS(:,62)).*CONSTANTS(:,38));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,29);
    ALGEBRAIC(:,33) = ( ALGEBRAIC(:,30).*STATES(:,10)+ ALGEBRAIC(:,25).*STATES(:,7)) -  (CONSTANTS(:,69)+ALGEBRAIC(:,26)).*STATES(:,6);
    RATES(:,6) = ALGEBRAIC(:,33);
    ALGEBRAIC(:,32) = ( ALGEBRAIC(:,30).*CONSTANTS(:,69)+ ALGEBRAIC(:,26).*CONSTANTS(:,67)+ CONSTANTS(:,69).*CONSTANTS(:,67))./( CONSTANTS(:,67).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*CONSTANTS(:,69)+ ALGEBRAIC(:,26).*CONSTANTS(:,67)+ CONSTANTS(:,69).*CONSTANTS(:,67)+ ALGEBRAIC(:,25).*ALGEBRAIC(:,26)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,26).*ALGEBRAIC(:,27));
    ALGEBRAIC(:,35) = CONSTANTS(:,60)./2.00000+ (CONSTANTS(:,46)./ALGEBRAIC(:,32)).*(  - CONSTANTS(:,67).*STATES(:,5)+ CONSTANTS(:,69).*(STATES(:,4) - (CONSTANTS(:,37)+STATES(:,5))));
    RATES(:,5) = ALGEBRAIC(:,35);
    ALGEBRAIC(:,31) = ( CONSTANTS(:,67).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,25))./( CONSTANTS(:,67).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*CONSTANTS(:,69)+ ALGEBRAIC(:,26).*CONSTANTS(:,67)+ CONSTANTS(:,69).*CONSTANTS(:,67)+ ALGEBRAIC(:,25).*ALGEBRAIC(:,26)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,26).*ALGEBRAIC(:,27));
    ALGEBRAIC(:,34) = CONSTANTS(:,60)./2.00000+ (CONSTANTS(:,46)./ALGEBRAIC(:,31)).*ALGEBRAIC(:,25).*((STATES(:,5)+CONSTANTS(:,37)) - STATES(:,4));
    RATES(:,4) = ALGEBRAIC(:,34);
   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(:,8) =  CONSTANTS(:,63).*CONSTANTS(:,20).*(1.00000 - STATES(:,2)) -  CONSTANTS(:,57).*STATES(:,2);
    ALGEBRAIC(:,11) =  CONSTANTS(:,63).*CONSTANTS(:,20).*(1.00000 - STATES(:,3)) -  CONSTANTS(:,58).*STATES(:,3);
    ALGEBRAIC(:,9) =  ((STATES(:,1) - CONSTANTS(:,48))./abs(STATES(:,1) - CONSTANTS(:,48))).*CONSTANTS(:,50).*(exp( CONSTANTS(:,51).*abs(STATES(:,1) - CONSTANTS(:,48))) - 1.00000);
    ALGEBRAIC(:,12) = piecewise({STATES(:,1)>CONSTANTS(:,47),  CONSTANTS(:,52).*(exp( CONSTANTS(:,53).*abs(STATES(:,1) - CONSTANTS(:,47))) - 1.00000) }, 0.00000);
    ALGEBRAIC(:,15) = ALGEBRAIC(:,9)+ALGEBRAIC(:,12);
    ALGEBRAIC(:,18) = piecewise({CONSTANTS(:,55)==1.00000,  CONSTANTS(:,54).*(CONSTANTS(:,49) - STATES(:,1)) }, 0.00000);
    ALGEBRAIC(:,1) = piecewise({CONSTANTS(:,2)./2.00000<STATES(:,1)./2.00000, CONSTANTS(:,2)./2.00000 }, STATES(:,1)./2.00000);
    ALGEBRAIC(:,2) = piecewise({STATES(:,1)./2.00000 - (STATES(:,1) - CONSTANTS(:,1))>CONSTANTS(:,3)./2.00000, STATES(:,1)./2.00000 - (STATES(:,1) - CONSTANTS(:,1)) }, CONSTANTS(:,3)./2.00000);
    ALGEBRAIC(:,3) = ALGEBRAIC(:,1) - ALGEBRAIC(:,2);
    ALGEBRAIC(:,4) = ( ALGEBRAIC(:,3).*2.00000)./(CONSTANTS(:,2) - CONSTANTS(:,3));
    ALGEBRAIC(:,6) = ( ALGEBRAIC(:,4).*( STATES(:,4).*STATES(:,6)+ STATES(:,5).*STATES(:,7)))./( CONSTANTS(:,37).*CONSTANTS(:,71));
    ALGEBRAIC(:,5) = ALGEBRAIC(:,3)./CONSTANTS(:,1);
    ALGEBRAIC(:,7) =  (1.00000 - ALGEBRAIC(:,5)).*STATES(:,2)+ ALGEBRAIC(:,5).*STATES(:,3);
    ALGEBRAIC(:,10) = power(abs(1.00000./(1.00000+power(CONSTANTS(:,11)./ALGEBRAIC(:,7), CONSTANTS(:,12)))), 1.0 ./ 2);
    ALGEBRAIC(:,13) =  CONSTANTS(:,13).*ALGEBRAIC(:,10).*power(CONSTANTS(:,6), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,16) = piecewise({1.00000./ALGEBRAIC(:,10)<100.000, 1.00000./ALGEBRAIC(:,10) }, 100.000);
    ALGEBRAIC(:,19) =  CONSTANTS(:,14).*ALGEBRAIC(:,16).*power(CONSTANTS(:,7), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,22) = 1.00000 - (STATES(:,10)+STATES(:,7)+STATES(:,6));
    ALGEBRAIC(:,20) = exp( ( - STATES(:,5)./abs(STATES(:,5))).*CONSTANTS(:,27).*power(STATES(:,5)./CONSTANTS(:,37), 2.00000));
    ALGEBRAIC(:,21) =  CONSTANTS(:,23).*ALGEBRAIC(:,20).*CONSTANTS(:,31).*power(CONSTANTS(:,34), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,25) = ALGEBRAIC(:,21);
    ALGEBRAIC(:,14) = 1.00000+ (1.00000 - ALGEBRAIC(:,4)).*CONSTANTS(:,26);
    ALGEBRAIC(:,17) =  CONSTANTS(:,22).*ALGEBRAIC(:,14).*CONSTANTS(:,31).*power(CONSTANTS(:,33), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,27) = ( CONSTANTS(:,43).*ALGEBRAIC(:,17))./CONSTANTS(:,40);
    ALGEBRAIC(:,28) = ( CONSTANTS(:,67).*STATES(:,10)+ CONSTANTS(:,69).*STATES(:,6)) -  (ALGEBRAIC(:,27)+ALGEBRAIC(:,25)).*STATES(:,7);
    ALGEBRAIC(:,23) = piecewise({STATES(:,4)<CONSTANTS(:,37), exp( CONSTANTS(:,29).*power((CONSTANTS(:,37) - STATES(:,4))./CONSTANTS(:,37), 2.00000)) }, exp( CONSTANTS(:,30).*power((STATES(:,4) - CONSTANTS(:,37))./CONSTANTS(:,37), 2.00000)));
    ALGEBRAIC(:,24) =  CONSTANTS(:,25).*ALGEBRAIC(:,23).*CONSTANTS(:,31).*power(CONSTANTS(:,36), (CONSTANTS(:,19) - 310.000)./10.0000);
    ALGEBRAIC(:,26) = ( (( CONSTANTS(:,44).*ALGEBRAIC(:,24))./CONSTANTS(:,41)).*(CONSTANTS(:,39)+CONSTANTS(:,42)))./(CONSTANTS(:,39)+CONSTANTS(:,45));
    ALGEBRAIC(:,29) = (( CONSTANTS(:,39).*CONSTANTS(:,64).*ALGEBRAIC(:,21).*ALGEBRAIC(:,24))./CONSTANTS(:,41))./( (( (ALGEBRAIC(:,17)./CONSTANTS(:,40)).*CONSTANTS(:,66))./CONSTANTS(:,62)).*CONSTANTS(:,38));
    ALGEBRAIC(:,30) = ALGEBRAIC(:,29);
    ALGEBRAIC(:,33) = ( ALGEBRAIC(:,30).*STATES(:,10)+ ALGEBRAIC(:,25).*STATES(:,7)) -  (CONSTANTS(:,69)+ALGEBRAIC(:,26)).*STATES(:,6);
    ALGEBRAIC(:,32) = ( ALGEBRAIC(:,30).*CONSTANTS(:,69)+ ALGEBRAIC(:,26).*CONSTANTS(:,67)+ CONSTANTS(:,69).*CONSTANTS(:,67))./( CONSTANTS(:,67).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*CONSTANTS(:,69)+ ALGEBRAIC(:,26).*CONSTANTS(:,67)+ CONSTANTS(:,69).*CONSTANTS(:,67)+ ALGEBRAIC(:,25).*ALGEBRAIC(:,26)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,26).*ALGEBRAIC(:,27));
    ALGEBRAIC(:,35) = CONSTANTS(:,60)./2.00000+ (CONSTANTS(:,46)./ALGEBRAIC(:,32)).*(  - CONSTANTS(:,67).*STATES(:,5)+ CONSTANTS(:,69).*(STATES(:,4) - (CONSTANTS(:,37)+STATES(:,5))));
    ALGEBRAIC(:,31) = ( CONSTANTS(:,67).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,25))./( CONSTANTS(:,67).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,25)+ ALGEBRAIC(:,30).*CONSTANTS(:,69)+ ALGEBRAIC(:,26).*CONSTANTS(:,67)+ CONSTANTS(:,69).*CONSTANTS(:,67)+ ALGEBRAIC(:,25).*ALGEBRAIC(:,26)+ ALGEBRAIC(:,30).*ALGEBRAIC(:,27)+ ALGEBRAIC(:,26).*ALGEBRAIC(:,27));
    ALGEBRAIC(:,34) = CONSTANTS(:,60)./2.00000+ (CONSTANTS(:,46)./ALGEBRAIC(:,31)).*ALGEBRAIC(:,25).*((STATES(:,5)+CONSTANTS(:,37)) - STATES(:,4));
    ALGEBRAIC(:,36) = (STATES(:,6)+STATES(:,7))./(CONSTANTS(:,71)+CONSTANTS(:,70));
    ALGEBRAIC(:,37) = (ALGEBRAIC(:,33)+ALGEBRAIC(:,28))./(CONSTANTS(:,71)+CONSTANTS(:,70));
    ALGEBRAIC(:,38) =  CONSTANTS(:,56).*( (1.00000 - ALGEBRAIC(:,5)).*STATES(:,2)+ ALGEBRAIC(:,5).*( ALGEBRAIC(:,36).*STATES(:,3)+ (1.00000 - ALGEBRAIC(:,36)).*STATES(:,2)));
    ALGEBRAIC(:,39) = piecewise({STATES(:,1)<CONSTANTS(:,2),   - 0.500000.*CONSTANTS(:,60) }, 0.00000);
    ALGEBRAIC(:,40) = piecewise({ 2.00000.*CONSTANTS(:,1) - STATES(:,1)>CONSTANTS(:,3),   - 0.500000.*CONSTANTS(:,60) }, 0.00000);
    ALGEBRAIC(:,41) = ALGEBRAIC(:,39) - ALGEBRAIC(:,40);
    ALGEBRAIC(:,42) = ( 2.00000.*ALGEBRAIC(:,41))./(CONSTANTS(:,2) - CONSTANTS(:,3));
    ALGEBRAIC(:,43) = ALGEBRAIC(:,41)./CONSTANTS(:,1);
    ALGEBRAIC(:,44) =  CONSTANTS(:,56).*(  - ALGEBRAIC(:,43).*STATES(:,2)+ (1.00000 - ALGEBRAIC(:,5)).*ALGEBRAIC(:,8)+ ALGEBRAIC(:,43).*( ALGEBRAIC(:,36).*STATES(:,3)+ (1.00000 - ALGEBRAIC(:,36)).*STATES(:,2))+ ALGEBRAIC(:,5).*(( ALGEBRAIC(:,37).*STATES(:,3)+ ALGEBRAIC(:,36).*ALGEBRAIC(:,11)+ (1.00000 - ALGEBRAIC(:,36)).*ALGEBRAIC(:,8)) -  ALGEBRAIC(:,37).*STATES(:,2)));
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