# 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 =60;
end
% There are a total of 33 entries in each of the rate and state variable arrays.
% There are a total of 79 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_mole_kelvin)');
LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_millimole)');
LEGEND_CONSTANTS(:,4) = strpad('C_sc in component membrane (microF_per_cm2)');
LEGEND_ALGEBRAIC(:,24) = strpad('i_Na in component fast_sodium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,46) = strpad('i_Ca in component L_type_Ca_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,49) = strpad('i_Ca_K in component L_type_Ca_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,30) = strpad('i_Kr in component rapid_activating_delayed_rectifiyer_K_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,32) = strpad('i_Ks in component slow_activating_delayed_rectifiyer_K_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,33) = strpad('i_to1 in component transient_outward_potassium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,35) = strpad('i_K1 in component time_independent_potassium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,37) = strpad('i_Kp in component plateau_potassium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,38) = strpad('i_NaCa in component Na_Ca_exchanger (microA_per_microF)');
LEGEND_ALGEBRAIC(:,40) = strpad('i_NaK in component sodium_potassium_pump (microA_per_microF)');
LEGEND_ALGEBRAIC(:,41) = strpad('i_p_Ca in component sarcolemmal_calcium_pump (microA_per_microF)');
LEGEND_ALGEBRAIC(:,43) = strpad('i_Ca_b in component calcium_background_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,44) = strpad('i_Na_b in component sodium_background_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,10) = strpad('i_Stim in component membrane (microA_per_microF)');
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 (microA_per_microF)');
LEGEND_ALGEBRAIC(:,20) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,10) = strpad('g_Na in component fast_sodium_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,11) = strpad('Nao in component standard_ionic_concentrations (millimolar)');
LEGEND_STATES(:,2) = strpad('Nai in component intracellular_ion_concentrations (millimolar)');
LEGEND_STATES(:,3) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,4) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_STATES(:,5) = strpad('j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,11) = strpad('alpha_m in component fast_sodium_current_m_gate (per_second)');
LEGEND_ALGEBRAIC(:,21) = strpad('beta_m in component fast_sodium_current_m_gate (per_second)');
LEGEND_ALGEBRAIC(:,1) = strpad('E0_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,2) = strpad('alpha_h in component fast_sodium_current_h_gate (per_second)');
LEGEND_ALGEBRAIC(:,12) = strpad('beta_h in component fast_sodium_current_h_gate (per_second)');
LEGEND_ALGEBRAIC(:,3) = strpad('alpha_j in component fast_sodium_current_j_gate (per_second)');
LEGEND_ALGEBRAIC(:,13) = strpad('beta_j in component fast_sodium_current_j_gate (per_second)');
LEGEND_ALGEBRAIC(:,27) = strpad('E_K in component rapid_activating_delayed_rectifiyer_K_current (millivolt)');
LEGEND_CONSTANTS(:,12) = strpad('g_Kr in component rapid_activating_delayed_rectifiyer_K_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,78) = strpad('f_Ko in component rapid_activating_delayed_rectifiyer_K_current (dimensionless)');
LEGEND_ALGEBRAIC(:,29) = strpad('R_V in component rapid_activating_delayed_rectifiyer_K_current (dimensionless)');
LEGEND_CONSTANTS(:,13) = strpad('Ko in component standard_ionic_concentrations (millimolar)');
LEGEND_STATES(:,6) = strpad('Ki in component intracellular_ion_concentrations (millimolar)');
LEGEND_STATES(:,7) = strpad('X_kr in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('K12 in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,14) = strpad('K21 in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,22) = strpad('X_kr_inf in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,25) = strpad('tau_X_kr in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (second)');
LEGEND_CONSTANTS(:,14) = strpad('tau_factor in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_CONSTANTS(:,15) = strpad('g_Ks in component slow_activating_delayed_rectifiyer_K_current (milliS_per_microF)');
LEGEND_ALGEBRAIC(:,31) = strpad('E_Ks in component slow_activating_delayed_rectifiyer_K_current (millivolt)');
LEGEND_STATES(:,8) = strpad('X_ks in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,15) = strpad('tau_X_ks in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (second)');
LEGEND_ALGEBRAIC(:,5) = strpad('X_ks_infinity in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (dimensionless)');
LEGEND_CONSTANTS(:,16) = strpad('g_to1 in component transient_outward_potassium_current (milliS_per_microF)');
LEGEND_STATES(:,9) = strpad('X_to1 in component transient_outward_potassium_current_X_to1_gate (dimensionless)');
LEGEND_STATES(:,10) = strpad('Y_to1 in component transient_outward_potassium_current_Y_to1_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,6) = strpad('alpha_X_to1 in component transient_outward_potassium_current_X_to1_gate (per_second)');
LEGEND_ALGEBRAIC(:,16) = strpad('beta_X_to1 in component transient_outward_potassium_current_X_to1_gate (per_second)');
LEGEND_ALGEBRAIC(:,7) = strpad('alpha_Y_to1 in component transient_outward_potassium_current_Y_to1_gate (per_second)');
LEGEND_ALGEBRAIC(:,17) = strpad('beta_Y_to1 in component transient_outward_potassium_current_Y_to1_gate (per_second)');
LEGEND_CONSTANTS(:,17) = strpad('g_K1 in component time_independent_potassium_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,18) = strpad('K_mK1 in component time_independent_potassium_current (millimolar)');
LEGEND_ALGEBRAIC(:,34) = strpad('K1_infinity_V in component time_independent_potassium_current_K1_gate (dimensionless)');
LEGEND_CONSTANTS(:,19) = strpad('g_Kp in component plateau_potassium_current (milliS_per_microF)');
LEGEND_ALGEBRAIC(:,36) = strpad('Kp_V in component plateau_potassium_current_Kp_gate (dimensionless)');
LEGEND_CONSTANTS(:,20) = strpad('K_mCa in component Na_Ca_exchanger (millimolar)');
LEGEND_CONSTANTS(:,21) = strpad('K_mNa in component Na_Ca_exchanger (millimolar)');
LEGEND_CONSTANTS(:,22) = strpad('K_NaCa in component Na_Ca_exchanger (microA_per_microF)');
LEGEND_CONSTANTS(:,23) = strpad('K_sat in component Na_Ca_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,24) = strpad('eta in component Na_Ca_exchanger (dimensionless)');
LEGEND_STATES(:,11) = strpad('Cai in component intracellular_ion_concentrations (millimolar)');
LEGEND_CONSTANTS(:,25) = strpad('Cao in component standard_ionic_concentrations (millimolar)');
LEGEND_CONSTANTS(:,26) = strpad('I_NaK in component sodium_potassium_pump (microA_per_microF)');
LEGEND_ALGEBRAIC(:,39) = strpad('f_NaK in component sodium_potassium_pump (dimensionless)');
LEGEND_CONSTANTS(:,27) = strpad('K_mNai in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,28) = strpad('K_mKo in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,79) = strpad('sigma in component sodium_potassium_pump (dimensionless)');
LEGEND_CONSTANTS(:,29) = strpad('K_mpCa in component sarcolemmal_calcium_pump (millimolar)');
LEGEND_CONSTANTS(:,30) = strpad('I_pCa in component sarcolemmal_calcium_pump (microA_per_microF)');
LEGEND_CONSTANTS(:,31) = strpad('g_Cab in component calcium_background_current (milliS_per_microF)');
LEGEND_ALGEBRAIC(:,42) = strpad('E_Ca in component calcium_background_current (millivolt)');
LEGEND_CONSTANTS(:,32) = strpad('g_Nab in component sodium_background_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,33) = strpad('P_Ca in component L_type_Ca_current (cm_per_second)');
LEGEND_CONSTANTS(:,34) = strpad('P_K in component L_type_Ca_current (cm_per_second)');
LEGEND_ALGEBRAIC(:,47) = strpad('p_prime_k in component L_type_Ca_current (cm_per_second)');
LEGEND_CONSTANTS(:,35) = strpad('i_Ca_half in component L_type_Ca_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,45) = strpad('i_Ca_max in component L_type_Ca_current (microA_per_microF)');
LEGEND_STATES(:,12) = strpad('O in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,13) = strpad('O_Ca in component L_type_Ca_current (dimensionless)');
LEGEND_ALGEBRAIC(:,8) = strpad('alpha in component L_type_Ca_current (per_second)');
LEGEND_ALGEBRAIC(:,18) = strpad('beta in component L_type_Ca_current (per_second)');
LEGEND_ALGEBRAIC(:,28) = strpad('gamma in component L_type_Ca_current (per_second)');
LEGEND_ALGEBRAIC(:,23) = strpad('alpha_a in component L_type_Ca_current (per_second)');
LEGEND_ALGEBRAIC(:,26) = strpad('beta_b in component L_type_Ca_current (per_second)');
LEGEND_CONSTANTS(:,36) = strpad('a in component L_type_Ca_current (dimensionless)');
LEGEND_CONSTANTS(:,37) = strpad('b in component L_type_Ca_current (dimensionless)');
LEGEND_CONSTANTS(:,38) = strpad('g in component L_type_Ca_current (per_second)');
LEGEND_CONSTANTS(:,39) = strpad('f in component L_type_Ca_current (per_second)');
LEGEND_CONSTANTS(:,40) = strpad('gprime in component L_type_Ca_current (per_second)');
LEGEND_CONSTANTS(:,41) = strpad('fprime in component L_type_Ca_current (per_second)');
LEGEND_CONSTANTS(:,42) = strpad('omega in component L_type_Ca_current (per_second)');
LEGEND_STATES(:,14) = strpad('C0 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,15) = strpad('C1 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,16) = strpad('C2 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,17) = strpad('C3 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,18) = strpad('C4 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,19) = strpad('C_Ca0 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,20) = strpad('C_Ca1 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,21) = strpad('C_Ca2 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,22) = strpad('C_Ca3 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,23) = strpad('C_Ca4 in component L_type_Ca_current (dimensionless)');
LEGEND_STATES(:,24) = strpad('Ca_ss in component intracellular_ion_concentrations (millimolar)');
LEGEND_STATES(:,25) = strpad('y in component L_type_Ca_current_y_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,9) = strpad('y_infinity in component L_type_Ca_current_y_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,19) = strpad('tau_y in component L_type_Ca_current_y_gate (second)');
LEGEND_ALGEBRAIC(:,48) = strpad('J_rel in component RyR_channel (millimolar_per_second)');
LEGEND_CONSTANTS(:,43) = strpad('v1 in component RyR_channel (per_second)');
LEGEND_CONSTANTS(:,44) = strpad('k_a_plus in component RyR_channel (millimolar4_per_second)');
LEGEND_CONSTANTS(:,45) = strpad('k_a_minus in component RyR_channel (per_second)');
LEGEND_CONSTANTS(:,46) = strpad('k_b_plus in component RyR_channel (millimolar3_per_second)');
LEGEND_CONSTANTS(:,47) = strpad('k_b_minus in component RyR_channel (per_second)');
LEGEND_CONSTANTS(:,48) = strpad('k_c_plus in component RyR_channel (per_second)');
LEGEND_CONSTANTS(:,49) = strpad('k_c_minus in component RyR_channel (per_second)');
LEGEND_STATES(:,26) = strpad('P_O1 in component RyR_channel (dimensionless)');
LEGEND_STATES(:,27) = strpad('P_O2 in component RyR_channel (dimensionless)');
LEGEND_STATES(:,28) = strpad('P_C1 in component RyR_channel (dimensionless)');
LEGEND_STATES(:,29) = strpad('P_C2 in component RyR_channel (dimensionless)');
LEGEND_CONSTANTS(:,50) = strpad('n in component RyR_channel (dimensionless)');
LEGEND_CONSTANTS(:,51) = strpad('m in component RyR_channel (dimensionless)');
LEGEND_STATES(:,30) = strpad('Ca_JSR in component intracellular_ion_concentrations (millimolar)');
LEGEND_ALGEBRAIC(:,52) = strpad('J_up in component SERCA2a_pump (millimolar_per_second)');
LEGEND_CONSTANTS(:,52) = strpad('K_fb in component SERCA2a_pump (millimolar)');
LEGEND_CONSTANTS(:,53) = strpad('K_rb in component SERCA2a_pump (millimolar)');
LEGEND_ALGEBRAIC(:,50) = strpad('fb in component SERCA2a_pump (dimensionless)');
LEGEND_ALGEBRAIC(:,51) = strpad('rb in component SERCA2a_pump (dimensionless)');
LEGEND_CONSTANTS(:,54) = strpad('Vmaxf in component SERCA2a_pump (millimolar_per_second)');
LEGEND_CONSTANTS(:,55) = strpad('Vmaxr in component SERCA2a_pump (millimolar_per_second)');
LEGEND_CONSTANTS(:,56) = strpad('K_SR in component SERCA2a_pump (dimensionless)');
LEGEND_CONSTANTS(:,57) = strpad('N_fb in component SERCA2a_pump (dimensionless)');
LEGEND_CONSTANTS(:,58) = strpad('N_rb in component SERCA2a_pump (dimensionless)');
LEGEND_STATES(:,31) = strpad('Ca_NSR in component intracellular_ion_concentrations (millimolar)');
LEGEND_ALGEBRAIC(:,54) = strpad('J_tr in component intracellular_Ca_fluxes (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,53) = strpad('J_xfer in component intracellular_Ca_fluxes (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,59) = strpad('J_trpn in component intracellular_Ca_fluxes (millimolar_per_second)');
LEGEND_CONSTANTS(:,59) = strpad('tau_tr in component intracellular_Ca_fluxes (second)');
LEGEND_CONSTANTS(:,60) = strpad('tau_xfer in component intracellular_Ca_fluxes (second)');
LEGEND_STATES(:,32) = strpad('HTRPNCa in component intracellular_Ca_fluxes (millimolar)');
LEGEND_STATES(:,33) = strpad('LTRPNCa in component intracellular_Ca_fluxes (millimolar)');
LEGEND_ALGEBRAIC(:,57) = strpad('J_HTRPNCa in component intracellular_Ca_fluxes (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,58) = strpad('J_LTRPNCa in component intracellular_Ca_fluxes (millimolar_per_second)');
LEGEND_CONSTANTS(:,61) = strpad('HTRPN_tot in component intracellular_Ca_fluxes (dimensionless)');
LEGEND_CONSTANTS(:,62) = strpad('LTRPN_tot in component intracellular_Ca_fluxes (dimensionless)');
LEGEND_CONSTANTS(:,63) = strpad('k_htrpn_plus in component intracellular_Ca_fluxes (per_millimolar_second)');
LEGEND_CONSTANTS(:,64) = strpad('k_htrpn_minus in component intracellular_Ca_fluxes (per_second)');
LEGEND_CONSTANTS(:,65) = strpad('k_ltrpn_plus in component intracellular_Ca_fluxes (per_millimolar_second)');
LEGEND_CONSTANTS(:,66) = strpad('k_ltrpn_minus in component intracellular_Ca_fluxes (per_second)');
LEGEND_CONSTANTS(:,67) = strpad('A_cap in component intracellular_ion_concentrations (cm2)');
LEGEND_CONSTANTS(:,68) = strpad('V_myo in component intracellular_ion_concentrations (micro_litre)');
LEGEND_CONSTANTS(:,69) = strpad('V_JSR in component intracellular_ion_concentrations (micro_litre)');
LEGEND_CONSTANTS(:,70) = strpad('V_NSR in component intracellular_ion_concentrations (micro_litre)');
LEGEND_CONSTANTS(:,71) = strpad('V_SS in component intracellular_ion_concentrations (micro_litre)');
LEGEND_CONSTANTS(:,72) = strpad('K_mCMDN in component intracellular_ion_concentrations (millimolar)');
LEGEND_CONSTANTS(:,73) = strpad('K_mEGTA in component intracellular_ion_concentrations (millimolar)');
LEGEND_CONSTANTS(:,74) = strpad('K_mCSQN in component intracellular_ion_concentrations (millimolar)');
LEGEND_CONSTANTS(:,75) = strpad('CMDN_tot in component intracellular_ion_concentrations (millimolar)');
LEGEND_CONSTANTS(:,76) = strpad('EGTA_tot in component intracellular_ion_concentrations (millimolar)');
LEGEND_CONSTANTS(:,77) = strpad('CSQN_tot in component intracellular_ion_concentrations (millimolar)');
LEGEND_ALGEBRAIC(:,60) = strpad('beta_i in component intracellular_ion_concentrations (dimensionless)');
LEGEND_ALGEBRAIC(:,55) = strpad('beta_SS in component intracellular_ion_concentrations (dimensionless)');
LEGEND_ALGEBRAIC(:,56) = strpad('beta_JSR in component intracellular_ion_concentrations (dimensionless)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,3) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,5) = strpad('d/dt j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt X_kr in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt X_ks in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt X_to1 in component transient_outward_potassium_current_X_to1_gate (dimensionless)');
LEGEND_RATES(:,10) = strpad('d/dt Y_to1 in component transient_outward_potassium_current_Y_to1_gate (dimensionless)');
LEGEND_RATES(:,14) = strpad('d/dt C0 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt C1 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,16) = strpad('d/dt C2 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,17) = strpad('d/dt C3 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,18) = strpad('d/dt C4 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,12) = strpad('d/dt O in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,19) = strpad('d/dt C_Ca0 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,20) = strpad('d/dt C_Ca1 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,21) = strpad('d/dt C_Ca2 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,22) = strpad('d/dt C_Ca3 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,23) = strpad('d/dt C_Ca4 in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt O_Ca in component L_type_Ca_current (dimensionless)');
LEGEND_RATES(:,25) = strpad('d/dt y in component L_type_Ca_current_y_gate (dimensionless)');
LEGEND_RATES(:,28) = strpad('d/dt P_C1 in component RyR_channel (dimensionless)');
LEGEND_RATES(:,26) = strpad('d/dt P_O1 in component RyR_channel (dimensionless)');
LEGEND_RATES(:,27) = strpad('d/dt P_O2 in component RyR_channel (dimensionless)');
LEGEND_RATES(:,29) = strpad('d/dt P_C2 in component RyR_channel (dimensionless)');
LEGEND_RATES(:,32) = strpad('d/dt HTRPNCa in component intracellular_Ca_fluxes (millimolar)');
LEGEND_RATES(:,33) = strpad('d/dt LTRPNCa in component intracellular_Ca_fluxes (millimolar)');
LEGEND_RATES(:,11) = strpad('d/dt Cai in component intracellular_ion_concentrations (millimolar)');
LEGEND_RATES(:,2) = strpad('d/dt Nai in component intracellular_ion_concentrations (millimolar)');
LEGEND_RATES(:,6) = strpad('d/dt Ki in component intracellular_ion_concentrations (millimolar)');
LEGEND_RATES(:,24) = strpad('d/dt Ca_ss in component intracellular_ion_concentrations (millimolar)');
LEGEND_RATES(:,30) = strpad('d/dt Ca_JSR in component intracellular_ion_concentrations (millimolar)');
LEGEND_RATES(:,31) = strpad('d/dt Ca_NSR in component intracellular_ion_concentrations (millimolar)');
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) = -96.1638;
CONSTANTS(:,1) = 8.314472;
CONSTANTS(:,2) = 310;
CONSTANTS(:,3) = 96.4853415;
CONSTANTS(:,4) = 0.001;
CONSTANTS(:,5) = 0.1;
CONSTANTS(:,6) = 100000000;
CONSTANTS(:,7) = 1;
CONSTANTS(:,8) = 0.002;
CONSTANTS(:,9) = -21.1268;
CONSTANTS(:,10) = 12.8;
CONSTANTS(:,11) = 138;
STATES(:,2) = 10;
STATES(:,3) = 0.0328302;
STATES(:,4) = 0.988354;
STATES(:,5) = 0.99254;
CONSTANTS(:,12) = 0.0034;
CONSTANTS(:,13) = 4;
STATES(:,6) = 157.8;
STATES(:,7) = 0.51;
CONSTANTS(:,14) = 1;
CONSTANTS(:,15) = 0.0027134;
STATES(:,8) = 0.264;
CONSTANTS(:,16) = 0.23815;
STATES(:,9) = 2.63;
STATES(:,10) = 0.99;
CONSTANTS(:,17) = 2.8;
CONSTANTS(:,18) = 13;
CONSTANTS(:,19) = 0.002216;
CONSTANTS(:,20) = 1.38;
CONSTANTS(:,21) = 87.5;
CONSTANTS(:,22) = 0.3;
CONSTANTS(:,23) = 0.2;
CONSTANTS(:,24) = 0.35;
STATES(:,11) = 0.00008;
CONSTANTS(:,25) = 2;
CONSTANTS(:,26) = 0.693;
CONSTANTS(:,27) = 10;
CONSTANTS(:,28) = 1.5;
CONSTANTS(:,29) = 0.00005;
CONSTANTS(:,30) = 0.05;
CONSTANTS(:,31) = 0.0003842;
CONSTANTS(:,32) = 0.0031;
CONSTANTS(:,33) = 3.125e-4;
CONSTANTS(:,34) = 5.79e-7;
CONSTANTS(:,35) = -0.265;
STATES(:,12) = 9.84546e-21;
STATES(:,13) = 0;
CONSTANTS(:,36) = 2;
CONSTANTS(:,37) = 2;
CONSTANTS(:,38) = 2000;
CONSTANTS(:,39) = 300;
CONSTANTS(:,40) = 7000;
CONSTANTS(:,41) = 7;
CONSTANTS(:,42) = 10;
STATES(:,14) = 0.997208;
STATES(:,15) = 6.38897e-5;
STATES(:,16) = 1.535e-9;
STATES(:,17) = 1.63909e-14;
STATES(:,18) = 6.56337e-20;
STATES(:,19) = 0.00272826;
STATES(:,20) = 6.99215e-7;
STATES(:,21) = 6.71989e-11;
STATES(:,22) = 2.87031e-15;
STATES(:,23) = 4.59752e-20;
STATES(:,24) = 0.00011;
STATES(:,25) = 0.798;
CONSTANTS(:,43) = 1800;
CONSTANTS(:,44) = 1.215e13;
CONSTANTS(:,45) = 576;
CONSTANTS(:,46) = 4.05e9;
CONSTANTS(:,47) = 1930;
CONSTANTS(:,48) = 100;
CONSTANTS(:,49) = 0.8;
STATES(:,26) = 0;
STATES(:,27) = 0;
STATES(:,28) = 0.47;
STATES(:,29) = 0.53;
CONSTANTS(:,50) = 4;
CONSTANTS(:,51) = 3;
STATES(:,30) = 0.257;
CONSTANTS(:,52) = 0.000168;
CONSTANTS(:,53) = 3.29;
CONSTANTS(:,54) = 0.0813;
CONSTANTS(:,55) = 0.318;
CONSTANTS(:,56) = 1;
CONSTANTS(:,57) = 1.2;
CONSTANTS(:,58) = 1;
STATES(:,31) = 0.257;
CONSTANTS(:,59) = 0.0005747;
CONSTANTS(:,60) = 0.0267;
STATES(:,32) = 0.98;
STATES(:,33) = 0.078;
CONSTANTS(:,61) = 0.14;
CONSTANTS(:,62) = 0.07;
CONSTANTS(:,63) = 20000;
CONSTANTS(:,64) = 0.066;
CONSTANTS(:,65) = 40000;
CONSTANTS(:,66) = 40;
CONSTANTS(:,67) = 0.0001534;
CONSTANTS(:,68) = 0.00002584;
CONSTANTS(:,69) = 0.00000016;
CONSTANTS(:,70) = 0.0000021;
CONSTANTS(:,71) = 0.0000000012;
CONSTANTS(:,72) = 0.00238;
CONSTANTS(:,73) = 0.00015;
CONSTANTS(:,74) = 0.8;
CONSTANTS(:,75) = 0.05;
CONSTANTS(:,76) = 0;
CONSTANTS(:,77) = 15;
CONSTANTS(:,78) = power((CONSTANTS(:,13)./4.00000), 1.0 ./ 2);
CONSTANTS(:,79) =  (1.00000./7.00000).*(exp(CONSTANTS(:,11)./67.3000) - 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(:,12) =  CONSTANTS(:,39).*STATES(:,18) -  CONSTANTS(:,38).*STATES(:,12);
RATES(:,13) =  CONSTANTS(:,41).*STATES(:,23) -  CONSTANTS(:,40).*STATES(:,13);
RATES(:,28) =   - CONSTANTS(:,44).*power(STATES(:,24), CONSTANTS(:,50)).*STATES(:,28)+ CONSTANTS(:,45).*STATES(:,26);
RATES(:,26) = ( CONSTANTS(:,44).*power(STATES(:,24), CONSTANTS(:,50)).*STATES(:,28) - ( CONSTANTS(:,45).*STATES(:,26)+ CONSTANTS(:,46).*power(STATES(:,24), CONSTANTS(:,51)).*STATES(:,26)+ CONSTANTS(:,48).*STATES(:,26)))+ CONSTANTS(:,47).*STATES(:,27)+ CONSTANTS(:,49).*STATES(:,29);
RATES(:,27) =  CONSTANTS(:,46).*power(STATES(:,24), CONSTANTS(:,51)).*STATES(:,26) -  CONSTANTS(:,47).*STATES(:,27);
RATES(:,29) =  CONSTANTS(:,48).*STATES(:,26) -  CONSTANTS(:,49).*STATES(:,29);
ALGEBRAIC(:,2) = piecewise({STATES(:,1)< - 40.0000,  135.000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
ALGEBRAIC(:,12) = piecewise({STATES(:,1)< - 40.0000,  3560.00.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1000.00./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
RATES(:,4) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,4)) -  ALGEBRAIC(:,12).*STATES(:,4);
ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000, ( 1000.00.* - ( 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(:,13) = piecewise({STATES(:,1)< - 40.0000, ( 121.200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 300.000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
RATES(:,5) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,13).*STATES(:,5);
ALGEBRAIC(:,15) = 0.00100000./(( 7.19000e-05.*(STATES(:,1) - 10.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1) - 10.0000)))+( 0.000131000.*(STATES(:,1) - 10.0000))./(exp( 0.0687000.*(STATES(:,1) - 10.0000)) - 1.00000));
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1) - 24.7000)./13.6000));
RATES(:,8) = (ALGEBRAIC(:,5) - STATES(:,8))./ALGEBRAIC(:,15);
ALGEBRAIC(:,6) =  45.1600.*exp( 0.0357700.*STATES(:,1));
ALGEBRAIC(:,16) =  98.9000.*exp(  - 0.0623700.*STATES(:,1));
RATES(:,9) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,9)) -  ALGEBRAIC(:,16).*STATES(:,9);
ALGEBRAIC(:,7) = ( 5.41500.*exp( - (STATES(:,1)+33.5000)./5.00000))./(1.00000+ 0.0513350.*exp( - (STATES(:,1)+33.5000)./5.00000));
ALGEBRAIC(:,17) = ( 5.41500.*exp((STATES(:,1)+33.5000)./5.00000))./(1.00000+ 0.0513350.*exp((STATES(:,1)+33.5000)./5.00000));
RATES(:,10) =  ALGEBRAIC(:,7).*(1.00000 - STATES(:,10)) -  ALGEBRAIC(:,17).*STATES(:,10);
ALGEBRAIC(:,9) = 0.800000./(1.00000+exp((STATES(:,1)+12.5000)./5.00000))+0.200000;
ALGEBRAIC(:,19) = (20.0000+600.000./(1.00000+exp((STATES(:,1)+20.0000)./9.50000)))./1000.00;
RATES(:,25) = (ALGEBRAIC(:,9) - STATES(:,25))./ALGEBRAIC(:,19);
ALGEBRAIC(:,1) = STATES(:,1)+47.1300;
ALGEBRAIC(:,11) = piecewise({abs(ALGEBRAIC(:,1))<1.00000e-05, 1000.00./(0.100000 -  0.00500000.*ALGEBRAIC(:,1)) }, ( 320.000.*ALGEBRAIC(:,1))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,1))));
ALGEBRAIC(:,21) =  80.0000.*exp( - STATES(:,1)./11.0000);
RATES(:,3) = piecewise({STATES(:,1)>= - 90.0000,  ALGEBRAIC(:,11).*(1.00000 - STATES(:,3)) -  ALGEBRAIC(:,21).*STATES(:,3) }, 0.00000);
ALGEBRAIC(:,4) = exp( - 5.49500+ 0.169100.*STATES(:,1));
ALGEBRAIC(:,14) = exp( - 7.67700 -  0.0128000.*STATES(:,1));
ALGEBRAIC(:,22) = ALGEBRAIC(:,4)./(ALGEBRAIC(:,4)+ALGEBRAIC(:,14));
ALGEBRAIC(:,25) = 0.00100000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,14))+ CONSTANTS(:,14).*0.0270000;
RATES(:,7) = (ALGEBRAIC(:,22) - STATES(:,7))./ALGEBRAIC(:,25);
ALGEBRAIC(:,8) =  400.000.*exp((STATES(:,1)+2.00000)./10.0000);
ALGEBRAIC(:,18) =  50.0000.*exp( - (STATES(:,1)+2.00000)./13.0000);
ALGEBRAIC(:,28) = ( 103.750.*STATES(:,24))./1.00000;
RATES(:,14) = ( ALGEBRAIC(:,18).*STATES(:,15)+ CONSTANTS(:,42).*STATES(:,19)) -  ( 4.00000.*ALGEBRAIC(:,8)+ALGEBRAIC(:,28)).*STATES(:,14);
RATES(:,15) = ( 4.00000.*ALGEBRAIC(:,8).*STATES(:,14)+ 2.00000.*ALGEBRAIC(:,18).*STATES(:,16)+ (CONSTANTS(:,42)./CONSTANTS(:,37)).*STATES(:,20)) -  (ALGEBRAIC(:,18)+ 3.00000.*ALGEBRAIC(:,8)+ ALGEBRAIC(:,28).*CONSTANTS(:,36)).*STATES(:,15);
RATES(:,16) = ( 3.00000.*ALGEBRAIC(:,8).*STATES(:,15)+ 3.00000.*ALGEBRAIC(:,18).*STATES(:,17)+ (CONSTANTS(:,42)./power(CONSTANTS(:,37), 2.00000)).*STATES(:,21)) -  ( ALGEBRAIC(:,18).*2.00000+ 2.00000.*ALGEBRAIC(:,8)+ ALGEBRAIC(:,28).*power(CONSTANTS(:,36), 2.00000)).*STATES(:,16);
RATES(:,17) = ( 2.00000.*ALGEBRAIC(:,8).*STATES(:,16)+ 4.00000.*ALGEBRAIC(:,18).*STATES(:,18)+ (CONSTANTS(:,42)./power(CONSTANTS(:,37), 3.00000)).*STATES(:,22)) -  ( ALGEBRAIC(:,18).*3.00000+ALGEBRAIC(:,8)+ ALGEBRAIC(:,28).*power(CONSTANTS(:,36), 3.00000)).*STATES(:,17);
RATES(:,18) = ( ALGEBRAIC(:,8).*STATES(:,17)+ CONSTANTS(:,38).*STATES(:,12)+ (CONSTANTS(:,42)./power(CONSTANTS(:,37), 4.00000)).*STATES(:,23)) -  ( ALGEBRAIC(:,18).*4.00000+CONSTANTS(:,39)+ ALGEBRAIC(:,28).*power(CONSTANTS(:,36), 4.00000)).*STATES(:,18);
ALGEBRAIC(:,23) =  ALGEBRAIC(:,8).*CONSTANTS(:,36);
ALGEBRAIC(:,26) = ALGEBRAIC(:,18)./CONSTANTS(:,37);
RATES(:,19) = ( ALGEBRAIC(:,26).*STATES(:,20)+ ALGEBRAIC(:,28).*STATES(:,14)) -  ( 4.00000.*ALGEBRAIC(:,23)+CONSTANTS(:,42)).*STATES(:,19);
RATES(:,20) = ( 4.00000.*ALGEBRAIC(:,23).*STATES(:,19)+ 2.00000.*ALGEBRAIC(:,26).*STATES(:,21)+ ALGEBRAIC(:,28).*CONSTANTS(:,36).*STATES(:,15)) -  (ALGEBRAIC(:,26)+ 3.00000.*ALGEBRAIC(:,23)+CONSTANTS(:,42)./CONSTANTS(:,37)).*STATES(:,20);
RATES(:,21) = ( 3.00000.*ALGEBRAIC(:,23).*STATES(:,20)+ 3.00000.*ALGEBRAIC(:,26).*STATES(:,22)+ ALGEBRAIC(:,28).*power(CONSTANTS(:,36), 2.00000).*STATES(:,16)) -  ( ALGEBRAIC(:,26).*2.00000+ 2.00000.*ALGEBRAIC(:,23)+CONSTANTS(:,42)./power(CONSTANTS(:,37), 2.00000)).*STATES(:,21);
RATES(:,22) = ( 2.00000.*ALGEBRAIC(:,23).*STATES(:,21)+ 4.00000.*ALGEBRAIC(:,26).*STATES(:,23)+ ALGEBRAIC(:,28).*power(CONSTANTS(:,36), 3.00000).*STATES(:,17)) -  ( ALGEBRAIC(:,26).*3.00000+ALGEBRAIC(:,23)+CONSTANTS(:,42)./power(CONSTANTS(:,37), 3.00000)).*STATES(:,22);
RATES(:,23) = ( ALGEBRAIC(:,23).*STATES(:,22)+ CONSTANTS(:,40).*STATES(:,13)+ ALGEBRAIC(:,28).*power(CONSTANTS(:,36), 4.00000).*STATES(:,18)) -  ( ALGEBRAIC(:,26).*4.00000+CONSTANTS(:,41)+CONSTANTS(:,42)./power(CONSTANTS(:,37), 4.00000)).*STATES(:,23);
ALGEBRAIC(:,20) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
ALGEBRAIC(:,24) =  CONSTANTS(:,10).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,20));
ALGEBRAIC(:,38) =  (( CONSTANTS(:,22).*5000.00)./( (power(CONSTANTS(:,21), 3.00000)+power(CONSTANTS(:,11), 3.00000)).*(CONSTANTS(:,20)+CONSTANTS(:,25)).*(1.00000+ CONSTANTS(:,23).*exp(( (CONSTANTS(:,24) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( exp(( CONSTANTS(:,24).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,25) -  exp(( (CONSTANTS(:,24) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,11), 3.00000).*STATES(:,11));
ALGEBRAIC(:,39) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,79).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,40) = ( (( CONSTANTS(:,26).*ALGEBRAIC(:,39))./(1.00000+power(CONSTANTS(:,27)./STATES(:,2), 1.50000))).*CONSTANTS(:,13))./(CONSTANTS(:,13)+CONSTANTS(:,28));
ALGEBRAIC(:,44) =  CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,20));
RATES(:,2) = (  - 0.00000.*(ALGEBRAIC(:,24)+ALGEBRAIC(:,44)+ ALGEBRAIC(:,38).*3.00000+ ALGEBRAIC(:,40).*3.00000).*CONSTANTS(:,67).*1.00000)./( CONSTANTS(:,68).*CONSTANTS(:,3));
ALGEBRAIC(:,45) = ( (( (CONSTANTS(:,33)./( 1.00000.*1.00000)).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000).*1000.00)./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.00100000.*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,25)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,46) =  ALGEBRAIC(:,45).*STATES(:,25).*(STATES(:,12)+STATES(:,13));
ALGEBRAIC(:,47) = CONSTANTS(:,34)./(1.00000+ALGEBRAIC(:,45)./CONSTANTS(:,35));
ALGEBRAIC(:,49) = ( (( (ALGEBRAIC(:,47)./( 1.00000.*1.00000)).*STATES(:,25).*(STATES(:,12)+STATES(:,13)).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,6).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,13)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,27) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,13)./STATES(:,6));
ALGEBRAIC(:,29) = 1.00000./(1.00000+ 1.49450.*exp( 0.0446000.*STATES(:,1)));
ALGEBRAIC(:,30) =  CONSTANTS(:,12).*CONSTANTS(:,78).*ALGEBRAIC(:,29).*STATES(:,7).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,31) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,13)+ 0.0183300.*CONSTANTS(:,11))./(STATES(:,6)+ 0.0183300.*STATES(:,2)));
ALGEBRAIC(:,32) =  CONSTANTS(:,15).*power(STATES(:,8), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,31));
ALGEBRAIC(:,33) =  CONSTANTS(:,16).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,34) = 1.00000./(2.00000+exp( (( 1.50000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,1) - ALGEBRAIC(:,27))));
ALGEBRAIC(:,35) =  (( CONSTANTS(:,17).*ALGEBRAIC(:,34).*CONSTANTS(:,13))./(CONSTANTS(:,13)+CONSTANTS(:,18))).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,36) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
ALGEBRAIC(:,37) =  CONSTANTS(:,19).*ALGEBRAIC(:,36).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,41) = ( CONSTANTS(:,30).*STATES(:,11))./(CONSTANTS(:,29)+STATES(:,11));
ALGEBRAIC(:,42) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,25)./STATES(:,11));
ALGEBRAIC(:,43) =  CONSTANTS(:,31).*(STATES(:,1) - ALGEBRAIC(:,42));
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.*1.00000.*(ALGEBRAIC(:,24)+ALGEBRAIC(:,46)+ALGEBRAIC(:,49)+ALGEBRAIC(:,30)+ALGEBRAIC(:,32)+ALGEBRAIC(:,33)+ALGEBRAIC(:,35)+ALGEBRAIC(:,37)+ALGEBRAIC(:,38)+ALGEBRAIC(:,40)+ALGEBRAIC(:,41)+ALGEBRAIC(:,44)+ALGEBRAIC(:,43)+ALGEBRAIC(:,10)))./CONSTANTS(:,4);
RATES(:,6) = (  - 0.00000.*(ALGEBRAIC(:,49)+ALGEBRAIC(:,30)+ALGEBRAIC(:,32)+ALGEBRAIC(:,35)+ALGEBRAIC(:,37)+ALGEBRAIC(:,33)+ ALGEBRAIC(:,40).* - 2.00000).*CONSTANTS(:,67).*1.00000)./( CONSTANTS(:,68).*CONSTANTS(:,3));
RATES(:,32) =  CONSTANTS(:,63).*STATES(:,11).*(1.00000 - STATES(:,32)) -  CONSTANTS(:,64).*STATES(:,32);
ALGEBRAIC(:,50) = power(STATES(:,11)./CONSTANTS(:,52), CONSTANTS(:,57));
ALGEBRAIC(:,51) = power(STATES(:,31)./CONSTANTS(:,53), CONSTANTS(:,58));
ALGEBRAIC(:,52) = ( CONSTANTS(:,56).*( CONSTANTS(:,54).*ALGEBRAIC(:,50) -  CONSTANTS(:,55).*ALGEBRAIC(:,51)))./(1.00000+ALGEBRAIC(:,50)+ALGEBRAIC(:,51));
ALGEBRAIC(:,54) = (STATES(:,31) - STATES(:,30))./CONSTANTS(:,59);
RATES(:,31) = ( ALGEBRAIC(:,52).*CONSTANTS(:,68))./CONSTANTS(:,70) - ( ALGEBRAIC(:,54).*CONSTANTS(:,69))./CONSTANTS(:,70);
ALGEBRAIC(:,48) =  CONSTANTS(:,43).*(STATES(:,26)+STATES(:,27)).*(STATES(:,30) - STATES(:,24));
ALGEBRAIC(:,53) = (STATES(:,24) - STATES(:,11))./CONSTANTS(:,60);
ALGEBRAIC(:,55) = 1.00000./(1.00000+( CONSTANTS(:,75).*CONSTANTS(:,72))./power(CONSTANTS(:,72)+STATES(:,24), 2.00000)+( CONSTANTS(:,76).*CONSTANTS(:,73))./power(CONSTANTS(:,73)+STATES(:,24), 2.00000));
RATES(:,24) =  ALGEBRAIC(:,55).*((( ALGEBRAIC(:,48).*CONSTANTS(:,69))./CONSTANTS(:,71) - ( ALGEBRAIC(:,53).*CONSTANTS(:,68))./CONSTANTS(:,71)) - ( ALGEBRAIC(:,46).*CONSTANTS(:,67).*1.00000)./( 2.00000.*CONSTANTS(:,71).*CONSTANTS(:,3)));
ALGEBRAIC(:,56) = 1.00000./(1.00000+( CONSTANTS(:,77).*CONSTANTS(:,74))./power(CONSTANTS(:,74)+STATES(:,30), 2.00000));
RATES(:,30) =  ALGEBRAIC(:,56).*(ALGEBRAIC(:,54) - ALGEBRAIC(:,48));
RATES(:,33) =  CONSTANTS(:,65).*STATES(:,11).*(1.00000 - STATES(:,33)) -  CONSTANTS(:,66).*STATES(:,33);
ALGEBRAIC(:,57) = RATES(:,32);
ALGEBRAIC(:,58) = RATES(:,33);
ALGEBRAIC(:,59) =  CONSTANTS(:,61).*ALGEBRAIC(:,57)+ CONSTANTS(:,62).*ALGEBRAIC(:,58);
ALGEBRAIC(:,60) = 1.00000./(1.00000+( CONSTANTS(:,75).*CONSTANTS(:,72))./power(CONSTANTS(:,72)+STATES(:,11), 2.00000)+( CONSTANTS(:,76).*CONSTANTS(:,73))./power(CONSTANTS(:,73)+STATES(:,11), 2.00000));
RATES(:,11) =  ALGEBRAIC(:,60).*((ALGEBRAIC(:,53) - (ALGEBRAIC(:,52)+ALGEBRAIC(:,59)))+( ( 2.00000.*ALGEBRAIC(:,38) - (ALGEBRAIC(:,41)+ALGEBRAIC(:,43))).*CONSTANTS(:,67).*1.00000)./( 2.00000.*CONSTANTS(:,68).*CONSTANTS(:,3)));
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) = piecewise({STATES(:,1)< - 40.0000,  135.000.*exp((80.0000+STATES(:,1))./ - 6.80000) }, 0.00000);
ALGEBRAIC(:,12) = piecewise({STATES(:,1)< - 40.0000,  3560.00.*exp( 0.0790000.*STATES(:,1))+ 310000..*exp( 0.350000.*STATES(:,1)) }, 1000.00./( 0.130000.*(1.00000+exp((STATES(:,1)+10.6600)./ - 11.1000))));
ALGEBRAIC(:,3) = piecewise({STATES(:,1)< - 40.0000, ( 1000.00.* - ( 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(:,13) = piecewise({STATES(:,1)< - 40.0000, ( 121.200.*exp(  - 0.0105200.*STATES(:,1)))./(1.00000+exp(  - 0.137800.*(STATES(:,1)+40.1400))) }, ( 300.000.*exp(  - 2.53500e-07.*STATES(:,1)))./(1.00000+exp(  - 0.100000.*(STATES(:,1)+32.0000))));
ALGEBRAIC(:,15) = 0.00100000./(( 7.19000e-05.*(STATES(:,1) - 10.0000))./(1.00000 - exp(  - 0.148000.*(STATES(:,1) - 10.0000)))+( 0.000131000.*(STATES(:,1) - 10.0000))./(exp( 0.0687000.*(STATES(:,1) - 10.0000)) - 1.00000));
ALGEBRAIC(:,5) = 1.00000./(1.00000+exp( - (STATES(:,1) - 24.7000)./13.6000));
ALGEBRAIC(:,6) =  45.1600.*exp( 0.0357700.*STATES(:,1));
ALGEBRAIC(:,16) =  98.9000.*exp(  - 0.0623700.*STATES(:,1));
ALGEBRAIC(:,7) = ( 5.41500.*exp( - (STATES(:,1)+33.5000)./5.00000))./(1.00000+ 0.0513350.*exp( - (STATES(:,1)+33.5000)./5.00000));
ALGEBRAIC(:,17) = ( 5.41500.*exp((STATES(:,1)+33.5000)./5.00000))./(1.00000+ 0.0513350.*exp((STATES(:,1)+33.5000)./5.00000));
ALGEBRAIC(:,9) = 0.800000./(1.00000+exp((STATES(:,1)+12.5000)./5.00000))+0.200000;
ALGEBRAIC(:,19) = (20.0000+600.000./(1.00000+exp((STATES(:,1)+20.0000)./9.50000)))./1000.00;
ALGEBRAIC(:,1) = STATES(:,1)+47.1300;
ALGEBRAIC(:,11) = piecewise({abs(ALGEBRAIC(:,1))<1.00000e-05, 1000.00./(0.100000 -  0.00500000.*ALGEBRAIC(:,1)) }, ( 320.000.*ALGEBRAIC(:,1))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,1))));
ALGEBRAIC(:,21) =  80.0000.*exp( - STATES(:,1)./11.0000);
ALGEBRAIC(:,4) = exp( - 5.49500+ 0.169100.*STATES(:,1));
ALGEBRAIC(:,14) = exp( - 7.67700 -  0.0128000.*STATES(:,1));
ALGEBRAIC(:,22) = ALGEBRAIC(:,4)./(ALGEBRAIC(:,4)+ALGEBRAIC(:,14));
ALGEBRAIC(:,25) = 0.00100000./(ALGEBRAIC(:,4)+ALGEBRAIC(:,14))+ CONSTANTS(:,14).*0.0270000;
ALGEBRAIC(:,8) =  400.000.*exp((STATES(:,1)+2.00000)./10.0000);
ALGEBRAIC(:,18) =  50.0000.*exp( - (STATES(:,1)+2.00000)./13.0000);
ALGEBRAIC(:,28) = ( 103.750.*STATES(:,24))./1.00000;
ALGEBRAIC(:,23) =  ALGEBRAIC(:,8).*CONSTANTS(:,36);
ALGEBRAIC(:,26) = ALGEBRAIC(:,18)./CONSTANTS(:,37);
ALGEBRAIC(:,20) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,2));
ALGEBRAIC(:,24) =  CONSTANTS(:,10).*power(STATES(:,3), 3.00000).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - ALGEBRAIC(:,20));
ALGEBRAIC(:,38) =  (( CONSTANTS(:,22).*5000.00)./( (power(CONSTANTS(:,21), 3.00000)+power(CONSTANTS(:,11), 3.00000)).*(CONSTANTS(:,20)+CONSTANTS(:,25)).*(1.00000+ CONSTANTS(:,23).*exp(( (CONSTANTS(:,24) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( exp(( CONSTANTS(:,24).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,2), 3.00000).*CONSTANTS(:,25) -  exp(( (CONSTANTS(:,24) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,11), 3.00000).*STATES(:,11));
ALGEBRAIC(:,39) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,79).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,40) = ( (( CONSTANTS(:,26).*ALGEBRAIC(:,39))./(1.00000+power(CONSTANTS(:,27)./STATES(:,2), 1.50000))).*CONSTANTS(:,13))./(CONSTANTS(:,13)+CONSTANTS(:,28));
ALGEBRAIC(:,44) =  CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,20));
ALGEBRAIC(:,45) = ( (( (CONSTANTS(:,33)./( 1.00000.*1.00000)).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000).*1000.00)./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( 0.00100000.*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,25)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,46) =  ALGEBRAIC(:,45).*STATES(:,25).*(STATES(:,12)+STATES(:,13));
ALGEBRAIC(:,47) = CONSTANTS(:,34)./(1.00000+ALGEBRAIC(:,45)./CONSTANTS(:,35));
ALGEBRAIC(:,49) = ( (( (ALGEBRAIC(:,47)./( 1.00000.*1.00000)).*STATES(:,25).*(STATES(:,12)+STATES(:,13)).*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,6).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,13)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,27) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,13)./STATES(:,6));
ALGEBRAIC(:,29) = 1.00000./(1.00000+ 1.49450.*exp( 0.0446000.*STATES(:,1)));
ALGEBRAIC(:,30) =  CONSTANTS(:,12).*CONSTANTS(:,78).*ALGEBRAIC(:,29).*STATES(:,7).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,31) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,13)+ 0.0183300.*CONSTANTS(:,11))./(STATES(:,6)+ 0.0183300.*STATES(:,2)));
ALGEBRAIC(:,32) =  CONSTANTS(:,15).*power(STATES(:,8), 2.00000).*(STATES(:,1) - ALGEBRAIC(:,31));
ALGEBRAIC(:,33) =  CONSTANTS(:,16).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,34) = 1.00000./(2.00000+exp( (( 1.50000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,1) - ALGEBRAIC(:,27))));
ALGEBRAIC(:,35) =  (( CONSTANTS(:,17).*ALGEBRAIC(:,34).*CONSTANTS(:,13))./(CONSTANTS(:,13)+CONSTANTS(:,18))).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,36) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
ALGEBRAIC(:,37) =  CONSTANTS(:,19).*ALGEBRAIC(:,36).*(STATES(:,1) - ALGEBRAIC(:,27));
ALGEBRAIC(:,41) = ( CONSTANTS(:,30).*STATES(:,11))./(CONSTANTS(:,29)+STATES(:,11));
ALGEBRAIC(:,42) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,25)./STATES(:,11));
ALGEBRAIC(:,43) =  CONSTANTS(:,31).*(STATES(:,1) - ALGEBRAIC(:,42));
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(:,50) = power(STATES(:,11)./CONSTANTS(:,52), CONSTANTS(:,57));
ALGEBRAIC(:,51) = power(STATES(:,31)./CONSTANTS(:,53), CONSTANTS(:,58));
ALGEBRAIC(:,52) = ( CONSTANTS(:,56).*( CONSTANTS(:,54).*ALGEBRAIC(:,50) -  CONSTANTS(:,55).*ALGEBRAIC(:,51)))./(1.00000+ALGEBRAIC(:,50)+ALGEBRAIC(:,51));
ALGEBRAIC(:,54) = (STATES(:,31) - STATES(:,30))./CONSTANTS(:,59);
ALGEBRAIC(:,48) =  CONSTANTS(:,43).*(STATES(:,26)+STATES(:,27)).*(STATES(:,30) - STATES(:,24));
ALGEBRAIC(:,53) = (STATES(:,24) - STATES(:,11))./CONSTANTS(:,60);
ALGEBRAIC(:,55) = 1.00000./(1.00000+( CONSTANTS(:,75).*CONSTANTS(:,72))./power(CONSTANTS(:,72)+STATES(:,24), 2.00000)+( CONSTANTS(:,76).*CONSTANTS(:,73))./power(CONSTANTS(:,73)+STATES(:,24), 2.00000));
ALGEBRAIC(:,56) = 1.00000./(1.00000+( CONSTANTS(:,77).*CONSTANTS(:,74))./power(CONSTANTS(:,74)+STATES(:,30), 2.00000));
ALGEBRAIC(:,57) = RATES(:,32);
ALGEBRAIC(:,58) = RATES(:,33);
ALGEBRAIC(:,59) =  CONSTANTS(:,61).*ALGEBRAIC(:,57)+ CONSTANTS(:,62).*ALGEBRAIC(:,58);
ALGEBRAIC(:,60) = 1.00000./(1.00000+( CONSTANTS(:,75).*CONSTANTS(:,72))./power(CONSTANTS(:,72)+STATES(:,11), 2.00000)+( CONSTANTS(:,76).*CONSTANTS(:,73))./power(CONSTANTS(:,73)+STATES(:,11), 2.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 Winslow, Rice, Jafri, Marban, Ororke, 1999 at changeset fecf9e962d0c.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: