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

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
LEGEND_VOI = strpad('time in component environment (second)');
LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,1) = strpad('R in component membrane (joule_per_kilomole_kelvin)');
LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_mole)');
LEGEND_CONSTANTS(:,4) = strpad('Cm in component membrane (microF)');
LEGEND_ALGEBRAIC(:,38) = strpad('i_K1 in component time_independent_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,54) = strpad('i_to in component transient_outward_current (nanoA)');
LEGEND_ALGEBRAIC(:,40) = strpad('i_Kr in component rapid_delayed_rectifier_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,41) = strpad('i_Ks in component slow_delayed_rectifier_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,42) = strpad('i_K_ATP in component ATP_dependent_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,55) = strpad('i_K_ACh in component ACh_dependent_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,47) = strpad('i_Ca_L_K_cyt in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,50) = strpad('i_Ca_L_K_ds in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,56) = strpad('i_NaK in component sodium_potassium_pump (nanoA)');
LEGEND_ALGEBRAIC(:,43) = strpad('i_Na in component fast_sodium_current (nanoA)');
LEGEND_ALGEBRAIC(:,45) = strpad('i_b_Na in component sodium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,44) = strpad('i_p_Na in component persistent_sodium_current (nanoA)');
LEGEND_ALGEBRAIC(:,48) = strpad('i_Ca_L_Na_cyt in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,51) = strpad('i_Ca_L_Na_ds in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,57) = strpad('i_NaCa_cyt in component sodium_calcium_exchanger (nanoA)');
LEGEND_ALGEBRAIC(:,58) = strpad('i_NaCa_ds in component sodium_calcium_exchanger (nanoA)');
LEGEND_ALGEBRAIC(:,46) = strpad('i_Ca_L_Ca_cyt in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,49) = strpad('i_Ca_L_Ca_ds in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,53) = strpad('i_b_Ca in component calcium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,71) = strpad('i_stretch in component stretch_current (nanoA)');
LEGEND_ALGEBRAIC(:,10) = strpad('i_Stim in component membrane (nanoA)');
LEGEND_CONSTANTS(:,5) = strpad('stim_start in component membrane (second)');
LEGEND_CONSTANTS(:,6) = strpad('stim_end in component membrane (second)');
LEGEND_CONSTANTS(:,7) = strpad('stim_period in component membrane (second)');
LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component membrane (second)');
LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component membrane (nanoA)');
LEGEND_ALGEBRAIC(:,22) = strpad('E_Na in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,29) = strpad('E_K in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,32) = strpad('E_Ks in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,34) = strpad('E_Ca in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,36) = strpad('E_mh in component reversal_potentials (millivolt)');
LEGEND_CONSTANTS(:,10) = strpad('P_kna in component reversal_potentials (dimensionless)');
LEGEND_CONSTANTS(:,11) = strpad('K_o in component extracellular_potassium_concentration (millimolar)');
LEGEND_CONSTANTS(:,12) = strpad('Na_o in component extracellular_sodium_concentration (millimolar)');
LEGEND_STATES(:,2) = strpad('K_i in component intracellular_potassium_concentration (millimolar)');
LEGEND_STATES(:,3) = strpad('Na_i in component intracellular_sodium_concentration (millimolar)');
LEGEND_CONSTANTS(:,13) = strpad('Ca_o in component extracellular_calcium_concentration (millimolar)');
LEGEND_STATES(:,4) = strpad('Ca_i in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,14) = strpad('K_mk1 in component time_independent_potassium_current (millimolar)');
LEGEND_CONSTANTS(:,15) = strpad('g_K1 in component time_independent_potassium_current (microS)');
LEGEND_CONSTANTS(:,16) = strpad('g_Kr1 in component rapid_delayed_rectifier_potassium_current (microS)');
LEGEND_CONSTANTS(:,17) = strpad('g_Kr2 in component rapid_delayed_rectifier_potassium_current (microS)');
LEGEND_STATES(:,5) = strpad('xr1 in component rapid_delayed_rectifier_potassium_current_xr1_gate (dimensionless)');
LEGEND_STATES(:,6) = strpad('xr2 in component rapid_delayed_rectifier_potassium_current_xr2_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,1) = strpad('alpha_xr1 in component rapid_delayed_rectifier_potassium_current_xr1_gate (per_second)');
LEGEND_ALGEBRAIC(:,13) = strpad('beta_xr1 in component rapid_delayed_rectifier_potassium_current_xr1_gate (per_second)');
LEGEND_ALGEBRAIC(:,2) = strpad('alpha_xr2 in component rapid_delayed_rectifier_potassium_current_xr2_gate (per_second)');
LEGEND_ALGEBRAIC(:,14) = strpad('beta_xr2 in component rapid_delayed_rectifier_potassium_current_xr2_gate (per_second)');
LEGEND_CONSTANTS(:,18) = strpad('g_Ks in component slow_delayed_rectifier_potassium_current (microS)');
LEGEND_STATES(:,7) = strpad('xs in component slow_delayed_rectifier_potassium_current_xs_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('alpha_xs in component slow_delayed_rectifier_potassium_current_xs_gate (per_second)');
LEGEND_ALGEBRAIC(:,15) = strpad('beta_xs in component slow_delayed_rectifier_potassium_current_xs_gate (per_second)');
LEGEND_CONSTANTS(:,19) = strpad('g_K_ATP in component ATP_dependent_potassium_current (microS)');
LEGEND_CONSTANTS(:,20) = strpad('K_ATP in component ATP_dependent_potassium_current (millimolar)');
LEGEND_CONSTANTS(:,21) = strpad('ATP in component ATP_dependent_potassium_current (millimolar)');
LEGEND_ALGEBRAIC(:,30) = strpad('i_KNa in component sodium_activated_potassium_current (nanoA)');
LEGEND_CONSTANTS(:,22) = strpad('g_K_Na in component sodium_activated_potassium_current (microS)');
LEGEND_CONSTANTS(:,23) = strpad('K_kna in component sodium_activated_potassium_current (millimolar)');
LEGEND_CONSTANTS(:,24) = strpad('g_Na in component fast_sodium_current (microS)');
LEGEND_STATES(:,8) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,9) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,16) = strpad('alpha_m in component fast_sodium_current_m_gate (per_second)');
LEGEND_ALGEBRAIC(:,25) = strpad('beta_m in component fast_sodium_current_m_gate (per_second)');
LEGEND_CONSTANTS(:,25) = strpad('delta_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,4) = strpad('E0_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,5) = strpad('alpha_h in component fast_sodium_current_h_gate (per_second)');
LEGEND_ALGEBRAIC(:,17) = strpad('beta_h in component fast_sodium_current_h_gate (per_second)');
LEGEND_CONSTANTS(:,26) = strpad('g_pna in component persistent_sodium_current (microS)');
LEGEND_CONSTANTS(:,27) = strpad('g_bna in component sodium_background_current (microS)');
LEGEND_ALGEBRAIC(:,52) = strpad('i_Ca_L in component L_type_Ca_channel (nanoA)');
LEGEND_CONSTANTS(:,28) = strpad('P_Ca_L in component L_type_Ca_channel (nanoA_per_millimolar)');
LEGEND_CONSTANTS(:,29) = strpad('P_CaK in component L_type_Ca_channel (dimensionless)');
LEGEND_CONSTANTS(:,30) = strpad('P_CaNa in component L_type_Ca_channel (dimensionless)');
LEGEND_STATES(:,10) = strpad('Ca_ds in component intracellular_calcium_concentration (millimolar)');
LEGEND_STATES(:,11) = strpad('d in component L_type_Ca_channel_d_gate (dimensionless)');
LEGEND_STATES(:,12) = strpad('f in component L_type_Ca_channel_f_gate (dimensionless)');
LEGEND_STATES(:,13) = strpad('f2 in component L_type_Ca_channel_f2_gate (dimensionless)');
LEGEND_STATES(:,14) = strpad('f2ds in component L_type_Ca_channel_f2ds_gate (dimensionless)');
LEGEND_CONSTANTS(:,31) = strpad('Km_f2 in component L_type_Ca_channel (millimolar)');
LEGEND_CONSTANTS(:,32) = strpad('Km_f2ds in component L_type_Ca_channel (millimolar)');
LEGEND_CONSTANTS(:,33) = strpad('R_decay in component L_type_Ca_channel (per_second)');
LEGEND_CONSTANTS(:,34) = strpad('FrICa in component L_type_Ca_channel (dimensionless)');
LEGEND_ALGEBRAIC(:,18) = strpad('alpha_d in component L_type_Ca_channel_d_gate (per_second)');
LEGEND_ALGEBRAIC(:,26) = strpad('beta_d in component L_type_Ca_channel_d_gate (per_second)');
LEGEND_ALGEBRAIC(:,6) = strpad('E0_d in component L_type_Ca_channel_d_gate (millivolt)');
LEGEND_CONSTANTS(:,35) = strpad('speed_d in component L_type_Ca_channel_d_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,19) = strpad('alpha_f in component L_type_Ca_channel_f_gate (per_second)');
LEGEND_ALGEBRAIC(:,27) = strpad('beta_f in component L_type_Ca_channel_f_gate (per_second)');
LEGEND_CONSTANTS(:,36) = strpad('speed_f in component L_type_Ca_channel_f_gate (dimensionless)');
LEGEND_CONSTANTS(:,37) = strpad('delta_f in component L_type_Ca_channel_f_gate (millivolt)');
LEGEND_ALGEBRAIC(:,7) = strpad('E0_f in component L_type_Ca_channel_f_gate (millivolt)');
LEGEND_CONSTANTS(:,38) = strpad('g_bca in component calcium_background_current (microS)');
LEGEND_CONSTANTS(:,39) = strpad('g_to in component transient_outward_current (microS)');
LEGEND_CONSTANTS(:,40) = strpad('g_tos in component transient_outward_current (dimensionless)');
LEGEND_STATES(:,15) = strpad('s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_STATES(:,16) = strpad('r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,8) = strpad('alpha_s in component transient_outward_current_s_gate (per_second)');
LEGEND_ALGEBRAIC(:,20) = strpad('beta_s in component transient_outward_current_s_gate (per_second)');
LEGEND_CONSTANTS(:,41) = strpad('g_KACh in component ACh_dependent_potassium_current (microS)');
LEGEND_CONSTANTS(:,42) = strpad('ACh in component ACh_dependent_potassium_current (millimolar)');
LEGEND_CONSTANTS(:,43) = strpad('K_D in component ACh_dependent_potassium_current (millimolar)');
LEGEND_STATES(:,17) = strpad('x_ACh in component ACh_dependent_potassium_current_xACh_gate (dimensionless)');
LEGEND_CONSTANTS(:,44) = strpad('alpha_ACh in component ACh_dependent_potassium_current_xACh_gate (per_second)');
LEGEND_CONSTANTS(:,45) = strpad('beta_ACh in component ACh_dependent_potassium_current_xACh_gate (per_second)');
LEGEND_CONSTANTS(:,46) = strpad('i_NaK_max in component sodium_potassium_pump (nanoA)');
LEGEND_CONSTANTS(:,47) = strpad('K_mK in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,48) = strpad('K_mNa in component sodium_potassium_pump (millimolar)');
LEGEND_ALGEBRAIC(:,59) = strpad('i_NaCa in component sodium_calcium_exchanger (nanoA)');
LEGEND_CONSTANTS(:,49) = strpad('k_NaCa in component sodium_calcium_exchanger (nanoA)');
LEGEND_CONSTANTS(:,50) = strpad('n_NaCa in component sodium_calcium_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,51) = strpad('d_NaCa in component sodium_calcium_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,52) = strpad('gamma in component sodium_calcium_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,53) = strpad('FRiNaCa in component sodium_calcium_exchanger (dimensionless)');
LEGEND_ALGEBRAIC(:,61) = strpad('i_up in component sarcoplasmic_reticulum_calcium_pump (millimolar_per_second)');
LEGEND_CONSTANTS(:,100) = strpad('K_1 in component sarcoplasmic_reticulum_calcium_pump (dimensionless)');
LEGEND_ALGEBRAIC(:,60) = strpad('K_2 in component sarcoplasmic_reticulum_calcium_pump (millimolar)');
LEGEND_CONSTANTS(:,54) = strpad('K_cyca in component sarcoplasmic_reticulum_calcium_pump (millimolar)');
LEGEND_CONSTANTS(:,55) = strpad('K_xcs in component sarcoplasmic_reticulum_calcium_pump (dimensionless)');
LEGEND_CONSTANTS(:,56) = strpad('K_srca in component sarcoplasmic_reticulum_calcium_pump (millimolar)');
LEGEND_CONSTANTS(:,57) = strpad('alpha_up in component sarcoplasmic_reticulum_calcium_pump (millimolar_per_second)');
LEGEND_CONSTANTS(:,58) = strpad('beta_up in component sarcoplasmic_reticulum_calcium_pump (millimolar_per_second)');
LEGEND_STATES(:,18) = strpad('Ca_up in component intracellular_calcium_concentration (millimolar)');
LEGEND_ALGEBRAIC(:,62) = strpad('i_trans in component calcium_translocation (millimolar_per_second)');
LEGEND_STATES(:,19) = strpad('Ca_rel in component intracellular_calcium_concentration (millimolar)');
LEGEND_ALGEBRAIC(:,67) = strpad('i_rel in component calcium_release (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,9) = strpad('VoltDep in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,31) = strpad('RegBindSite in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,21) = strpad('CaiReg in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,33) = strpad('ActRate in component calcium_release (per_second)');
LEGEND_ALGEBRAIC(:,35) = strpad('InactRate in component calcium_release (per_second)');
LEGEND_CONSTANTS(:,59) = strpad('K_leak_rate in component calcium_release (per_second)');
LEGEND_ALGEBRAIC(:,64) = strpad('SRLeak in component calcium_release (per_second)');
LEGEND_CONSTANTS(:,60) = strpad('K_m_rel in component calcium_release (per_second)');
LEGEND_CONSTANTS(:,61) = strpad('K_m_Ca_cyt in component calcium_release (millimolar)');
LEGEND_CONSTANTS(:,62) = strpad('K_m_Ca_ds in component calcium_release (millimolar)');
LEGEND_ALGEBRAIC(:,39) = strpad('PrecFrac in component calcium_release (dimensionless)');
LEGEND_STATES(:,20) = strpad('ActFrac in component calcium_release (dimensionless)');
LEGEND_STATES(:,21) = strpad('ProdFrac in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,37) = strpad('SpeedRel in component calcium_release (dimensionless)');
LEGEND_CONSTANTS(:,63) = strpad('gama_SR_SL in component calcium_release (per_micrometre)');
LEGEND_CONSTANTS(:,64) = strpad('gama_SR_IT in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,63) = strpad('isometric_tension in component contraction (dimensionless)');
LEGEND_CONSTANTS(:,65) = strpad('sarcomere_length in component contraction (micrometre)');
LEGEND_CONSTANTS(:,106) = strpad('V_i in component intracellular_calcium_concentration (micrometre3)');
LEGEND_STATES(:,22) = strpad('Ca_Calmod in component intracellular_calcium_concentration (millimolar)');
LEGEND_STATES(:,23) = strpad('Ca_Trop in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,66) = strpad('Calmod in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,67) = strpad('Trop in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,68) = strpad('alpha_Calmod in component intracellular_calcium_concentration (per_millimolar_second)');
LEGEND_CONSTANTS(:,69) = strpad('beta_Calmod in component intracellular_calcium_concentration (per_second)');
LEGEND_CONSTANTS(:,101) = strpad('alpha_Trop in component intracellular_calcium_concentration (per_millimolar_second)');
LEGEND_CONSTANTS(:,70) = strpad('beta_Trop in component intracellular_calcium_concentration (per_second)');
LEGEND_CONSTANTS(:,71) = strpad('gama_Trop_SL in component intracellular_calcium_concentration (per_micrometre)');
LEGEND_CONSTANTS(:,72) = strpad('KTrop in component intracellular_calcium_concentration (per_millimolar_second)');
LEGEND_CONSTANTS(:,74) = strpad('length in component intracellular_calcium_concentration (micrometre)');
LEGEND_CONSTANTS(:,99) = strpad('V_Cell in component intracellular_calcium_concentration (micrometre3)');
LEGEND_CONSTANTS(:,104) = strpad('V_i_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,75) = strpad('V_ds_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,76) = strpad('V_rel_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,77) = strpad('V_e_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,78) = strpad('V_up_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,79) = strpad('Kdecay in component intracellular_calcium_concentration (per_second)');
LEGEND_STATES(:,24) = strpad('light_chain in component contraction (dimensionless)');
LEGEND_STATES(:,25) = strpad('cross_bridge in component contraction (dimensionless)');
LEGEND_CONSTANTS(:,80) = strpad('KCont1 in component contraction (per_second)');
LEGEND_ALGEBRAIC(:,11) = strpad('XCont2 in component contraction (dimensionless)');
LEGEND_ALGEBRAIC(:,23) = strpad('XCont1 in component contraction (dimensionless)');
LEGEND_CONSTANTS(:,81) = strpad('KCont2 in component contraction (per_second)');
LEGEND_CONSTANTS(:,82) = strpad('KCont3 in component contraction (per_second)');
LEGEND_CONSTANTS(:,83) = strpad('KCont4 in component contraction (per_second)');
LEGEND_CONSTANTS(:,84) = strpad('cross_bridge_density in component contraction (per_micrometre)');
LEGEND_CONSTANTS(:,102) = strpad('tension_rest in component contraction (dimensionless)');
LEGEND_CONSTANTS(:,103) = strpad('tension_active in component contraction (dimensionless)');
LEGEND_CONSTANTS(:,105) = strpad('overlap in component contraction (micrometre)');
LEGEND_CONSTANTS(:,107) = strpad('cross_bridge_availability in component contraction (dimensionless)');
LEGEND_ALGEBRAIC(:,66) = strpad('i_Ca_stretch in component stretch_current (nanoA)');
LEGEND_ALGEBRAIC(:,69) = strpad('i_K_stretch in component stretch_current (nanoA)');
LEGEND_ALGEBRAIC(:,68) = strpad('i_Na_stretch in component stretch_current (nanoA)');
LEGEND_ALGEBRAIC(:,70) = strpad('i_An_stretch in component stretch_current (nanoA)');
LEGEND_CONSTANTS(:,85) = strpad('gama_SAC_SL in component stretch_current (per_micrometre)');
LEGEND_CONSTANTS(:,86) = strpad('gama_SAC_IT in component stretch_current (dimensionless)');
LEGEND_CONSTANTS(:,87) = strpad('SLHST in component stretch_current (micrometre)');
LEGEND_CONSTANTS(:,88) = strpad('ITHST in component stretch_current (dimensionless)');
LEGEND_CONSTANTS(:,89) = strpad('g_Ca_stretch in component stretch_current (microS)');
LEGEND_CONSTANTS(:,90) = strpad('g_K_stretch in component stretch_current (microS)');
LEGEND_CONSTANTS(:,91) = strpad('g_Na_stretch in component stretch_current (microS)');
LEGEND_CONSTANTS(:,92) = strpad('g_An_stretch in component stretch_current (microS)');
LEGEND_CONSTANTS(:,93) = strpad('E_An_stretch in component stretch_current (millivolt)');
LEGEND_ALGEBRAIC(:,65) = strpad('f_stretch in component stretch_current (dimensionless)');
LEGEND_CONSTANTS(:,94) = strpad('g_fibro_junct in component fibroblast (microS)');
LEGEND_CONSTANTS(:,95) = strpad('g_fibro in component fibroblast (microS)');
LEGEND_CONSTANTS(:,96) = strpad('c_fibro in component fibroblast (microF)');
LEGEND_CONSTANTS(:,97) = strpad('g_fibro_stretch in component fibroblast (microS)');
LEGEND_CONSTANTS(:,98) = strpad('E_fibro_stretch in component fibroblast (millivolt)');
LEGEND_STATES(:,26) = strpad('V_fibro in component fibroblast (millivolt)');
LEGEND_ALGEBRAIC(:,12) = strpad('i_fibro in component fibroblast (nanoA)');
LEGEND_ALGEBRAIC(:,24) = strpad('i_fibro_junct in component fibroblast (nanoA)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,5) = strpad('d/dt xr1 in component rapid_delayed_rectifier_potassium_current_xr1_gate (dimensionless)');
LEGEND_RATES(:,6) = strpad('d/dt xr2 in component rapid_delayed_rectifier_potassium_current_xr2_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt xs in component slow_delayed_rectifier_potassium_current_xs_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,11) = strpad('d/dt d in component L_type_Ca_channel_d_gate (dimensionless)');
LEGEND_RATES(:,12) = strpad('d/dt f in component L_type_Ca_channel_f_gate (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt f2 in component L_type_Ca_channel_f2_gate (dimensionless)');
LEGEND_RATES(:,14) = strpad('d/dt f2ds in component L_type_Ca_channel_f2ds_gate (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_RATES(:,16) = strpad('d/dt r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_RATES(:,17) = strpad('d/dt x_ACh in component ACh_dependent_potassium_current_xACh_gate (dimensionless)');
LEGEND_RATES(:,20) = strpad('d/dt ActFrac in component calcium_release (dimensionless)');
LEGEND_RATES(:,21) = strpad('d/dt ProdFrac in component calcium_release (dimensionless)');
LEGEND_RATES(:,3) = strpad('d/dt Na_i in component intracellular_sodium_concentration (millimolar)');
LEGEND_RATES(:,2) = strpad('d/dt K_i in component intracellular_potassium_concentration (millimolar)');
LEGEND_RATES(:,4) = strpad('d/dt Ca_i in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,22) = strpad('d/dt Ca_Calmod in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,23) = strpad('d/dt Ca_Trop in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,10) = strpad('d/dt Ca_ds in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,18) = strpad('d/dt Ca_up in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,19) = strpad('d/dt Ca_rel in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,24) = strpad('d/dt light_chain in component contraction (dimensionless)');
LEGEND_RATES(:,25) = strpad('d/dt cross_bridge in component contraction (dimensionless)');
LEGEND_RATES(:,26) = strpad('d/dt V_fibro in component fibroblast (millivolt)');
LEGEND_STATES  = LEGEND_STATES';
LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
LEGEND_RATES = LEGEND_RATES';
LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
STATES(:,1) = -92.849333;
CONSTANTS(:,1) = 8314.472;
CONSTANTS(:,2) = 310;
CONSTANTS(:,3) = 96485.3415;
CONSTANTS(:,4) = 9.5e-5;
CONSTANTS(:,5) = 0.1;
CONSTANTS(:,6) = 10000;
CONSTANTS(:,7) = 1;
CONSTANTS(:,8) = 0.003;
CONSTANTS(:,9) = -3;
CONSTANTS(:,10) = 0.03;
CONSTANTS(:,11) = 4;
CONSTANTS(:,12) = 140;
STATES(:,2) = 136.5644281;
STATES(:,3) = 7.3321223;
CONSTANTS(:,13) = 2;
STATES(:,4) = 1.4e-5;
CONSTANTS(:,14) = 10;
CONSTANTS(:,15) = 0.5;
CONSTANTS(:,16) = 0.0021;
CONSTANTS(:,17) = 0.0013;
STATES(:,5) = 1.03e-5;
STATES(:,6) = 2e-7;
CONSTANTS(:,18) = 0.0026;
STATES(:,7) = 0.001302;
CONSTANTS(:,19) = 0;
CONSTANTS(:,20) = 0.1;
CONSTANTS(:,21) = 0;
CONSTANTS(:,22) = 0;
CONSTANTS(:,23) = 20;
CONSTANTS(:,24) = 2.5;
STATES(:,8) = 0.0016203;
STATES(:,9) = 0.9944036;
CONSTANTS(:,25) = 1e-5;
CONSTANTS(:,26) = 0.004;
CONSTANTS(:,27) = 0.0006;
CONSTANTS(:,28) = 0.1;
CONSTANTS(:,29) = 0.002;
CONSTANTS(:,30) = 0.01;
STATES(:,10) = 1.88e-5;
STATES(:,11) = 0;
STATES(:,12) = 1;
STATES(:,13) = 0.9349197;
STATES(:,14) = 0.9651958;
CONSTANTS(:,31) = 100000;
CONSTANTS(:,32) = 0.001;
CONSTANTS(:,33) = 20;
CONSTANTS(:,34) = 1;
CONSTANTS(:,35) = 3;
CONSTANTS(:,36) = 0.3;
CONSTANTS(:,37) = 0.0001;
CONSTANTS(:,38) = 0.00025;
CONSTANTS(:,39) = 0.005;
CONSTANTS(:,40) = 0;
STATES(:,15) = 0.9948645;
STATES(:,16) = 0;
CONSTANTS(:,41) = 0;
CONSTANTS(:,42) = 5;
CONSTANTS(:,43) = 0.00013;
STATES(:,17) = 0;
CONSTANTS(:,44) = 0.5;
CONSTANTS(:,45) = 0.5;
CONSTANTS(:,46) = 0.7;
CONSTANTS(:,47) = 1;
CONSTANTS(:,48) = 40;
CONSTANTS(:,49) = 0.0005;
CONSTANTS(:,50) = 3;
CONSTANTS(:,51) = 0;
CONSTANTS(:,52) = 0.5;
CONSTANTS(:,53) = 0.001;
CONSTANTS(:,54) = 0.0003;
CONSTANTS(:,55) = 0.4;
CONSTANTS(:,56) = 0.5;
CONSTANTS(:,57) = 0.4;
CONSTANTS(:,58) = 0.03;
STATES(:,18) = 0.4531889;
STATES(:,19) = 0.4481927;
CONSTANTS(:,59) = 0.005;
CONSTANTS(:,60) = 250;
CONSTANTS(:,61) = 0.0005;
CONSTANTS(:,62) = 0.01;
STATES(:,20) = 0.001914;
STATES(:,21) = 0.2854569;
CONSTANTS(:,63) = 2.5;
CONSTANTS(:,64) = 2.5;
CONSTANTS(:,65) = 2;
STATES(:,22) = 0.0005555;
STATES(:,23) = 0.0002;
CONSTANTS(:,66) = 0.02;
CONSTANTS(:,67) = 0.05;
CONSTANTS(:,68) = 100000;
CONSTANTS(:,69) = 50;
CONSTANTS(:,70) = 200;
CONSTANTS(:,71) = 1.5;
CONSTANTS(:,72) = 5000;
CONSTANTS(:,73) = 12;
CONSTANTS(:,74) = 74;
CONSTANTS(:,75) = 0.1;
CONSTANTS(:,76) = 0.1;
CONSTANTS(:,77) = 0.4;
CONSTANTS(:,78) = 0.01;
CONSTANTS(:,79) = 10;
STATES(:,24) = 3.32e-5;
STATES(:,25) = 8.09e-5;
CONSTANTS(:,80) = 12000;
CONSTANTS(:,81) = 100;
CONSTANTS(:,82) = 60;
CONSTANTS(:,83) = 25;
CONSTANTS(:,84) = 0.05;
CONSTANTS(:,85) = 2.5;
CONSTANTS(:,86) = 2.5;
CONSTANTS(:,87) = 2;
CONSTANTS(:,88) = 1;
CONSTANTS(:,89) = 0.01;
CONSTANTS(:,90) = 0.01;
CONSTANTS(:,91) = 0.01;
CONSTANTS(:,92) = 0.01;
CONSTANTS(:,93) = -20;
CONSTANTS(:,94) = 2.9e-4;
CONSTANTS(:,95) = 2e-4;
CONSTANTS(:,96) = 1e-5;
CONSTANTS(:,97) = 0;
CONSTANTS(:,98) = 0;
STATES(:,26) = -20;
CONSTANTS(:,99) = ( 3.14159.*power(CONSTANTS(:,73)./1000.00, 2.00000).*CONSTANTS(:,74))./1000.00;
CONSTANTS(:,100) = ( CONSTANTS(:,54).*CONSTANTS(:,55))./CONSTANTS(:,56);
CONSTANTS(:,101) =  CONSTANTS(:,72).*exp( CONSTANTS(:,71).*CONSTANTS(:,65));
CONSTANTS(:,102) =  0.000200000.*exp( 2.00000.*CONSTANTS(:,65));
CONSTANTS(:,103) = piecewise({CONSTANTS(:,65)>1.00000, 1.00000 - exp(  - 3.00000.*(CONSTANTS(:,65) - 1.00000)) }, 0.00000);
CONSTANTS(:,104) = ((1.00000 - CONSTANTS(:,77)) - CONSTANTS(:,78)) - CONSTANTS(:,76);
CONSTANTS(:,105) = piecewise({CONSTANTS(:,65)>2.00000, 1.00000 -  0.625000.*(CONSTANTS(:,65) - 2.00000) }, 1.00000);
CONSTANTS(:,106) =  CONSTANTS(:,99).*CONSTANTS(:,104);
CONSTANTS(:,107) =  CONSTANTS(:,103).*CONSTANTS(:,105).*CONSTANTS(:,84);
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(:,13) = 1.00000 -  1.00000.*(STATES(:,4)./(CONSTANTS(:,31)+STATES(:,4))+STATES(:,13));
RATES(:,14) =  CONSTANTS(:,33).*(1.00000 - (STATES(:,10)./(CONSTANTS(:,32)+STATES(:,10))+STATES(:,14)));
RATES(:,16) =  333.000.*(1.00000./(1.00000+exp( - (STATES(:,1)+4.00000)./5.00000)) - STATES(:,16));
RATES(:,17) =  CONSTANTS(:,44).*(1.00000 - STATES(:,17)) -  CONSTANTS(:,45).*STATES(:,17);
RATES(:,25) =  CONSTANTS(:,82).*STATES(:,24).*(1.00000 - STATES(:,25)) -  CONSTANTS(:,83).*STATES(:,25);
ALGEBRAIC(:,1) = 50.0000./(1.00000+exp( - (STATES(:,1) - 5.00000)./9.00000));
ALGEBRAIC(:,13) =  0.0500000.*exp( - (STATES(:,1) - 20.0000)./15.0000);
RATES(:,5) =  ALGEBRAIC(:,1).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,13).*STATES(:,5);
ALGEBRAIC(:,2) = 50.0000./(1.00000+exp( - (STATES(:,1) - 5.00000)./9.00000));
ALGEBRAIC(:,14) =  0.400000.*exp( - power((STATES(:,1)+30.0000)./30.0000, 3.00000));
RATES(:,6) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,6)) -  ALGEBRAIC(:,14).*STATES(:,6);
ALGEBRAIC(:,3) = 14.0000./(1.00000+exp( - (STATES(:,1) - 40.0000)./9.00000));
ALGEBRAIC(:,15) =  1.00000.*exp( - STATES(:,1)./45.0000);
RATES(:,7) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,15).*STATES(:,7);
ALGEBRAIC(:,5) =  20.0000.*exp(  - 0.125000.*(STATES(:,1)+75.0000));
ALGEBRAIC(:,17) = 2000.00./(1.00000+ 320.000.*exp(  - 0.100000.*(STATES(:,1)+75.0000)));
RATES(:,9) =  ALGEBRAIC(:,5).*(1.00000 - STATES(:,9)) -  ALGEBRAIC(:,17).*STATES(:,9);
ALGEBRAIC(:,8) =  0.0330000.*exp( - STATES(:,1)./17.0000);
ALGEBRAIC(:,20) = 33.0000./(1.00000+exp(  - 0.125000.*(STATES(:,1)+10.0000)));
RATES(:,15) =  ALGEBRAIC(:,8).*(1.00000 - STATES(:,15)) -  ALGEBRAIC(:,20).*STATES(:,15);
ALGEBRAIC(:,11) = STATES(:,22)./CONSTANTS(:,66);
ALGEBRAIC(:,23) = STATES(:,23)./CONSTANTS(:,67);
RATES(:,24) =  CONSTANTS(:,80).*power(ALGEBRAIC(:,23), 2.00000).*ALGEBRAIC(:,11).*(1.00000 - STATES(:,24)) -  CONSTANTS(:,81).*STATES(:,24);
ALGEBRAIC(:,12) =  CONSTANTS(:,95).*(STATES(:,26)+20.0000)+ CONSTANTS(:,97).*(STATES(:,26) - CONSTANTS(:,98));
ALGEBRAIC(:,24) =   - CONSTANTS(:,94).*(STATES(:,1) - STATES(:,26));
RATES(:,26) =  - (ALGEBRAIC(:,12)+ALGEBRAIC(:,24))./CONSTANTS(:,96);
ALGEBRAIC(:,4) = STATES(:,1)+41.0000;
ALGEBRAIC(:,16) = piecewise({abs(ALGEBRAIC(:,4))<CONSTANTS(:,25), 2000.00 }, ( 200.000.*ALGEBRAIC(:,4))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,4))));
ALGEBRAIC(:,25) =  8000.00.*exp(  - 0.0560000.*(STATES(:,1)+66.0000));
RATES(:,8) =  ALGEBRAIC(:,16).*(1.00000 - STATES(:,8)) -  ALGEBRAIC(:,25).*STATES(:,8);
ALGEBRAIC(:,6) = (STATES(:,1)+24.0000) - 5.00000;
ALGEBRAIC(:,18) = piecewise({abs(ALGEBRAIC(:,6))<0.000100000, 120.000 }, ( 30.0000.*ALGEBRAIC(:,6))./(1.00000 - exp( - ALGEBRAIC(:,6)./4.00000)));
ALGEBRAIC(:,26) = piecewise({abs(ALGEBRAIC(:,6))<0.000100000, 120.000 }, ( 12.0000.*ALGEBRAIC(:,6))./(exp(ALGEBRAIC(:,6)./10.0000) - 1.00000));
RATES(:,11) =  CONSTANTS(:,35).*( ALGEBRAIC(:,18).*(1.00000 - STATES(:,11)) -  ALGEBRAIC(:,26).*STATES(:,11));
ALGEBRAIC(:,7) = STATES(:,1)+34.0000;
ALGEBRAIC(:,19) = piecewise({abs(ALGEBRAIC(:,7))<CONSTANTS(:,37), 25.0000 }, ( 6.25000.*ALGEBRAIC(:,7))./(exp(ALGEBRAIC(:,7)./4.00000) - 1.00000));
ALGEBRAIC(:,27) = 12.0000./(1.00000+exp((  - 1.00000.*(STATES(:,1)+34.0000))./4.00000));
RATES(:,12) =  CONSTANTS(:,36).*( ALGEBRAIC(:,19).*(1.00000 - STATES(:,12)) -  ALGEBRAIC(:,27).*STATES(:,12));
ALGEBRAIC(:,21) = STATES(:,4)./(STATES(:,4)+CONSTANTS(:,61));
ALGEBRAIC(:,28) = STATES(:,10)./(STATES(:,10)+CONSTANTS(:,62));
ALGEBRAIC(:,31) = ALGEBRAIC(:,21)+ (1.00000 - ALGEBRAIC(:,21)).*ALGEBRAIC(:,28);
ALGEBRAIC(:,35) = 60.0000+ 500.000.*power(ALGEBRAIC(:,31), 2.00000);
ALGEBRAIC(:,37) = piecewise({STATES(:,1)< - 50.0000, 5.00000 }, 1.00000);
RATES(:,21) =  STATES(:,20).*ALGEBRAIC(:,37).*ALGEBRAIC(:,35) -  ALGEBRAIC(:,37).*1.00000.*STATES(:,21);
ALGEBRAIC(:,9) = exp( 0.0800000.*(STATES(:,1) - 40.0000));
ALGEBRAIC(:,33) =  0.00000.*ALGEBRAIC(:,9)+ 500.000.*power(ALGEBRAIC(:,31), 2.00000);
ALGEBRAIC(:,39) = (1.00000 - STATES(:,20)) - STATES(:,21);
RATES(:,20) =  ALGEBRAIC(:,39).*ALGEBRAIC(:,37).*ALGEBRAIC(:,33) -  STATES(:,20).*ALGEBRAIC(:,37).*ALGEBRAIC(:,35);
ALGEBRAIC(:,49) =  ((( CONSTANTS(:,34).*4.00000.*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,14).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
RATES(:,10) = (  - 1.00000.*ALGEBRAIC(:,49))./( 2.00000.*1.00000.*CONSTANTS(:,75).*CONSTANTS(:,106).*CONSTANTS(:,3)) -  STATES(:,10).*CONSTANTS(:,79);
ALGEBRAIC(:,29) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
ALGEBRAIC(:,38) = ( (( CONSTANTS(:,15).*CONSTANTS(:,11))./(CONSTANTS(:,11)+CONSTANTS(:,14))).*(STATES(:,1) - ALGEBRAIC(:,29)))./(1.00000+exp(( ((STATES(:,1) - ALGEBRAIC(:,29)) - 10.0000).*CONSTANTS(:,3).*1.25000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,54) =  CONSTANTS(:,39).*(CONSTANTS(:,40)+ STATES(:,15).*(1.00000 - CONSTANTS(:,40))).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,29));
ALGEBRAIC(:,40) =  (( ( CONSTANTS(:,16).*STATES(:,5)+ CONSTANTS(:,17).*STATES(:,6)).*1.00000)./(1.00000+exp((STATES(:,1)+9.00000)./22.4000))).*(STATES(:,1) - ALGEBRAIC(:,29));
ALGEBRAIC(:,32) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,11)+ CONSTANTS(:,10).*CONSTANTS(:,12))./(STATES(:,2)+ CONSTANTS(:,10).*STATES(:,3)));
ALGEBRAIC(:,41) =  CONSTANTS(:,18).*power(STATES(:,7), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,32));
ALGEBRAIC(:,47) =  ((( (1.00000 - CONSTANTS(:,34)).*CONSTANTS(:,29).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,2).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,50) =  ((( CONSTANTS(:,34).*CONSTANTS(:,29).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,14).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,2).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,56) = ( (( CONSTANTS(:,46).*CONSTANTS(:,11))./(CONSTANTS(:,47)+CONSTANTS(:,11))).*STATES(:,3))./(CONSTANTS(:,48)+STATES(:,3));
RATES(:,2) =  ( - 1.00000./( 1.00000.*CONSTANTS(:,106).*CONSTANTS(:,3))).*((ALGEBRAIC(:,38)+ALGEBRAIC(:,40)+ALGEBRAIC(:,41)+ALGEBRAIC(:,47)+ALGEBRAIC(:,50)+ALGEBRAIC(:,54)) -  2.00000.*ALGEBRAIC(:,56));
ALGEBRAIC(:,36) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,12)+ 0.120000.*CONSTANTS(:,11))./(STATES(:,3)+ 0.120000.*STATES(:,2)));
ALGEBRAIC(:,43) =  CONSTANTS(:,24).*power(STATES(:,8), 3.00000).*STATES(:,9).*(STATES(:,1) - ALGEBRAIC(:,36));
ALGEBRAIC(:,22) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,3));
ALGEBRAIC(:,45) =  CONSTANTS(:,27).*(STATES(:,1) - ALGEBRAIC(:,22));
ALGEBRAIC(:,44) =  (( CONSTANTS(:,26).*1.00000)./(1.00000+exp( - (STATES(:,1)+52.0000)./8.00000))).*(STATES(:,1) - ALGEBRAIC(:,22));
ALGEBRAIC(:,48) =  ((( (1.00000 - CONSTANTS(:,34)).*CONSTANTS(:,30).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,12).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,51) =  ((( CONSTANTS(:,34).*CONSTANTS(:,30).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,14).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,12).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,57) = ( (1.00000 - CONSTANTS(:,53)).*CONSTANTS(:,49).*( exp(( CONSTANTS(:,52).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), CONSTANTS(:,50)).*CONSTANTS(:,13) -  exp(( (CONSTANTS(:,52) - 1.00000).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,12), CONSTANTS(:,50)).*STATES(:,4)))./( (1.00000+ CONSTANTS(:,51).*( STATES(:,4).*power(CONSTANTS(:,12), CONSTANTS(:,50))+ CONSTANTS(:,13).*power(STATES(:,3), CONSTANTS(:,50)))).*(1.00000+STATES(:,4)./0.00690000));
RATES(:,3) =  ( - 1.00000./( 1.00000.*CONSTANTS(:,106).*CONSTANTS(:,3))).*(ALGEBRAIC(:,43)+ALGEBRAIC(:,44)+ALGEBRAIC(:,45)+ 3.00000.*ALGEBRAIC(:,56)+ 3.00000.*ALGEBRAIC(:,57)+ALGEBRAIC(:,48)+ALGEBRAIC(:,51));
RATES(:,22) =  CONSTANTS(:,68).*STATES(:,4).*(CONSTANTS(:,66) - STATES(:,22)) -  CONSTANTS(:,69).*STATES(:,22);
ALGEBRAIC(:,60) = STATES(:,4)+ STATES(:,18).*CONSTANTS(:,100)+ CONSTANTS(:,54).*CONSTANTS(:,55)+CONSTANTS(:,54);
ALGEBRAIC(:,61) =  (STATES(:,4)./ALGEBRAIC(:,60)).*CONSTANTS(:,57) -  (( STATES(:,18).*CONSTANTS(:,100))./ALGEBRAIC(:,60)).*CONSTANTS(:,58);
ALGEBRAIC(:,62) =  50.0000.*(STATES(:,18) - STATES(:,19));
RATES(:,18) =  (CONSTANTS(:,104)./CONSTANTS(:,78)).*ALGEBRAIC(:,61) - ALGEBRAIC(:,62);
RATES(:,23) =  CONSTANTS(:,101).*STATES(:,4).*(CONSTANTS(:,67) - STATES(:,23)) -  CONSTANTS(:,70).*STATES(:,23);
ALGEBRAIC(:,58) = ( CONSTANTS(:,53).*CONSTANTS(:,49).*( exp(( CONSTANTS(:,52).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), CONSTANTS(:,50)).*CONSTANTS(:,13) -  exp(( (CONSTANTS(:,52) - 1.00000).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,12), CONSTANTS(:,50)).*STATES(:,10)))./( (1.00000+ CONSTANTS(:,51).*( STATES(:,10).*power(CONSTANTS(:,12), CONSTANTS(:,50))+ CONSTANTS(:,13).*power(STATES(:,3), CONSTANTS(:,50)))).*(1.00000+STATES(:,10)./0.00690000));
ALGEBRAIC(:,46) =  ((( (1.00000 - CONSTANTS(:,34)).*4.00000.*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,34) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,13)./STATES(:,4));
ALGEBRAIC(:,53) =  CONSTANTS(:,38).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,63) =  STATES(:,25).*CONSTANTS(:,107)+CONSTANTS(:,102);
ALGEBRAIC(:,64) = piecewise({ALGEBRAIC(:,63)>0.00000,  CONSTANTS(:,59).*exp( CONSTANTS(:,64).*ALGEBRAIC(:,63)) },  CONSTANTS(:,59).*exp( CONSTANTS(:,63).*CONSTANTS(:,65)));
ALGEBRAIC(:,67) =  ( power(STATES(:,20)./(STATES(:,20)+0.250000), 2.00000).*CONSTANTS(:,60)+ALGEBRAIC(:,64)).*STATES(:,19);
RATES(:,4) = ((( ( - 1.00000./( 2.00000.*1.00000.*CONSTANTS(:,106).*CONSTANTS(:,3))).*(((ALGEBRAIC(:,46)+ALGEBRAIC(:,53)) -  2.00000.*ALGEBRAIC(:,57)) -  2.00000.*ALGEBRAIC(:,58))+ STATES(:,10).*CONSTANTS(:,75).*CONSTANTS(:,79)+( ALGEBRAIC(:,67).*CONSTANTS(:,76))./CONSTANTS(:,104)) - RATES(:,22)) - RATES(:,23)) - ALGEBRAIC(:,61);
RATES(:,19) =  (CONSTANTS(:,78)./CONSTANTS(:,76)).*ALGEBRAIC(:,62) - ALGEBRAIC(:,67);
ALGEBRAIC(:,42) = ( CONSTANTS(:,19).*(STATES(:,1)+80.0000))./(1.00000+power(CONSTANTS(:,21)./CONSTANTS(:,20), 2.00000));
ALGEBRAIC(:,55) = ( CONSTANTS(:,41).*(CONSTANTS(:,11)./(CONSTANTS(:,11)+CONSTANTS(:,14))).*STATES(:,17).*(1.00000./(1.00000+power(CONSTANTS(:,43)./CONSTANTS(:,42), 2.00000))).*(STATES(:,1) - ALGEBRAIC(:,29)))./(1.00000+exp(( 2.00000.*CONSTANTS(:,3).*(STATES(:,1) - (ALGEBRAIC(:,29)+10.0000)))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,65) = piecewise({ALGEBRAIC(:,63)>0.00000, 1.00000./(1.00000+exp(  - 2.00000.*CONSTANTS(:,86).*(ALGEBRAIC(:,63) - CONSTANTS(:,88)))) }, 1.00000./(1.00000+exp(  - 2.00000.*CONSTANTS(:,85).*(CONSTANTS(:,65) - CONSTANTS(:,87)))));
ALGEBRAIC(:,66) =  CONSTANTS(:,89).*ALGEBRAIC(:,65).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,69) =  CONSTANTS(:,90).*ALGEBRAIC(:,65).*(STATES(:,1) - ALGEBRAIC(:,29));
ALGEBRAIC(:,68) =  CONSTANTS(:,91).*ALGEBRAIC(:,65).*(STATES(:,1) - ALGEBRAIC(:,22));
ALGEBRAIC(:,70) =  CONSTANTS(:,92).*ALGEBRAIC(:,65).*(STATES(:,1) - CONSTANTS(:,93));
ALGEBRAIC(:,71) = ALGEBRAIC(:,66)+ALGEBRAIC(:,68)+ALGEBRAIC(:,69)+ALGEBRAIC(:,70);
ALGEBRAIC(:,10) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
RATES(:,1) =  ( - 1.00000./CONSTANTS(:,4)).*(ALGEBRAIC(:,10)+ALGEBRAIC(:,38)+ALGEBRAIC(:,54)+ALGEBRAIC(:,40)+ALGEBRAIC(:,41)+ALGEBRAIC(:,42)+ALGEBRAIC(:,55)+ALGEBRAIC(:,56)+ALGEBRAIC(:,43)+ALGEBRAIC(:,45)+ALGEBRAIC(:,44)+ALGEBRAIC(:,48)+ALGEBRAIC(:,51)+ALGEBRAIC(:,57)+ALGEBRAIC(:,58)+ALGEBRAIC(:,46)+ALGEBRAIC(:,49)+ALGEBRAIC(:,47)+ALGEBRAIC(:,50)+ALGEBRAIC(:,53)+ALGEBRAIC(:,71));
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) = 50.0000./(1.00000+exp( - (STATES(:,1) - 5.00000)./9.00000));
ALGEBRAIC(:,13) =  0.0500000.*exp( - (STATES(:,1) - 20.0000)./15.0000);
ALGEBRAIC(:,2) = 50.0000./(1.00000+exp( - (STATES(:,1) - 5.00000)./9.00000));
ALGEBRAIC(:,14) =  0.400000.*exp( - power((STATES(:,1)+30.0000)./30.0000, 3.00000));
ALGEBRAIC(:,3) = 14.0000./(1.00000+exp( - (STATES(:,1) - 40.0000)./9.00000));
ALGEBRAIC(:,15) =  1.00000.*exp( - STATES(:,1)./45.0000);
ALGEBRAIC(:,5) =  20.0000.*exp(  - 0.125000.*(STATES(:,1)+75.0000));
ALGEBRAIC(:,17) = 2000.00./(1.00000+ 320.000.*exp(  - 0.100000.*(STATES(:,1)+75.0000)));
ALGEBRAIC(:,8) =  0.0330000.*exp( - STATES(:,1)./17.0000);
ALGEBRAIC(:,20) = 33.0000./(1.00000+exp(  - 0.125000.*(STATES(:,1)+10.0000)));
ALGEBRAIC(:,11) = STATES(:,22)./CONSTANTS(:,66);
ALGEBRAIC(:,23) = STATES(:,23)./CONSTANTS(:,67);
ALGEBRAIC(:,12) =  CONSTANTS(:,95).*(STATES(:,26)+20.0000)+ CONSTANTS(:,97).*(STATES(:,26) - CONSTANTS(:,98));
ALGEBRAIC(:,24) =   - CONSTANTS(:,94).*(STATES(:,1) - STATES(:,26));
ALGEBRAIC(:,4) = STATES(:,1)+41.0000;
ALGEBRAIC(:,16) = piecewise({abs(ALGEBRAIC(:,4))<CONSTANTS(:,25), 2000.00 }, ( 200.000.*ALGEBRAIC(:,4))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,4))));
ALGEBRAIC(:,25) =  8000.00.*exp(  - 0.0560000.*(STATES(:,1)+66.0000));
ALGEBRAIC(:,6) = (STATES(:,1)+24.0000) - 5.00000;
ALGEBRAIC(:,18) = piecewise({abs(ALGEBRAIC(:,6))<0.000100000, 120.000 }, ( 30.0000.*ALGEBRAIC(:,6))./(1.00000 - exp( - ALGEBRAIC(:,6)./4.00000)));
ALGEBRAIC(:,26) = piecewise({abs(ALGEBRAIC(:,6))<0.000100000, 120.000 }, ( 12.0000.*ALGEBRAIC(:,6))./(exp(ALGEBRAIC(:,6)./10.0000) - 1.00000));
ALGEBRAIC(:,7) = STATES(:,1)+34.0000;
ALGEBRAIC(:,19) = piecewise({abs(ALGEBRAIC(:,7))<CONSTANTS(:,37), 25.0000 }, ( 6.25000.*ALGEBRAIC(:,7))./(exp(ALGEBRAIC(:,7)./4.00000) - 1.00000));
ALGEBRAIC(:,27) = 12.0000./(1.00000+exp((  - 1.00000.*(STATES(:,1)+34.0000))./4.00000));
ALGEBRAIC(:,21) = STATES(:,4)./(STATES(:,4)+CONSTANTS(:,61));
ALGEBRAIC(:,28) = STATES(:,10)./(STATES(:,10)+CONSTANTS(:,62));
ALGEBRAIC(:,31) = ALGEBRAIC(:,21)+ (1.00000 - ALGEBRAIC(:,21)).*ALGEBRAIC(:,28);
ALGEBRAIC(:,35) = 60.0000+ 500.000.*power(ALGEBRAIC(:,31), 2.00000);
ALGEBRAIC(:,37) = piecewise({STATES(:,1)< - 50.0000, 5.00000 }, 1.00000);
ALGEBRAIC(:,9) = exp( 0.0800000.*(STATES(:,1) - 40.0000));
ALGEBRAIC(:,33) =  0.00000.*ALGEBRAIC(:,9)+ 500.000.*power(ALGEBRAIC(:,31), 2.00000);
ALGEBRAIC(:,39) = (1.00000 - STATES(:,20)) - STATES(:,21);
ALGEBRAIC(:,49) =  ((( CONSTANTS(:,34).*4.00000.*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,14).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,29) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
ALGEBRAIC(:,38) = ( (( CONSTANTS(:,15).*CONSTANTS(:,11))./(CONSTANTS(:,11)+CONSTANTS(:,14))).*(STATES(:,1) - ALGEBRAIC(:,29)))./(1.00000+exp(( ((STATES(:,1) - ALGEBRAIC(:,29)) - 10.0000).*CONSTANTS(:,3).*1.25000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,54) =  CONSTANTS(:,39).*(CONSTANTS(:,40)+ STATES(:,15).*(1.00000 - CONSTANTS(:,40))).*STATES(:,16).*(STATES(:,1) - ALGEBRAIC(:,29));
ALGEBRAIC(:,40) =  (( ( CONSTANTS(:,16).*STATES(:,5)+ CONSTANTS(:,17).*STATES(:,6)).*1.00000)./(1.00000+exp((STATES(:,1)+9.00000)./22.4000))).*(STATES(:,1) - ALGEBRAIC(:,29));
ALGEBRAIC(:,32) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,11)+ CONSTANTS(:,10).*CONSTANTS(:,12))./(STATES(:,2)+ CONSTANTS(:,10).*STATES(:,3)));
ALGEBRAIC(:,41) =  CONSTANTS(:,18).*power(STATES(:,7), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,32));
ALGEBRAIC(:,47) =  ((( (1.00000 - CONSTANTS(:,34)).*CONSTANTS(:,29).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,2).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,50) =  ((( CONSTANTS(:,34).*CONSTANTS(:,29).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,14).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,2).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,56) = ( (( CONSTANTS(:,46).*CONSTANTS(:,11))./(CONSTANTS(:,47)+CONSTANTS(:,11))).*STATES(:,3))./(CONSTANTS(:,48)+STATES(:,3));
ALGEBRAIC(:,36) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,12)+ 0.120000.*CONSTANTS(:,11))./(STATES(:,3)+ 0.120000.*STATES(:,2)));
ALGEBRAIC(:,43) =  CONSTANTS(:,24).*power(STATES(:,8), 3.00000).*STATES(:,9).*(STATES(:,1) - ALGEBRAIC(:,36));
ALGEBRAIC(:,22) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,12)./STATES(:,3));
ALGEBRAIC(:,45) =  CONSTANTS(:,27).*(STATES(:,1) - ALGEBRAIC(:,22));
ALGEBRAIC(:,44) =  (( CONSTANTS(:,26).*1.00000)./(1.00000+exp( - (STATES(:,1)+52.0000)./8.00000))).*(STATES(:,1) - ALGEBRAIC(:,22));
ALGEBRAIC(:,48) =  ((( (1.00000 - CONSTANTS(:,34)).*CONSTANTS(:,30).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,12).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,51) =  ((( CONSTANTS(:,34).*CONSTANTS(:,30).*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,14).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,12).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,57) = ( (1.00000 - CONSTANTS(:,53)).*CONSTANTS(:,49).*( exp(( CONSTANTS(:,52).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), CONSTANTS(:,50)).*CONSTANTS(:,13) -  exp(( (CONSTANTS(:,52) - 1.00000).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,12), CONSTANTS(:,50)).*STATES(:,4)))./( (1.00000+ CONSTANTS(:,51).*( STATES(:,4).*power(CONSTANTS(:,12), CONSTANTS(:,50))+ CONSTANTS(:,13).*power(STATES(:,3), CONSTANTS(:,50)))).*(1.00000+STATES(:,4)./0.00690000));
ALGEBRAIC(:,60) = STATES(:,4)+ STATES(:,18).*CONSTANTS(:,100)+ CONSTANTS(:,54).*CONSTANTS(:,55)+CONSTANTS(:,54);
ALGEBRAIC(:,61) =  (STATES(:,4)./ALGEBRAIC(:,60)).*CONSTANTS(:,57) -  (( STATES(:,18).*CONSTANTS(:,100))./ALGEBRAIC(:,60)).*CONSTANTS(:,58);
ALGEBRAIC(:,62) =  50.0000.*(STATES(:,18) - STATES(:,19));
ALGEBRAIC(:,58) = ( CONSTANTS(:,53).*CONSTANTS(:,49).*( exp(( CONSTANTS(:,52).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), CONSTANTS(:,50)).*CONSTANTS(:,13) -  exp(( (CONSTANTS(:,52) - 1.00000).*(CONSTANTS(:,50) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,12), CONSTANTS(:,50)).*STATES(:,10)))./( (1.00000+ CONSTANTS(:,51).*( STATES(:,10).*power(CONSTANTS(:,12), CONSTANTS(:,50))+ CONSTANTS(:,13).*power(STATES(:,3), CONSTANTS(:,50)))).*(1.00000+STATES(:,10)./0.00690000));
ALGEBRAIC(:,46) =  ((( (1.00000 - CONSTANTS(:,34)).*4.00000.*CONSTANTS(:,28).*STATES(:,11).*STATES(:,12).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,13).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,34) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,13)./STATES(:,4));
ALGEBRAIC(:,53) =  CONSTANTS(:,38).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,63) =  STATES(:,25).*CONSTANTS(:,107)+CONSTANTS(:,102);
ALGEBRAIC(:,64) = piecewise({ALGEBRAIC(:,63)>0.00000,  CONSTANTS(:,59).*exp( CONSTANTS(:,64).*ALGEBRAIC(:,63)) },  CONSTANTS(:,59).*exp( CONSTANTS(:,63).*CONSTANTS(:,65)));
ALGEBRAIC(:,67) =  ( power(STATES(:,20)./(STATES(:,20)+0.250000), 2.00000).*CONSTANTS(:,60)+ALGEBRAIC(:,64)).*STATES(:,19);
ALGEBRAIC(:,42) = ( CONSTANTS(:,19).*(STATES(:,1)+80.0000))./(1.00000+power(CONSTANTS(:,21)./CONSTANTS(:,20), 2.00000));
ALGEBRAIC(:,55) = ( CONSTANTS(:,41).*(CONSTANTS(:,11)./(CONSTANTS(:,11)+CONSTANTS(:,14))).*STATES(:,17).*(1.00000./(1.00000+power(CONSTANTS(:,43)./CONSTANTS(:,42), 2.00000))).*(STATES(:,1) - ALGEBRAIC(:,29)))./(1.00000+exp(( 2.00000.*CONSTANTS(:,3).*(STATES(:,1) - (ALGEBRAIC(:,29)+10.0000)))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,65) = piecewise({ALGEBRAIC(:,63)>0.00000, 1.00000./(1.00000+exp(  - 2.00000.*CONSTANTS(:,86).*(ALGEBRAIC(:,63) - CONSTANTS(:,88)))) }, 1.00000./(1.00000+exp(  - 2.00000.*CONSTANTS(:,85).*(CONSTANTS(:,65) - CONSTANTS(:,87)))));
ALGEBRAIC(:,66) =  CONSTANTS(:,89).*ALGEBRAIC(:,65).*(STATES(:,1) - ALGEBRAIC(:,34));
ALGEBRAIC(:,69) =  CONSTANTS(:,90).*ALGEBRAIC(:,65).*(STATES(:,1) - ALGEBRAIC(:,29));
ALGEBRAIC(:,68) =  CONSTANTS(:,91).*ALGEBRAIC(:,65).*(STATES(:,1) - ALGEBRAIC(:,22));
ALGEBRAIC(:,70) =  CONSTANTS(:,92).*ALGEBRAIC(:,65).*(STATES(:,1) - CONSTANTS(:,93));
ALGEBRAIC(:,71) = ALGEBRAIC(:,66)+ALGEBRAIC(:,68)+ALGEBRAIC(:,69)+ALGEBRAIC(:,70);
ALGEBRAIC(:,10) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
ALGEBRAIC(:,30) =  (( CONSTANTS(:,22).*STATES(:,3))./(STATES(:,3)+CONSTANTS(:,23))).*(STATES(:,1) - ALGEBRAIC(:,29));
ALGEBRAIC(:,52) = ALGEBRAIC(:,46)+ALGEBRAIC(:,47)+ALGEBRAIC(:,48)+ALGEBRAIC(:,49)+ALGEBRAIC(:,50)+ALGEBRAIC(:,51);
ALGEBRAIC(:,59) = ALGEBRAIC(:,57)+ALGEBRAIC(:,58);
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
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

```
Source
Derived from workspace Noble, Varghese, Kohl, Noble, 1998 at changeset 995dda261096.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: