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

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

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

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

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

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

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

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
LEGEND_VOI = strpad('time in component environment (millisecond)');
LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,1) = strpad('Cm in component membrane (microF_per_cm2)');
LEGEND_CONSTANTS(:,2) = strpad('Vmyo in component membrane (microlitre)');
LEGEND_CONSTANTS(:,3) = strpad('VJSR in component membrane (microlitre)');
LEGEND_CONSTANTS(:,4) = strpad('VNSR in component membrane (microlitre)');
LEGEND_CONSTANTS(:,5) = strpad('Vss in component membrane (microlitre)');
LEGEND_CONSTANTS(:,6) = strpad('Acap in component membrane (cm2)');
LEGEND_CONSTANTS(:,7) = strpad('Ko in component membrane (micromolar)');
LEGEND_CONSTANTS(:,8) = strpad('Nao in component membrane (micromolar)');
LEGEND_CONSTANTS(:,9) = strpad('Cao in component membrane (micromolar)');
LEGEND_CONSTANTS(:,10) = strpad('Clo in component membrane (micromolar)');
LEGEND_CONSTANTS(:,11) = strpad('Cli in component membrane (micromolar)');
LEGEND_CONSTANTS(:,12) = strpad('R in component membrane (joule_per_mole_kelvin)');
LEGEND_CONSTANTS(:,13) = strpad('T in component membrane (kelvin)');
LEGEND_CONSTANTS(:,14) = strpad('F in component membrane (coulomb_per_millimole)');
LEGEND_ALGEBRAIC(:,1) = strpad('i_stim in component membrane (picoA_per_picoF)');
LEGEND_CONSTANTS(:,15) = strpad('stim_start in component membrane (millisecond)');
LEGEND_CONSTANTS(:,16) = strpad('stim_end in component membrane (millisecond)');
LEGEND_CONSTANTS(:,17) = strpad('stim_period in component membrane (millisecond)');
LEGEND_CONSTANTS(:,18) = strpad('stim_duration in component membrane (millisecond)');
LEGEND_CONSTANTS(:,19) = strpad('stim_amplitude in component membrane (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,44) = strpad('i_CaL in component L_type_calcium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,46) = strpad('i_CaT in component T_type_calcium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,48) = strpad('i_pCa in component calcium_pump_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,50) = strpad('i_NaCa in component sodium_calcium_exchange_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,52) = strpad('i_Cab in component calcium_background_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,54) = strpad('i_Na in component fast_sodium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,55) = strpad('i_Nab in component sodium_background_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,64) = strpad('i_NaK in component sodium_potassium_pump_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,57) = strpad('i_Kto_f in component fast_transient_outward_potassium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,60) = strpad('i_K1 in component time_independent_potassium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,61) = strpad('i_Ks in component slow_delayed_rectifier_potassium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,58) = strpad('i_Kur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,66) = strpad('i_ClCa in component calcium_activated_chloride_current (picoA_per_picoF)');
LEGEND_ALGEBRAIC(:,62) = strpad('i_Kr in component rapid_delayed_rectifier_potassium_current (picoA_per_picoF)');
LEGEND_STATES(:,2) = strpad('Cai in component calcium_concentration (micromolar)');
LEGEND_STATES(:,3) = strpad('Cass in component calcium_concentration (micromolar)');
LEGEND_STATES(:,4) = strpad('CaJSR in component calcium_concentration (micromolar)');
LEGEND_STATES(:,5) = strpad('CaNSR in component calcium_concentration (micromolar)');
LEGEND_ALGEBRAIC(:,16) = strpad('Bi in component calcium_concentration (dimensionless)');
LEGEND_ALGEBRAIC(:,31) = strpad('Bss in component calcium_concentration (dimensionless)');
LEGEND_ALGEBRAIC(:,36) = strpad('BJSR in component calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,20) = strpad('CMDN_tot in component calcium_concentration (micromolar)');
LEGEND_CONSTANTS(:,21) = strpad('CSQN_tot in component calcium_concentration (micromolar)');
LEGEND_CONSTANTS(:,22) = strpad('Km_CMDN in component calcium_concentration (micromolar)');
LEGEND_CONSTANTS(:,23) = strpad('Km_CSQN in component calcium_concentration (micromolar)');
LEGEND_ALGEBRAIC(:,45) = strpad('J_leak in component calcium_fluxes (micromolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,40) = strpad('J_rel in component calcium_fluxes (micromolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,47) = strpad('J_up in component calcium_fluxes (micromolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,42) = strpad('J_tr in component calcium_fluxes (micromolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,49) = strpad('J_trpn in component calcium_fluxes (micromolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,43) = strpad('J_xfer in component calcium_fluxes (micromolar_per_millisecond)');
LEGEND_CONSTANTS(:,24) = strpad('k_plus_htrpn in component calcium_fluxes (per_micromolar_millisecond)');
LEGEND_CONSTANTS(:,25) = strpad('k_minus_htrpn in component calcium_fluxes (per_millisecond)');
LEGEND_CONSTANTS(:,26) = strpad('k_plus_ltrpn in component calcium_fluxes (per_micromolar_millisecond)');
LEGEND_CONSTANTS(:,27) = strpad('k_minus_ltrpn in component calcium_fluxes (per_millisecond)');
LEGEND_STATES(:,6) = strpad('P_RyR in component calcium_fluxes (dimensionless)');
LEGEND_CONSTANTS(:,28) = strpad('v1 in component calcium_fluxes (per_millisecond)');
LEGEND_CONSTANTS(:,29) = strpad('tau_tr in component calcium_fluxes (millisecond)');
LEGEND_CONSTANTS(:,30) = strpad('v2 in component calcium_fluxes (per_millisecond)');
LEGEND_CONSTANTS(:,31) = strpad('tau_xfer in component calcium_fluxes (millisecond)');
LEGEND_CONSTANTS(:,32) = strpad('v3 in component calcium_fluxes (micromolar_per_millisecond)');
LEGEND_CONSTANTS(:,33) = strpad('Km_up in component calcium_fluxes (micromolar)');
LEGEND_CONSTANTS(:,34) = strpad('LTRPN_tot in component calcium_buffering (micromolar)');
LEGEND_CONSTANTS(:,35) = strpad('HTRPN_tot in component calcium_buffering (micromolar)');
LEGEND_STATES(:,7) = strpad('LTRPN_Ca in component calcium_buffering (micromolar)');
LEGEND_STATES(:,8) = strpad('HTRPN_Ca in component calcium_buffering (micromolar)');
LEGEND_CONSTANTS(:,36) = strpad('i_CaL_max in component L_type_calcium_current (picoA_per_picoF)');
LEGEND_STATES(:,9) = strpad('P_O1 in component ryanodine_receptors (dimensionless)');
LEGEND_STATES(:,10) = strpad('P_O2 in component ryanodine_receptors (dimensionless)');
LEGEND_ALGEBRAIC(:,2) = strpad('P_C1 in component ryanodine_receptors (dimensionless)');
LEGEND_STATES(:,11) = strpad('P_C2 in component ryanodine_receptors (dimensionless)');
LEGEND_CONSTANTS(:,37) = strpad('k_plus_a in component ryanodine_receptors (micromolar4_per_millisecond)');
LEGEND_CONSTANTS(:,38) = strpad('k_minus_a in component ryanodine_receptors (per_millisecond)');
LEGEND_CONSTANTS(:,39) = strpad('k_plus_b in component ryanodine_receptors (micromolar3_per_millisecond)');
LEGEND_CONSTANTS(:,40) = strpad('k_minus_b in component ryanodine_receptors (per_millisecond)');
LEGEND_CONSTANTS(:,41) = strpad('k_plus_c in component ryanodine_receptors (per_millisecond)');
LEGEND_CONSTANTS(:,42) = strpad('k_minus_c in component ryanodine_receptors (per_millisecond)');
LEGEND_CONSTANTS(:,43) = strpad('m in component ryanodine_receptors (dimensionless)');
LEGEND_CONSTANTS(:,44) = strpad('n in component ryanodine_receptors (dimensionless)');
LEGEND_CONSTANTS(:,45) = strpad('E_CaL in component L_type_calcium_current (millivolt)');
LEGEND_CONSTANTS(:,46) = strpad('g_CaL in component L_type_calcium_current (milliS_per_microF)');
LEGEND_STATES(:,12) = strpad('O in component L_type_calcium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,3) = strpad('C1 in component L_type_calcium_current (dimensionless)');
LEGEND_STATES(:,13) = strpad('C2 in component L_type_calcium_current (dimensionless)');
LEGEND_STATES(:,14) = strpad('C3 in component L_type_calcium_current (dimensionless)');
LEGEND_STATES(:,15) = strpad('C4 in component L_type_calcium_current (dimensionless)');
LEGEND_STATES(:,16) = strpad('I1 in component L_type_calcium_current (dimensionless)');
LEGEND_STATES(:,17) = strpad('I2 in component L_type_calcium_current (dimensionless)');
LEGEND_STATES(:,18) = strpad('I3 in component L_type_calcium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,17) = strpad('alpha in component L_type_calcium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,32) = strpad('beta in component L_type_calcium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,37) = strpad('gamma in component L_type_calcium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,41) = strpad('Kpcf in component L_type_calcium_current (per_millisecond)');
LEGEND_CONSTANTS(:,47) = strpad('Kpcb in component L_type_calcium_current (per_millisecond)');
LEGEND_CONSTANTS(:,48) = strpad('Kpc_max in component L_type_calcium_current (per_millisecond)');
LEGEND_CONSTANTS(:,49) = strpad('Kpc_half in component L_type_calcium_current (micromolar)');
LEGEND_CONSTANTS(:,50) = strpad('E_CaT in component T_type_calcium_current (millivolt)');
LEGEND_CONSTANTS(:,51) = strpad('g_CaT in component T_type_calcium_current (milliS_per_microF)');
LEGEND_STATES(:,19) = strpad('b in component T_type_calcium_current_b_gate (dimensionless)');
LEGEND_STATES(:,20) = strpad('g in component T_type_calcium_current_g_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('b_infinity in component T_type_calcium_current_b_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,18) = strpad('tau_b in component T_type_calcium_current_b_gate (millisecond)');
LEGEND_ALGEBRAIC(:,5) = strpad('g_infinity in component T_type_calcium_current_g_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,19) = strpad('tau_g in component T_type_calcium_current_g_gate (millisecond)');
LEGEND_CONSTANTS(:,52) = strpad('i_pCa_max in component calcium_pump_current (picoA_per_picoF)');
LEGEND_CONSTANTS(:,53) = strpad('Km_pCa in component calcium_pump_current (micromolar)');
LEGEND_CONSTANTS(:,54) = strpad('k_NaCa in component sodium_calcium_exchange_current (picoA_per_picoF)');
LEGEND_CONSTANTS(:,55) = strpad('K_mNa in component sodium_calcium_exchange_current (micromolar)');
LEGEND_CONSTANTS(:,56) = strpad('K_mCa in component sodium_calcium_exchange_current (micromolar)');
LEGEND_CONSTANTS(:,57) = strpad('k_sat in component sodium_calcium_exchange_current (dimensionless)');
LEGEND_CONSTANTS(:,58) = strpad('eta in component sodium_calcium_exchange_current (dimensionless)');
LEGEND_STATES(:,21) = strpad('Nai in component sodium_concentration (micromolar)');
LEGEND_CONSTANTS(:,59) = strpad('g_Cab in component calcium_background_current (milliS_per_microF)');
LEGEND_ALGEBRAIC(:,51) = strpad('E_CaN in component calcium_background_current (millivolt)');
LEGEND_ALGEBRAIC(:,53) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,60) = strpad('g_Na in component fast_sodium_current (milliS_per_microF)');
LEGEND_STATES(:,22) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,23) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_STATES(:,24) = strpad('j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,6) = strpad('alpha_m in component fast_sodium_current_m_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,20) = strpad('beta_m in component fast_sodium_current_m_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,7) = strpad('alpha_h in component fast_sodium_current_h_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,21) = strpad('beta_h in component fast_sodium_current_h_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,8) = strpad('alpha_j in component fast_sodium_current_j_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,22) = strpad('beta_j in component fast_sodium_current_j_gate (per_millisecond)');
LEGEND_CONSTANTS(:,61) = strpad('g_Nab in component sodium_background_current (milliS_per_microF)');
LEGEND_STATES(:,25) = strpad('Ki in component potassium_concentration (micromolar)');
LEGEND_ALGEBRAIC(:,56) = strpad('E_K in component fast_transient_outward_potassium_current (millivolt)');
LEGEND_CONSTANTS(:,62) = strpad('g_Kto_f in component fast_transient_outward_potassium_current (milliS_per_microF)');
LEGEND_STATES(:,26) = strpad('ato_f in component fast_transient_outward_potassium_current (dimensionless)');
LEGEND_STATES(:,27) = strpad('ito_f in component fast_transient_outward_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,38) = strpad('ito_f_infinity in component fast_transient_outward_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,9) = strpad('tau_ito_f in component fast_transient_outward_potassium_current (millisecond)');
LEGEND_ALGEBRAIC(:,10) = strpad('alpha_a in component fast_transient_outward_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,24) = strpad('beta_a in component fast_transient_outward_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,23) = strpad('alpha_i in component fast_transient_outward_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,33) = strpad('beta_i in component fast_transient_outward_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,11) = strpad('ass in component ultra_rapidly_activating_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_CONSTANTS(:,63) = strpad('g_Kur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (milliS_per_microF)');
LEGEND_STATES(:,28) = strpad('aur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_STATES(:,29) = strpad('iur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,25) = strpad('tau_aur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (millisecond)');
LEGEND_ALGEBRAIC(:,26) = strpad('tau_iur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (millisecond)');
LEGEND_ALGEBRAIC(:,12) = strpad('iss in component ultra_rapidly_activating_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_CONSTANTS(:,65) = strpad('g_K1 in component time_independent_potassium_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,66) = strpad('g_Ks in component slow_delayed_rectifier_potassium_current (milliS_per_microF)');
LEGEND_STATES(:,31) = strpad('nKs in component slow_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,13) = strpad('alpha_n in component slow_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,28) = strpad('beta_n in component slow_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_CONSTANTS(:,67) = strpad('g_Kr in component rapid_delayed_rectifier_potassium_current (milliS_per_microF)');
LEGEND_STATES(:,32) = strpad('O_K in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_STATES(:,33) = strpad('C_K1 in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_STATES(:,34) = strpad('C_K2 in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,14) = strpad('C_K0 in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_STATES(:,35) = strpad('I_K in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_ALGEBRAIC(:,29) = strpad('alpha_a0 in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,34) = strpad('beta_a0 in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_CONSTANTS(:,68) = strpad('kb in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_CONSTANTS(:,69) = strpad('kf in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,15) = strpad('alpha_a1 in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,30) = strpad('beta_a1 in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,35) = strpad('alpha_i in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_ALGEBRAIC(:,39) = strpad('beta_i in component rapid_delayed_rectifier_potassium_current (per_millisecond)');
LEGEND_CONSTANTS(:,70) = strpad('i_NaK_max in component sodium_potassium_pump_current (picoA_per_picoF)');
LEGEND_CONSTANTS(:,71) = strpad('Km_Nai in component sodium_potassium_pump_current (micromolar)');
LEGEND_CONSTANTS(:,72) = strpad('Km_Ko in component sodium_potassium_pump_current (micromolar)');
LEGEND_ALGEBRAIC(:,63) = strpad('f_NaK in component sodium_potassium_pump_current (dimensionless)');
LEGEND_CONSTANTS(:,76) = strpad('sigma in component sodium_potassium_pump_current (dimensionless)');
LEGEND_CONSTANTS(:,73) = strpad('P_ClCa in component calcium_activated_chloride_current (cm_per_second)');
LEGEND_ALGEBRAIC(:,65) = strpad('f_ClCa in component calcium_activated_chloride_current (dimensionless)');
LEGEND_CONSTANTS(:,74) = strpad('Km_Cl in component calcium_activated_chloride_current (micromolar)');
LEGEND_CONSTANTS(:,75) = strpad('n_ClCa in component calcium_activated_chloride_current (dimensionless)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,2) = strpad('d/dt Cai in component calcium_concentration (micromolar)');
LEGEND_RATES(:,3) = strpad('d/dt Cass in component calcium_concentration (micromolar)');
LEGEND_RATES(:,4) = strpad('d/dt CaJSR in component calcium_concentration (micromolar)');
LEGEND_RATES(:,5) = strpad('d/dt CaNSR in component calcium_concentration (micromolar)');
LEGEND_RATES(:,6) = strpad('d/dt P_RyR in component calcium_fluxes (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt LTRPN_Ca in component calcium_buffering (micromolar)');
LEGEND_RATES(:,8) = strpad('d/dt HTRPN_Ca in component calcium_buffering (micromolar)');
LEGEND_RATES(:,9) = strpad('d/dt P_O1 in component ryanodine_receptors (dimensionless)');
LEGEND_RATES(:,10) = strpad('d/dt P_O2 in component ryanodine_receptors (dimensionless)');
LEGEND_RATES(:,11) = strpad('d/dt P_C2 in component ryanodine_receptors (dimensionless)');
LEGEND_RATES(:,12) = strpad('d/dt O in component L_type_calcium_current (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt C2 in component L_type_calcium_current (dimensionless)');
LEGEND_RATES(:,14) = strpad('d/dt C3 in component L_type_calcium_current (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt C4 in component L_type_calcium_current (dimensionless)');
LEGEND_RATES(:,16) = strpad('d/dt I1 in component L_type_calcium_current (dimensionless)');
LEGEND_RATES(:,17) = strpad('d/dt I2 in component L_type_calcium_current (dimensionless)');
LEGEND_RATES(:,18) = strpad('d/dt I3 in component L_type_calcium_current (dimensionless)');
LEGEND_RATES(:,19) = strpad('d/dt b in component T_type_calcium_current_b_gate (dimensionless)');
LEGEND_RATES(:,20) = strpad('d/dt g in component T_type_calcium_current_g_gate (dimensionless)');
LEGEND_RATES(:,21) = strpad('d/dt Nai in component sodium_concentration (micromolar)');
LEGEND_RATES(:,22) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,23) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,24) = strpad('d/dt j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_RATES(:,25) = strpad('d/dt Ki in component potassium_concentration (micromolar)');
LEGEND_RATES(:,26) = strpad('d/dt ato_f in component fast_transient_outward_potassium_current (dimensionless)');
LEGEND_RATES(:,27) = strpad('d/dt ito_f in component fast_transient_outward_potassium_current (dimensionless)');
LEGEND_RATES(:,28) = strpad('d/dt aur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_RATES(:,29) = strpad('d/dt iur in component ultra_rapidly_activating_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_RATES(:,31) = strpad('d/dt nKs in component slow_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_RATES(:,34) = strpad('d/dt C_K2 in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_RATES(:,33) = strpad('d/dt C_K1 in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_RATES(:,32) = strpad('d/dt O_K in component rapid_delayed_rectifier_potassium_current (dimensionless)');
LEGEND_RATES(:,35) = strpad('d/dt I_K in component rapid_delayed_rectifier_potassium_current (dimensionless)');
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) = -80.6475;
CONSTANTS(:,1) = 1;
CONSTANTS(:,2) = 2.2826e-6;
CONSTANTS(:,3) = 0.12e-8;
CONSTANTS(:,4) = 2.098e-7;
CONSTANTS(:,5) = 3.0734e-8;
CONSTANTS(:,6) = 1.5410e-5;
CONSTANTS(:,7) = 5400;
CONSTANTS(:,8) = 140000;
CONSTANTS(:,9) = 1000;
CONSTANTS(:,10) = 132000;
CONSTANTS(:,11) = 30000;
CONSTANTS(:,12) = 8.314;
CONSTANTS(:,13) = 298;
CONSTANTS(:,14) = 96.5;
CONSTANTS(:,15) = 20;
CONSTANTS(:,16) = 500000;
CONSTANTS(:,17) = 2000.0;
CONSTANTS(:,18) = 0.5;
CONSTANTS(:,19) = -80;
STATES(:,2) = 0.2049;
STATES(:,3) = 0.1867;
STATES(:,4) = 705.5417;
STATES(:,5) = 703.3063;
CONSTANTS(:,20) = 25;
CONSTANTS(:,21) = 15000;
CONSTANTS(:,22) = 0.238;
CONSTANTS(:,23) = 800;
CONSTANTS(:,24) = 0.00237;
CONSTANTS(:,25) = 3.2e-5;
CONSTANTS(:,26) = 0.0327;
CONSTANTS(:,27) = 0.0196;
STATES(:,6) = 2.8603e-14;
CONSTANTS(:,28) = 0.45;
CONSTANTS(:,29) = 20;
CONSTANTS(:,30) = 2.088e-5;
CONSTANTS(:,31) = 8;
CONSTANTS(:,32) = 0.09;
CONSTANTS(:,33) = 0.5;
CONSTANTS(:,34) = 35;
CONSTANTS(:,35) = 70;
STATES(:,7) = 8.9220;
STATES(:,8) = 66.0407;
CONSTANTS(:,36) = 7;
STATES(:,9) = 1.1e-3;
STATES(:,10) = 2.9799e-8;
STATES(:,11) = 0.1003;
CONSTANTS(:,37) = 0.00608;
CONSTANTS(:,38) = 0.07125;
CONSTANTS(:,39) = 0.00405;
CONSTANTS(:,40) = 0.965;
CONSTANTS(:,41) = 0.009;
CONSTANTS(:,42) = 0.0008;
CONSTANTS(:,43) = 3;
CONSTANTS(:,44) = 4;
CONSTANTS(:,45) = 63;
CONSTANTS(:,46) = 0.19019;
STATES(:,12) = 4.4776e-12;
STATES(:,13) = 1.6996e-4;
STATES(:,14) = 1.1754e-8;
STATES(:,15) = 6.1239e-10;
STATES(:,16) = 1.5450e-9;
STATES(:,17) = 6.4226e-8;
STATES(:,18) = 6.5201e-7;
CONSTANTS(:,47) = 0.0005;
CONSTANTS(:,48) = 0.23324;
CONSTANTS(:,49) = 20;
CONSTANTS(:,50) = 50;
CONSTANTS(:,51) = 0.055;
STATES(:,19) = 0.0047;
STATES(:,20) = 0.9020;
CONSTANTS(:,52) = 0.2;
CONSTANTS(:,53) = 0.5;
CONSTANTS(:,54) = 907.68;
CONSTANTS(:,55) = 87500;
CONSTANTS(:,56) = 1380;
CONSTANTS(:,57) = 0.1;
CONSTANTS(:,58) = 0.35;
STATES(:,21) = 2.1747e4;
CONSTANTS(:,59) = 0.00025;
CONSTANTS(:,60) = 10;
STATES(:,22) = 0.0032;
STATES(:,23) = 0.9606;
STATES(:,24) = 0.9744;
CONSTANTS(:,61) = 0.0026;
STATES(:,25) = 1.3645e5;
CONSTANTS(:,62) = 0.1017;
STATES(:,26) = 0.0032;
STATES(:,27) = 0.7530;
CONSTANTS(:,63) = 0.0048;
STATES(:,28) = 5.2471e-4;
STATES(:,29) = 0.9866;
CONSTANTS(:,64) = 0.015;
STATES(:,30) = 0.8500;
CONSTANTS(:,65) = 0.235;
CONSTANTS(:,66) = 0.046;
STATES(:,31) = 0.0026;
CONSTANTS(:,67) = 01.17;
STATES(:,32) = 2.1e-3;
STATES(:,33) = 1.1e-3;
STATES(:,34) = 8.3641e-4;
STATES(:,35) = 4.3522e-4;
CONSTANTS(:,68) = 0.036778;
CONSTANTS(:,69) = 0.023761;
CONSTANTS(:,70) = 0.88;
CONSTANTS(:,71) = 21000;
CONSTANTS(:,72) = 1500;
CONSTANTS(:,73) = 2.74e-7;
CONSTANTS(:,74) = 4;
CONSTANTS(:,75) = 3;
CONSTANTS(:,76) =  (1.00000./7.00000).*(exp(CONSTANTS(:,8)./67300.0) - 1.00000);
if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
global algebraicVariableCount;
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
ALGEBRAIC = zeros(1, algebraicVariableCount);
utilOnes = 1;
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
utilOnes = ones(statesRowCount, 1);
end
RATES(:,7) =  CONSTANTS(:,26).*STATES(:,2).*(CONSTANTS(:,34) - STATES(:,7)) -  CONSTANTS(:,27).*STATES(:,7);
RATES(:,8) =  CONSTANTS(:,24).*STATES(:,2).*(CONSTANTS(:,35) - STATES(:,8)) -  CONSTANTS(:,25).*STATES(:,8);
RATES(:,10) =  CONSTANTS(:,39).*power(STATES(:,3), CONSTANTS(:,43)).*STATES(:,9) -  CONSTANTS(:,40).*STATES(:,10);
RATES(:,11) =  CONSTANTS(:,41).*STATES(:,9) -  CONSTANTS(:,42).*STATES(:,11);
ALGEBRAIC(:,2) = 1.00000 - (STATES(:,11)+STATES(:,9)+STATES(:,10));
RATES(:,9) = ( CONSTANTS(:,37).*power(STATES(:,3), CONSTANTS(:,44)).*ALGEBRAIC(:,2)+ CONSTANTS(:,40).*STATES(:,10)+ CONSTANTS(:,42).*STATES(:,11)) - ( CONSTANTS(:,38).*STATES(:,9)+ CONSTANTS(:,39).*power(STATES(:,3), CONSTANTS(:,43)).*STATES(:,9)+ CONSTANTS(:,41).*STATES(:,9));
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp( - (STATES(:,1)+48.0000)./6.10000));
ALGEBRAIC(:,18) = 0.100000+5.40000./(1.00000+exp((STATES(:,1)+100.000)./6.60000));
RATES(:,19) = (ALGEBRAIC(:,4) - STATES(:,19))./ALGEBRAIC(:,18);
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+66.0000)./6.60000));
ALGEBRAIC(:,19) = 8.00000+32.0000./(1.00000+exp((STATES(:,1)+65.0000)./5.00000));
RATES(:,20) = (ALGEBRAIC(:,5) - STATES(:,20))./ALGEBRAIC(:,19);
ALGEBRAIC(:,6) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp( -0.100000.*(STATES(:,1)+47.1300)));
ALGEBRAIC(:,20) =  0.0800000.*exp( - STATES(:,1)./11.0000);
RATES(:,22) = ALGEBRAIC(:,6) -  (ALGEBRAIC(:,6)+ALGEBRAIC(:,20)).*STATES(:,22);
ALGEBRAIC(:,7) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
ALGEBRAIC(:,21) = piecewise({STATES(:,1)< - 40.0000,  3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
RATES(:,23) = ALGEBRAIC(:,7) -  (ALGEBRAIC(:,7)+ALGEBRAIC(:,21)).*STATES(:,23);
ALGEBRAIC(:,8) = piecewise({STATES(:,1)< - 40.0000, (  - ( 127140..*exp( 0.244400.*STATES(:,1))+ 3.47400e-05.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
ALGEBRAIC(:,22) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
RATES(:,24) = ALGEBRAIC(:,8) -  (ALGEBRAIC(:,8)+ALGEBRAIC(:,22)).*STATES(:,24);
ALGEBRAIC(:,10) =  0.180640.*exp( 0.0357700.*(STATES(:,1)+30.0000));
ALGEBRAIC(:,24) =  0.395600.*exp(  - 0.0623700.*(STATES(:,1)+30.0000));
RATES(:,26) =  ALGEBRAIC(:,10).*(1.00000 - STATES(:,26)) -  ALGEBRAIC(:,24).*STATES(:,26);
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp( - (STATES(:,1)+22.5000)./7.70000));
ALGEBRAIC(:,25) =  0.493000.*exp(  - 0.0629000.*STATES(:,1))+2.05800;
RATES(:,28) = (ALGEBRAIC(:,11) - STATES(:,28))./ALGEBRAIC(:,25);
ALGEBRAIC(:,26) = 1200.00 - 170.000./(1.00000+exp((STATES(:,1)+45.2000)./5.70000));
ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+45.2000)./5.70000));
RATES(:,29) = (ALGEBRAIC(:,12) - STATES(:,29))./ALGEBRAIC(:,26);
ALGEBRAIC(:,27) =  39.3000.*exp(  - 0.0862000.*STATES(:,1))+13.1700;
RATES(:,30) = (ALGEBRAIC(:,11) - STATES(:,30))./ALGEBRAIC(:,27);
ALGEBRAIC(:,13) = ( 4.81333e-06.*(STATES(:,1)+26.5000))./(1.00000 - exp(  - 0.128000.*(STATES(:,1)+26.5000)));
ALGEBRAIC(:,28) =  9.53333e-05.*exp(  - 0.0380000.*(STATES(:,1)+26.5000));
RATES(:,31) =  ALGEBRAIC(:,13).*(1.00000 - STATES(:,31)) -  ALGEBRAIC(:,28).*STATES(:,31);
ALGEBRAIC(:,15) =  0.0137330.*exp( 0.0381980.*STATES(:,1));
ALGEBRAIC(:,30) =  6.89000e-05.*exp(  - 0.0417800.*STATES(:,1));
RATES(:,34) = ( CONSTANTS(:,69).*STATES(:,33)+ ALGEBRAIC(:,30).*STATES(:,32)) - ( CONSTANTS(:,68).*STATES(:,34)+ ALGEBRAIC(:,15).*STATES(:,34));
ALGEBRAIC(:,3) = 1.00000 - (STATES(:,12)+STATES(:,13)+STATES(:,13)+STATES(:,14)+STATES(:,15)+STATES(:,16)+STATES(:,17)+STATES(:,18));
ALGEBRAIC(:,17) = ( 0.400000.*exp((STATES(:,1)+12.0000)./10.0000).*((1.00000+ 0.700000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./10.0000)) -  0.750000.*exp( - power(STATES(:,1)+20.0000, 2.00000)./400.000)))./(1.00000+ 0.120000.*exp((STATES(:,1)+12.0000)./10.0000));
ALGEBRAIC(:,32) =  0.0500000.*exp( - (STATES(:,1)+12.0000)./13.0000);
RATES(:,13) = ( 4.00000.*ALGEBRAIC(:,17).*ALGEBRAIC(:,3)+ 2.00000.*ALGEBRAIC(:,32).*STATES(:,14)) - ( ALGEBRAIC(:,32).*STATES(:,13)+ 3.00000.*ALGEBRAIC(:,17).*STATES(:,13));
RATES(:,14) = ( 3.00000.*ALGEBRAIC(:,17).*STATES(:,13)+ 3.00000.*ALGEBRAIC(:,32).*STATES(:,15)) - ( 2.00000.*ALGEBRAIC(:,32).*STATES(:,14)+ 2.00000.*ALGEBRAIC(:,17).*STATES(:,14));
ALGEBRAIC(:,14) = 1.00000 - (STATES(:,33)+STATES(:,34)+STATES(:,32)+STATES(:,35));
ALGEBRAIC(:,29) =  0.0223480.*exp( 0.0117600.*STATES(:,1));
ALGEBRAIC(:,34) =  0.0470020.*exp(  - 0.0631000.*STATES(:,1));
RATES(:,33) = ( ALGEBRAIC(:,29).*ALGEBRAIC(:,14)+ CONSTANTS(:,68).*STATES(:,34)) - ( ALGEBRAIC(:,34).*STATES(:,33)+ CONSTANTS(:,69).*STATES(:,33));
ALGEBRAIC(:,23) = ( 0.000152000.*exp( - (STATES(:,1) - 3.81000)./15.7500))./( 0.00670830.*exp( - (STATES(:,1)+132.050)./15.7500)+1.00000);
ALGEBRAIC(:,33) = ( 0.000950000.*exp((STATES(:,1)+132.050)./15.7500))./( 0.0513350.*exp((STATES(:,1)+132.050)./15.7500)+1.00000);
ALGEBRAIC(:,38) = ALGEBRAIC(:,23)./(ALGEBRAIC(:,23)+ALGEBRAIC(:,33));
ALGEBRAIC(:,9) = 1.00000./(( 0.000152000.*exp( - (STATES(:,1)+13.5000)./7.00000))./( 0.0670830.*exp( - (STATES(:,1)+33.5000)./7.00000)+1.00000)+( 0.000950000.*exp((STATES(:,1)+33.5000)./7.00000))./( 0.0513350.*exp((STATES(:,1)+33.5000)./7.00000)+1.00000));
RATES(:,27) = (ALGEBRAIC(:,38) - STATES(:,27))./ALGEBRAIC(:,9);
ALGEBRAIC(:,35) =  0.0908210.*exp( 0.0233910.*(STATES(:,1)+5.00000));
ALGEBRAIC(:,39) =  0.00649700.*exp(  - 0.0326800.*(STATES(:,1)+5.00000));
RATES(:,32) = ( ALGEBRAIC(:,15).*STATES(:,34)+ ALGEBRAIC(:,39).*STATES(:,35)) - ( ALGEBRAIC(:,30).*STATES(:,32)+ ALGEBRAIC(:,35).*STATES(:,32));
RATES(:,35) =  ALGEBRAIC(:,35).*STATES(:,32) -  ALGEBRAIC(:,39).*STATES(:,35);
ALGEBRAIC(:,37) = ( CONSTANTS(:,48).*STATES(:,3))./(CONSTANTS(:,49)+STATES(:,3));
ALGEBRAIC(:,41) =  13.0000.*(1.00000 - exp( - power(STATES(:,1)+14.5000, 2.00000)./100.000));
RATES(:,12) = ( ALGEBRAIC(:,17).*STATES(:,15)+ CONSTANTS(:,47).*STATES(:,16)+ 0.00100000.*( ALGEBRAIC(:,17).*STATES(:,17) -  ALGEBRAIC(:,41).*STATES(:,12))) - ( 4.00000.*ALGEBRAIC(:,32).*STATES(:,12)+ ALGEBRAIC(:,37).*STATES(:,12));
RATES(:,15) = ( 2.00000.*ALGEBRAIC(:,17).*STATES(:,14)+ 4.00000.*ALGEBRAIC(:,32).*STATES(:,12)+ 0.0100000.*( 4.00000.*CONSTANTS(:,47).*ALGEBRAIC(:,32).*STATES(:,16) -  ALGEBRAIC(:,17).*ALGEBRAIC(:,37).*STATES(:,15))+ 0.00200000.*( 4.00000.*ALGEBRAIC(:,32).*STATES(:,17) -  ALGEBRAIC(:,41).*STATES(:,15))+ 4.00000.*ALGEBRAIC(:,32).*CONSTANTS(:,47).*STATES(:,18)) - ( 3.00000.*ALGEBRAIC(:,32).*STATES(:,15)+ ALGEBRAIC(:,17).*STATES(:,15)+ 1.00000.*ALGEBRAIC(:,37).*ALGEBRAIC(:,41).*STATES(:,15));
RATES(:,16) = ( ALGEBRAIC(:,37).*STATES(:,12)+ 0.00100000.*( ALGEBRAIC(:,17).*STATES(:,18) -  ALGEBRAIC(:,41).*STATES(:,16))+ 0.0100000.*( ALGEBRAIC(:,17).*ALGEBRAIC(:,37).*STATES(:,15) -  4.00000.*ALGEBRAIC(:,32).*ALGEBRAIC(:,41).*STATES(:,16))) -  CONSTANTS(:,47).*STATES(:,16);
RATES(:,17) = ( 0.00100000.*( ALGEBRAIC(:,41).*STATES(:,12) -  ALGEBRAIC(:,17).*STATES(:,17))+ CONSTANTS(:,47).*STATES(:,18)+ 0.00200000.*( ALGEBRAIC(:,41).*STATES(:,15) -  4.00000.*ALGEBRAIC(:,32).*STATES(:,17))) -  ALGEBRAIC(:,37).*STATES(:,17);
RATES(:,18) = ( 0.00100000.*( ALGEBRAIC(:,41).*STATES(:,16) -  ALGEBRAIC(:,17).*STATES(:,18))+ ALGEBRAIC(:,37).*STATES(:,17)+ 1.00000.*ALGEBRAIC(:,37).*ALGEBRAIC(:,41).*STATES(:,15)) - ( 4.00000.*ALGEBRAIC(:,32).*CONSTANTS(:,47).*STATES(:,18)+ CONSTANTS(:,47).*STATES(:,18));
ALGEBRAIC(:,36) = power(1.00000+( CONSTANTS(:,21).*CONSTANTS(:,23))./power(CONSTANTS(:,23)+STATES(:,4), 2.00000),  - 1.00000);
ALGEBRAIC(:,40) =  CONSTANTS(:,28).*(STATES(:,9)+STATES(:,10)).*(STATES(:,4) - STATES(:,3)).*STATES(:,6);
ALGEBRAIC(:,43) = (STATES(:,3) - STATES(:,2))./CONSTANTS(:,31);
RATES(:,4) =  ALGEBRAIC(:,36).*(ALGEBRAIC(:,43) - ALGEBRAIC(:,40));
ALGEBRAIC(:,44) =  CONSTANTS(:,46).*STATES(:,12).*(STATES(:,1) - CONSTANTS(:,45));
RATES(:,6) =   - 0.0400000.*STATES(:,6) -  (( 0.100000.*ALGEBRAIC(:,44))./CONSTANTS(:,36)).*exp( - power(STATES(:,1) - 5.00000, 2.00000)./648.000);
ALGEBRAIC(:,45) =  CONSTANTS(:,30).*(STATES(:,5) - STATES(:,2));
ALGEBRAIC(:,47) = ( CONSTANTS(:,32).*power(STATES(:,2), 2.00000))./(power(CONSTANTS(:,33), 2.00000)+power(STATES(:,2), 2.00000));
ALGEBRAIC(:,42) = (STATES(:,5) - STATES(:,4))./CONSTANTS(:,29);
RATES(:,5) = ( (ALGEBRAIC(:,47) - ALGEBRAIC(:,45)).*CONSTANTS(:,2))./CONSTANTS(:,4) - ( ALGEBRAIC(:,42).*CONSTANTS(:,3))./CONSTANTS(:,4);
ALGEBRAIC(:,16) = power(1.00000+( CONSTANTS(:,20).*CONSTANTS(:,22))./power(CONSTANTS(:,22)+STATES(:,2), 2.00000),  - 1.00000);
ALGEBRAIC(:,49) = ( CONSTANTS(:,24).*STATES(:,2).*(CONSTANTS(:,35) - STATES(:,8))+ CONSTANTS(:,26).*STATES(:,2).*(CONSTANTS(:,34) - STATES(:,7))) - ( CONSTANTS(:,25).*STATES(:,8)+ CONSTANTS(:,27).*STATES(:,7));
RATES(:,2) =  ALGEBRAIC(:,16).*((ALGEBRAIC(:,45)+ALGEBRAIC(:,43)) - (ALGEBRAIC(:,47)+ALGEBRAIC(:,49)));
ALGEBRAIC(:,46) =  CONSTANTS(:,51).*STATES(:,19).*STATES(:,20).*(STATES(:,1) - CONSTANTS(:,50));
ALGEBRAIC(:,48) = ( CONSTANTS(:,52).*power(STATES(:,2), 2.00000))./(power(CONSTANTS(:,53), 2.00000)+power(STATES(:,2), 2.00000));
ALGEBRAIC(:,50) =  (( (( (( CONSTANTS(:,54).*1.00000)./(power(CONSTANTS(:,55), 3.00000)+power(CONSTANTS(:,8), 3.00000))).*1.00000)./(CONSTANTS(:,56)+CONSTANTS(:,9))).*1.00000)./(1.00000+ CONSTANTS(:,57).*exp(( (CONSTANTS(:,58) - 1.00000).*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))))).*( exp(( CONSTANTS(:,58).*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))).*power(STATES(:,21), 3.00000).*CONSTANTS(:,9) -  exp(( (CONSTANTS(:,58) - 1.00000).*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))).*power(CONSTANTS(:,8), 3.00000).*STATES(:,2));
ALGEBRAIC(:,51) =  (( CONSTANTS(:,12).*CONSTANTS(:,13))./( 2.00000.*CONSTANTS(:,14))).*log(CONSTANTS(:,9)./STATES(:,2));
ALGEBRAIC(:,52) =  CONSTANTS(:,59).*(STATES(:,1) - ALGEBRAIC(:,51));
ALGEBRAIC(:,31) = power(1.00000+( CONSTANTS(:,20).*CONSTANTS(:,22))./power(CONSTANTS(:,22)+STATES(:,3), 2.00000),  - 1.00000);
RATES(:,3) =  ALGEBRAIC(:,31).*(( ALGEBRAIC(:,40).*CONSTANTS(:,3))./CONSTANTS(:,5) - (( ALGEBRAIC(:,43).*CONSTANTS(:,2))./CONSTANTS(:,5)+ ((ALGEBRAIC(:,44)+ALGEBRAIC(:,52)+ALGEBRAIC(:,48)+ALGEBRAIC(:,46)) -  2.00000.*ALGEBRAIC(:,50)).*(( CONSTANTS(:,6).*CONSTANTS(:,1))./( 2.00000.*CONSTANTS(:,5).*CONSTANTS(:,14)))));
ALGEBRAIC(:,53) =  (( CONSTANTS(:,12).*CONSTANTS(:,13))./CONSTANTS(:,14)).*log(CONSTANTS(:,8)./STATES(:,21));
ALGEBRAIC(:,54) =  CONSTANTS(:,60).*power(STATES(:,22), 3.00000).*STATES(:,23).*STATES(:,24).*(STATES(:,1) - ALGEBRAIC(:,53));
ALGEBRAIC(:,55) =  CONSTANTS(:,61).*(STATES(:,1) - ALGEBRAIC(:,53));
ALGEBRAIC(:,63) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13)))+ 0.0365000.*CONSTANTS(:,76).*exp((  - STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))));
ALGEBRAIC(:,64) = ( (( CONSTANTS(:,70).*ALGEBRAIC(:,63).*1.00000)./(1.00000+power(CONSTANTS(:,71)./STATES(:,21), 1.50000))).*CONSTANTS(:,7))./(CONSTANTS(:,7)+CONSTANTS(:,72));
RATES(:,21) = (  - (ALGEBRAIC(:,54)+ALGEBRAIC(:,55)+ 3.00000.*ALGEBRAIC(:,64)+ 3.00000.*ALGEBRAIC(:,50)).*CONSTANTS(:,6).*CONSTANTS(:,1))./( CONSTANTS(:,2).*CONSTANTS(:,14));
ALGEBRAIC(:,56) =  (( CONSTANTS(:,12).*CONSTANTS(:,13))./CONSTANTS(:,14)).*log(CONSTANTS(:,7)./STATES(:,25));
ALGEBRAIC(:,57) =  CONSTANTS(:,62).*power(STATES(:,26), 6.50000).*STATES(:,27).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,60) =  CONSTANTS(:,65).*(CONSTANTS(:,7)./(CONSTANTS(:,7)+210.000)).*((STATES(:,1) - ALGEBRAIC(:,56))./(1.00000+exp( 0.0896000.*(STATES(:,1) - ALGEBRAIC(:,56)))));
ALGEBRAIC(:,61) =  CONSTANTS(:,66).*power(STATES(:,31), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,58) =  CONSTANTS(:,63).*STATES(:,28).*STATES(:,29).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,59) =  CONSTANTS(:,64).*STATES(:,30).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,62) =  CONSTANTS(:,67).*STATES(:,32).*(STATES(:,1) - ALGEBRAIC(:,56));
RATES(:,25) = (  - ((ALGEBRAIC(:,57)+ALGEBRAIC(:,60)+ALGEBRAIC(:,61)+ALGEBRAIC(:,59)+ALGEBRAIC(:,58)+ALGEBRAIC(:,62)) -  2.00000.*ALGEBRAIC(:,64)).*CONSTANTS(:,6).*CONSTANTS(:,1))./( CONSTANTS(:,2).*CONSTANTS(:,14));
ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,15)&VOI<=CONSTANTS(:,16)&(VOI - CONSTANTS(:,15)) -  floor((VOI - CONSTANTS(:,15))./CONSTANTS(:,17)).*CONSTANTS(:,17)<=CONSTANTS(:,18), CONSTANTS(:,19) }, 0.00000);
ALGEBRAIC(:,65) = power(STATES(:,3)./(CONSTANTS(:,74)+STATES(:,3)), CONSTANTS(:,75));
ALGEBRAIC(:,66) =  1.00000.*CONSTANTS(:,73).*ALGEBRAIC(:,65).*(( STATES(:,1).*power(CONSTANTS(:,14), 2.00000))./( CONSTANTS(:,12).*CONSTANTS(:,13))).*(( CONSTANTS(:,10).*exp(( STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))) - CONSTANTS(:,11))./(exp(( STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))) - 1.00000));
RATES(:,1) =  - (ALGEBRAIC(:,44)+ALGEBRAIC(:,46)+ALGEBRAIC(:,48)+ALGEBRAIC(:,50)+ALGEBRAIC(:,52)+ALGEBRAIC(:,54)+ALGEBRAIC(:,55)+ALGEBRAIC(:,64)+ALGEBRAIC(:,57)+ALGEBRAIC(:,60)+ALGEBRAIC(:,61)+ALGEBRAIC(:,58)+ALGEBRAIC(:,59)+ALGEBRAIC(:,62)+ALGEBRAIC(:,66)+ALGEBRAIC(:,1));
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
utilOnes = 1;
else
statesRowCount = statesSize(1);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,2) = 1.00000 - (STATES(:,11)+STATES(:,9)+STATES(:,10));
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp( - (STATES(:,1)+48.0000)./6.10000));
ALGEBRAIC(:,18) = 0.100000+5.40000./(1.00000+exp((STATES(:,1)+100.000)./6.60000));
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp((STATES(:,1)+66.0000)./6.60000));
ALGEBRAIC(:,19) = 8.00000+32.0000./(1.00000+exp((STATES(:,1)+65.0000)./5.00000));
ALGEBRAIC(:,6) = ( 0.320000.*(STATES(:,1)+47.1300))./(1.00000 - exp( -0.100000.*(STATES(:,1)+47.1300)));
ALGEBRAIC(:,20) =  0.0800000.*exp( - STATES(:,1)./11.0000);
ALGEBRAIC(:,7) = piecewise({STATES(:,1)< - 40.0000,  0.135000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
ALGEBRAIC(:,21) = piecewise({STATES(:,1)< - 40.0000,  3.56000.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1.00000./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
ALGEBRAIC(:,8) = piecewise({STATES(:,1)< - 40.0000, (  - ( 127140..*exp( 0.244400.*STATES(:,1))+ 3.47400e-05.*exp(  - 0.0439100.*STATES(:,1))).*(STATES(:,1)+37.7800))./(1.00000+exp( 0.311000.*(STATES(:,1)+79.2300))) }, 0.00000);
ALGEBRAIC(:,22) = piecewise({STATES(:,1)< - 40.0000, ( 0.121200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 0.300000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
ALGEBRAIC(:,10) =  0.180640.*exp( 0.0357700.*(STATES(:,1)+30.0000));
ALGEBRAIC(:,24) =  0.395600.*exp(  - 0.0623700.*(STATES(:,1)+30.0000));
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp( - (STATES(:,1)+22.5000)./7.70000));
ALGEBRAIC(:,25) =  0.493000.*exp(  - 0.0629000.*STATES(:,1))+2.05800;
ALGEBRAIC(:,26) = 1200.00 - 170.000./(1.00000+exp((STATES(:,1)+45.2000)./5.70000));
ALGEBRAIC(:,12) = 1.00000./(1.00000+exp((STATES(:,1)+45.2000)./5.70000));
ALGEBRAIC(:,27) =  39.3000.*exp(  - 0.0862000.*STATES(:,1))+13.1700;
ALGEBRAIC(:,13) = ( 4.81333e-06.*(STATES(:,1)+26.5000))./(1.00000 - exp(  - 0.128000.*(STATES(:,1)+26.5000)));
ALGEBRAIC(:,28) =  9.53333e-05.*exp(  - 0.0380000.*(STATES(:,1)+26.5000));
ALGEBRAIC(:,15) =  0.0137330.*exp( 0.0381980.*STATES(:,1));
ALGEBRAIC(:,30) =  6.89000e-05.*exp(  - 0.0417800.*STATES(:,1));
ALGEBRAIC(:,3) = 1.00000 - (STATES(:,12)+STATES(:,13)+STATES(:,13)+STATES(:,14)+STATES(:,15)+STATES(:,16)+STATES(:,17)+STATES(:,18));
ALGEBRAIC(:,17) = ( 0.400000.*exp((STATES(:,1)+12.0000)./10.0000).*((1.00000+ 0.700000.*exp( - power(STATES(:,1)+40.0000, 2.00000)./10.0000)) -  0.750000.*exp( - power(STATES(:,1)+20.0000, 2.00000)./400.000)))./(1.00000+ 0.120000.*exp((STATES(:,1)+12.0000)./10.0000));
ALGEBRAIC(:,32) =  0.0500000.*exp( - (STATES(:,1)+12.0000)./13.0000);
ALGEBRAIC(:,14) = 1.00000 - (STATES(:,33)+STATES(:,34)+STATES(:,32)+STATES(:,35));
ALGEBRAIC(:,29) =  0.0223480.*exp( 0.0117600.*STATES(:,1));
ALGEBRAIC(:,34) =  0.0470020.*exp(  - 0.0631000.*STATES(:,1));
ALGEBRAIC(:,23) = ( 0.000152000.*exp( - (STATES(:,1) - 3.81000)./15.7500))./( 0.00670830.*exp( - (STATES(:,1)+132.050)./15.7500)+1.00000);
ALGEBRAIC(:,33) = ( 0.000950000.*exp((STATES(:,1)+132.050)./15.7500))./( 0.0513350.*exp((STATES(:,1)+132.050)./15.7500)+1.00000);
ALGEBRAIC(:,38) = ALGEBRAIC(:,23)./(ALGEBRAIC(:,23)+ALGEBRAIC(:,33));
ALGEBRAIC(:,9) = 1.00000./(( 0.000152000.*exp( - (STATES(:,1)+13.5000)./7.00000))./( 0.0670830.*exp( - (STATES(:,1)+33.5000)./7.00000)+1.00000)+( 0.000950000.*exp((STATES(:,1)+33.5000)./7.00000))./( 0.0513350.*exp((STATES(:,1)+33.5000)./7.00000)+1.00000));
ALGEBRAIC(:,35) =  0.0908210.*exp( 0.0233910.*(STATES(:,1)+5.00000));
ALGEBRAIC(:,39) =  0.00649700.*exp(  - 0.0326800.*(STATES(:,1)+5.00000));
ALGEBRAIC(:,37) = ( CONSTANTS(:,48).*STATES(:,3))./(CONSTANTS(:,49)+STATES(:,3));
ALGEBRAIC(:,41) =  13.0000.*(1.00000 - exp( - power(STATES(:,1)+14.5000, 2.00000)./100.000));
ALGEBRAIC(:,36) = power(1.00000+( CONSTANTS(:,21).*CONSTANTS(:,23))./power(CONSTANTS(:,23)+STATES(:,4), 2.00000),  - 1.00000);
ALGEBRAIC(:,40) =  CONSTANTS(:,28).*(STATES(:,9)+STATES(:,10)).*(STATES(:,4) - STATES(:,3)).*STATES(:,6);
ALGEBRAIC(:,43) = (STATES(:,3) - STATES(:,2))./CONSTANTS(:,31);
ALGEBRAIC(:,44) =  CONSTANTS(:,46).*STATES(:,12).*(STATES(:,1) - CONSTANTS(:,45));
ALGEBRAIC(:,45) =  CONSTANTS(:,30).*(STATES(:,5) - STATES(:,2));
ALGEBRAIC(:,47) = ( CONSTANTS(:,32).*power(STATES(:,2), 2.00000))./(power(CONSTANTS(:,33), 2.00000)+power(STATES(:,2), 2.00000));
ALGEBRAIC(:,42) = (STATES(:,5) - STATES(:,4))./CONSTANTS(:,29);
ALGEBRAIC(:,16) = power(1.00000+( CONSTANTS(:,20).*CONSTANTS(:,22))./power(CONSTANTS(:,22)+STATES(:,2), 2.00000),  - 1.00000);
ALGEBRAIC(:,49) = ( CONSTANTS(:,24).*STATES(:,2).*(CONSTANTS(:,35) - STATES(:,8))+ CONSTANTS(:,26).*STATES(:,2).*(CONSTANTS(:,34) - STATES(:,7))) - ( CONSTANTS(:,25).*STATES(:,8)+ CONSTANTS(:,27).*STATES(:,7));
ALGEBRAIC(:,46) =  CONSTANTS(:,51).*STATES(:,19).*STATES(:,20).*(STATES(:,1) - CONSTANTS(:,50));
ALGEBRAIC(:,48) = ( CONSTANTS(:,52).*power(STATES(:,2), 2.00000))./(power(CONSTANTS(:,53), 2.00000)+power(STATES(:,2), 2.00000));
ALGEBRAIC(:,50) =  (( (( (( CONSTANTS(:,54).*1.00000)./(power(CONSTANTS(:,55), 3.00000)+power(CONSTANTS(:,8), 3.00000))).*1.00000)./(CONSTANTS(:,56)+CONSTANTS(:,9))).*1.00000)./(1.00000+ CONSTANTS(:,57).*exp(( (CONSTANTS(:,58) - 1.00000).*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))))).*( exp(( CONSTANTS(:,58).*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))).*power(STATES(:,21), 3.00000).*CONSTANTS(:,9) -  exp(( (CONSTANTS(:,58) - 1.00000).*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))).*power(CONSTANTS(:,8), 3.00000).*STATES(:,2));
ALGEBRAIC(:,51) =  (( CONSTANTS(:,12).*CONSTANTS(:,13))./( 2.00000.*CONSTANTS(:,14))).*log(CONSTANTS(:,9)./STATES(:,2));
ALGEBRAIC(:,52) =  CONSTANTS(:,59).*(STATES(:,1) - ALGEBRAIC(:,51));
ALGEBRAIC(:,31) = power(1.00000+( CONSTANTS(:,20).*CONSTANTS(:,22))./power(CONSTANTS(:,22)+STATES(:,3), 2.00000),  - 1.00000);
ALGEBRAIC(:,53) =  (( CONSTANTS(:,12).*CONSTANTS(:,13))./CONSTANTS(:,14)).*log(CONSTANTS(:,8)./STATES(:,21));
ALGEBRAIC(:,54) =  CONSTANTS(:,60).*power(STATES(:,22), 3.00000).*STATES(:,23).*STATES(:,24).*(STATES(:,1) - ALGEBRAIC(:,53));
ALGEBRAIC(:,55) =  CONSTANTS(:,61).*(STATES(:,1) - ALGEBRAIC(:,53));
ALGEBRAIC(:,63) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13)))+ 0.0365000.*CONSTANTS(:,76).*exp((  - STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))));
ALGEBRAIC(:,64) = ( (( CONSTANTS(:,70).*ALGEBRAIC(:,63).*1.00000)./(1.00000+power(CONSTANTS(:,71)./STATES(:,21), 1.50000))).*CONSTANTS(:,7))./(CONSTANTS(:,7)+CONSTANTS(:,72));
ALGEBRAIC(:,56) =  (( CONSTANTS(:,12).*CONSTANTS(:,13))./CONSTANTS(:,14)).*log(CONSTANTS(:,7)./STATES(:,25));
ALGEBRAIC(:,57) =  CONSTANTS(:,62).*power(STATES(:,26), 6.50000).*STATES(:,27).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,60) =  CONSTANTS(:,65).*(CONSTANTS(:,7)./(CONSTANTS(:,7)+210.000)).*((STATES(:,1) - ALGEBRAIC(:,56))./(1.00000+exp( 0.0896000.*(STATES(:,1) - ALGEBRAIC(:,56)))));
ALGEBRAIC(:,61) =  CONSTANTS(:,66).*power(STATES(:,31), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,58) =  CONSTANTS(:,63).*STATES(:,28).*STATES(:,29).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,59) =  CONSTANTS(:,64).*STATES(:,30).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,62) =  CONSTANTS(:,67).*STATES(:,32).*(STATES(:,1) - ALGEBRAIC(:,56));
ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,15)&VOI<=CONSTANTS(:,16)&(VOI - CONSTANTS(:,15)) -  floor((VOI - CONSTANTS(:,15))./CONSTANTS(:,17)).*CONSTANTS(:,17)<=CONSTANTS(:,18), CONSTANTS(:,19) }, 0.00000);
ALGEBRAIC(:,65) = power(STATES(:,3)./(CONSTANTS(:,74)+STATES(:,3)), CONSTANTS(:,75));
ALGEBRAIC(:,66) =  1.00000.*CONSTANTS(:,73).*ALGEBRAIC(:,65).*(( STATES(:,1).*power(CONSTANTS(:,14), 2.00000))./( CONSTANTS(:,12).*CONSTANTS(:,13))).*(( CONSTANTS(:,10).*exp(( STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))) - CONSTANTS(:,11))./(exp(( STATES(:,1).*CONSTANTS(:,14))./( CONSTANTS(:,12).*CONSTANTS(:,13))) - 1.00000));
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 Wang, Sobie, 2008 at changeset e46c3504eb74.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: