# 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 =47;
end
% There are a total of 13 entries in each of the rate and state variable arrays.
% There are a total of 55 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('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_ALGEBRAIC(:,21) = strpad('i_Na in component fast_sodium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,40) = strpad('i_Ca in component L_type_Ca_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,41) = strpad('i_CaK in component L_type_Ca_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,27) = strpad('i_Kr in component rapid_activating_delayed_rectifiyer_K_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,28) = strpad('i_Ks in component slow_activating_delayed_rectifiyer_K_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,29) = strpad('i_to in component transient_outward_potassium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,25) = strpad('i_K1 in component time_independent_potassium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,31) = strpad('i_Kp in component plateau_potassium_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,34) = strpad('i_NaCa in component Na_Ca_exchanger (microA_per_microF)');
LEGEND_ALGEBRAIC(:,33) = strpad('i_NaK in component sodium_potassium_pump (microA_per_microF)');
LEGEND_ALGEBRAIC(:,35) = strpad('i_p_Ca in component sarcolemmal_calcium_pump (microA_per_microF)');
LEGEND_ALGEBRAIC(:,37) = strpad('i_Ca_b in component calcium_background_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,38) = strpad('i_Na_b in component sodium_background_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,11) = strpad('i_Stim in component membrane (microA_per_microF)');
LEGEND_CONSTANTS(:,4) = strpad('stim_start in component membrane (millisecond)');
LEGEND_CONSTANTS(:,5) = strpad('stim_end in component membrane (millisecond)');
LEGEND_CONSTANTS(:,6) = strpad('stim_period in component membrane (millisecond)');
LEGEND_CONSTANTS(:,7) = strpad('stim_duration in component membrane (millisecond)');
LEGEND_CONSTANTS(:,8) = strpad('stim_amplitude in component membrane (microA_per_microF)');
LEGEND_CONSTANTS(:,51) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,9) = strpad('g_Na in component fast_sodium_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,10) = strpad('Na_o in component standard_ionic_concentrations (millimolar)');
LEGEND_CONSTANTS(:,11) = strpad('Na_i in component standard_ionic_concentrations (millimolar)');
LEGEND_STATES(:,2) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,3) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_STATES(:,4) = strpad('j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,12) = strpad('alpha_m in component fast_sodium_current_m_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,22) = strpad('beta_m in component fast_sodium_current_m_gate (per_millisecond)');
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_millisecond)');
LEGEND_ALGEBRAIC(:,13) = strpad('beta_h in component fast_sodium_current_h_gate (per_millisecond)');
LEGEND_CONSTANTS(:,12) = strpad('shift_h in component fast_sodium_current_h_gate (millivolt)');
LEGEND_ALGEBRAIC(:,3) = strpad('alpha_j in component fast_sodium_current_j_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,14) = strpad('beta_j in component fast_sodium_current_j_gate (per_millisecond)');
LEGEND_CONSTANTS(:,13) = strpad('shift_j in component fast_sodium_current_j_gate (millivolt)');
LEGEND_CONSTANTS(:,14) = strpad('g_K1 in component time_independent_potassium_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,15) = strpad('K_mK1 in component time_independent_potassium_current (millimolar)');
LEGEND_CONSTANTS(:,52) = strpad('E_K in component rapid_activating_delayed_rectifiyer_K_current (millivolt)');
LEGEND_CONSTANTS(:,16) = strpad('K_o in component standard_ionic_concentrations (millimolar)');
LEGEND_ALGEBRAIC(:,24) = strpad('K1_infinity in component time_independent_potassium_current_K1_gate (dimensionless)');
LEGEND_CONSTANTS(:,17) = strpad('g_Kr in component rapid_activating_delayed_rectifiyer_K_current (milliS_per_microF)');
LEGEND_ALGEBRAIC(:,26) = strpad('R_V in component rapid_activating_delayed_rectifiyer_K_current (dimensionless)');
LEGEND_CONSTANTS(:,18) = strpad('K_i in component standard_ionic_concentrations (millimolar)');
LEGEND_STATES(:,5) = strpad('X_kr in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('X_kr_inf in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,15) = strpad('tau_X_kr in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (millisecond)');
LEGEND_CONSTANTS(:,19) = strpad('g_Ks in component slow_activating_delayed_rectifiyer_K_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,53) = strpad('E_Ks in component slow_activating_delayed_rectifiyer_K_current (millivolt)');
LEGEND_STATES(:,6) = strpad('X_ks in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,16) = strpad('tau_X_ks in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (millisecond)');
LEGEND_ALGEBRAIC(:,5) = strpad('X_ks_infinity in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (dimensionless)');
LEGEND_CONSTANTS(:,20) = strpad('g_to in component transient_outward_potassium_current (milliS_per_microF)');
LEGEND_STATES(:,7) = strpad('X_to in component transient_outward_potassium_current_X_to_gate (dimensionless)');
LEGEND_STATES(:,8) = strpad('Y_to in component transient_outward_potassium_current_Y_to_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,6) = strpad('alpha_X_to in component transient_outward_potassium_current_X_to_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,17) = strpad('beta_X_to in component transient_outward_potassium_current_X_to_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,7) = strpad('alpha_Y_to in component transient_outward_potassium_current_Y_to_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,18) = strpad('beta_Y_to in component transient_outward_potassium_current_Y_to_gate (per_millisecond)');
LEGEND_CONSTANTS(:,21) = strpad('g_Kp in component plateau_potassium_current (milliS_per_microF)');
LEGEND_ALGEBRAIC(:,30) = strpad('Kp_V in component plateau_potassium_current_Kp_gate (dimensionless)');
LEGEND_CONSTANTS(:,22) = strpad('i_NaK_max in component sodium_potassium_pump (microA_per_microF)');
LEGEND_ALGEBRAIC(:,32) = strpad('f_NaK in component sodium_potassium_pump (dimensionless)');
LEGEND_CONSTANTS(:,23) = strpad('K_mNai in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,24) = strpad('K_mKo in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,54) = strpad('sigma in component sodium_potassium_pump (dimensionless)');
LEGEND_CONSTANTS(:,25) = strpad('K_mCa in component Na_Ca_exchanger (micromolar)');
LEGEND_CONSTANTS(:,26) = strpad('K_mNa in component Na_Ca_exchanger (millimolar)');
LEGEND_CONSTANTS(:,27) = strpad('K_NaCa in component Na_Ca_exchanger (microA_per_microF)');
LEGEND_CONSTANTS(:,28) = strpad('K_sat in component Na_Ca_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,29) = strpad('eta in component Na_Ca_exchanger (dimensionless)');
LEGEND_STATES(:,9) = strpad('Ca_i in component calcium_dynamics (micromolar)');
LEGEND_CONSTANTS(:,30) = strpad('Ca_o in component standard_ionic_concentrations (micromolar)');
LEGEND_CONSTANTS(:,31) = strpad('K_mpCa in component sarcolemmal_calcium_pump (micromolar)');
LEGEND_CONSTANTS(:,32) = strpad('i_pCa_max in component sarcolemmal_calcium_pump (microA_per_microF)');
LEGEND_CONSTANTS(:,33) = strpad('g_Cab in component calcium_background_current (milliS_per_microF)');
LEGEND_ALGEBRAIC(:,36) = strpad('E_Ca in component calcium_background_current (millivolt)');
LEGEND_CONSTANTS(:,34) = strpad('g_Nab in component sodium_background_current (milliS_per_microF)');
LEGEND_CONSTANTS(:,35) = strpad('P_Ca in component L_type_Ca_current (cm_per_millisecond)');
LEGEND_CONSTANTS(:,36) = strpad('P_CaK in component L_type_Ca_current (cm_per_millisecond)');
LEGEND_CONSTANTS(:,37) = strpad('i_Ca_half in component L_type_Ca_current (microA_per_microF)');
LEGEND_ALGEBRAIC(:,39) = strpad('i_Ca_max in component L_type_Ca_current (microA_per_microF)');
LEGEND_CONSTANTS(:,38) = strpad('C_sc in component L_type_Ca_current (microF_per_cm2)');
LEGEND_STATES(:,10) = strpad('f in component L_type_Ca_current_f_gate (dimensionless)');
LEGEND_STATES(:,11) = strpad('d in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_STATES(:,12) = strpad('f_Ca in component L_type_Ca_current_f_Ca_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,8) = strpad('f_infinity in component L_type_Ca_current_f_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,19) = strpad('tau_f in component L_type_Ca_current_f_gate (millisecond)');
LEGEND_ALGEBRAIC(:,9) = strpad('d_infinity in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,23) = strpad('tau_d in component L_type_Ca_current_d_gate (millisecond)');
LEGEND_ALGEBRAIC(:,20) = strpad('E0_m in component L_type_Ca_current_d_gate (millivolt)');
LEGEND_CONSTANTS(:,55) = strpad('tau_f_Ca in component L_type_Ca_current_f_Ca_gate (millisecond)');
LEGEND_ALGEBRAIC(:,10) = strpad('f_Ca_infinity in component L_type_Ca_current_f_Ca_gate (dimensionless)');
LEGEND_CONSTANTS(:,39) = strpad('K_mfCa in component L_type_Ca_current_f_Ca_gate (micromolar)');
LEGEND_ALGEBRAIC(:,46) = strpad('beta_i in component calcium_dynamics (dimensionless)');
LEGEND_CONSTANTS(:,40) = strpad('K_mCMDN in component calcium_dynamics (micromolar)');
LEGEND_CONSTANTS(:,41) = strpad('CMDN_tot in component calcium_dynamics (micromolar)');
LEGEND_CONSTANTS(:,42) = strpad('V_myo in component calcium_dynamics (microlitre)');
LEGEND_CONSTANTS(:,43) = strpad('A_Cap in component calcium_dynamics (cm2)');
LEGEND_ALGEBRAIC(:,44) = strpad('J_rel in component calcium_dynamics (micromolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,45) = strpad('J_leak in component calcium_dynamics (micromolar_per_millisecond)');
LEGEND_ALGEBRAIC(:,42) = strpad('J_up in component calcium_dynamics (micromolar_per_millisecond)');
LEGEND_STATES(:,13) = strpad('Ca_SR in component calcium_dynamics (micromolar)');
LEGEND_CONSTANTS(:,44) = strpad('P_rel in component calcium_dynamics (per_millisecond)');
LEGEND_CONSTANTS(:,45) = strpad('P_leak in component calcium_dynamics (per_millisecond)');
LEGEND_CONSTANTS(:,46) = strpad('K_mCSQN in component calcium_dynamics (micromolar)');
LEGEND_CONSTANTS(:,47) = strpad('CSQN_tot in component calcium_dynamics (micromolar)');
LEGEND_CONSTANTS(:,48) = strpad('V_SR in component calcium_dynamics (microlitre)');
LEGEND_CONSTANTS(:,49) = strpad('V_up in component calcium_dynamics (micromolar_per_millisecond)');
LEGEND_CONSTANTS(:,50) = strpad('K_mup in component calcium_dynamics (micromolar)');
LEGEND_ALGEBRAIC(:,43) = strpad('gamma in component calcium_dynamics (dimensionless)');
LEGEND_ALGEBRAIC(:,47) = strpad('beta_SR in component calcium_dynamics (dimensionless)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,2) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,3) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt j in component fast_sodium_current_j_gate (dimensionless)');
LEGEND_RATES(:,5) = strpad('d/dt X_kr in component rapid_activating_delayed_rectifiyer_K_current_X_kr_gate (dimensionless)');
LEGEND_RATES(:,6) = strpad('d/dt X_ks in component slow_activating_delayed_rectifiyer_K_current_X_ks_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt X_to in component transient_outward_potassium_current_X_to_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt Y_to in component transient_outward_potassium_current_Y_to_gate (dimensionless)');
LEGEND_RATES(:,10) = strpad('d/dt f in component L_type_Ca_current_f_gate (dimensionless)');
LEGEND_RATES(:,11) = strpad('d/dt d in component L_type_Ca_current_d_gate (dimensionless)');
LEGEND_RATES(:,12) = strpad('d/dt f_Ca in component L_type_Ca_current_f_Ca_gate (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt Ca_SR in component calcium_dynamics (micromolar)');
LEGEND_RATES(:,9) = strpad('d/dt Ca_i in component calcium_dynamics (micromolar)');
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) = -94.7;
CONSTANTS(:,1) = 8.314;
CONSTANTS(:,2) = 310;
CONSTANTS(:,3) = 96.5;
CONSTANTS(:,4) = 50;
CONSTANTS(:,5) = 9000;
CONSTANTS(:,6) = 1000;
CONSTANTS(:,7) = 1;
CONSTANTS(:,8) = -80;
CONSTANTS(:,9) = 12.8;
CONSTANTS(:,10) = 138;
CONSTANTS(:,11) = 10;
STATES(:,2) = 0.00024676;
STATES(:,3) = 0.99869;
STATES(:,4) = 0.99887;
CONSTANTS(:,12) = 0;
CONSTANTS(:,13) = 0;
CONSTANTS(:,14) = 2.8;
CONSTANTS(:,15) = 13;
CONSTANTS(:,16) = 4;
CONSTANTS(:,17) = 0.0136;
CONSTANTS(:,18) = 149.4;
STATES(:,5) = 0.229;
CONSTANTS(:,19) = 0.0245;
STATES(:,6) = 0.0001;
CONSTANTS(:,20) = 0.23815;
STATES(:,7) = 0.00003742;
STATES(:,8) = 1;
CONSTANTS(:,21) = 0.002216;
CONSTANTS(:,22) = 0.693;
CONSTANTS(:,23) = 10;
CONSTANTS(:,24) = 1.5;
CONSTANTS(:,25) = 1380;
CONSTANTS(:,26) = 87.5;
CONSTANTS(:,27) = 1500;
CONSTANTS(:,28) = 0.2;
CONSTANTS(:,29) = 0.35;
STATES(:,9) = 0.0472;
CONSTANTS(:,30) = 2000;
CONSTANTS(:,31) = 0.05;
CONSTANTS(:,32) = 0.05;
CONSTANTS(:,33) = 0.0003842;
CONSTANTS(:,34) = 0.0031;
CONSTANTS(:,35) = 0.0000226;
CONSTANTS(:,36) = 0.000000579;
CONSTANTS(:,37) = -0.265;
CONSTANTS(:,38) = 1;
STATES(:,10) = 0.983;
STATES(:,11) = 0.0001;
STATES(:,12) = 0.942;
CONSTANTS(:,39) = 0.18;
CONSTANTS(:,40) = 2;
CONSTANTS(:,41) = 10;
CONSTANTS(:,42) = 0.00002584;
CONSTANTS(:,43) = 0.0001534;
STATES(:,13) = 320;
CONSTANTS(:,44) = 6;
CONSTANTS(:,45) = 0.000001;
CONSTANTS(:,46) = 600;
CONSTANTS(:,47) = 10000;
CONSTANTS(:,48) = 0.000002;
CONSTANTS(:,49) = 0.1;
CONSTANTS(:,50) = 0.32;
CONSTANTS(:,51) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,10)./CONSTANTS(:,11));
CONSTANTS(:,52) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,16)./CONSTANTS(:,18));
CONSTANTS(:,53) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,16)+ 0.0183300.*CONSTANTS(:,10))./(CONSTANTS(:,18)+ 0.0183300.*CONSTANTS(:,11)));
CONSTANTS(:,54) =  (1.00000./7.00000).*(exp(CONSTANTS(:,10)./67.3000) - 1.00000);
CONSTANTS(:,55) = 30.0000;
if (isempty(STATES)), warning('Initial values for states not set');, end
end

function [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS)
global algebraicVariableCount;
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
ALGEBRAIC = zeros(1, algebraicVariableCount);
utilOnes = 1;
else
statesRowCount = statesSize(1);
ALGEBRAIC = zeros(statesRowCount, algebraicVariableCount);
RATES = zeros(statesRowCount, statesColumnCount);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,10) = 1.00000./(1.00000+power(STATES(:,9)./CONSTANTS(:,39), 3.00000));
RATES(:,12) = (ALGEBRAIC(:,10) - STATES(:,12))./CONSTANTS(:,55);
ALGEBRAIC(:,2) =  0.135000.*exp(((STATES(:,1)+80.0000) - CONSTANTS(:,12))./ - 6.80000);
ALGEBRAIC(:,13) = 7.50000./(1.00000+exp(  - 0.100000.*((STATES(:,1)+11.0000) - CONSTANTS(:,12))));
RATES(:,3) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,3)) -  ALGEBRAIC(:,13).*STATES(:,3);
ALGEBRAIC(:,3) = ( 0.175000.*exp(((STATES(:,1)+100.000) - CONSTANTS(:,13))./ - 23.0000))./(1.00000+exp( 0.150000.*((STATES(:,1)+79.0000) - CONSTANTS(:,13))));
ALGEBRAIC(:,14) = 0.300000./(1.00000+exp(  - 0.100000.*((STATES(:,1)+32.0000) - CONSTANTS(:,13))));
RATES(:,4) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,4)) -  ALGEBRAIC(:,14).*STATES(:,4);
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp( - 2.18200 -  0.181900.*STATES(:,1)));
ALGEBRAIC(:,15) = 43.0000+1.00000./(exp( - 5.49500+ 0.169100.*STATES(:,1))+exp( - 7.67700 -  0.0128000.*STATES(:,1)));
RATES(:,5) = (ALGEBRAIC(:,4) - STATES(:,5))./ALGEBRAIC(:,15);
ALGEBRAIC(:,16) = 1.00000./(( 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) - 16.0000)./ - 13.6000));
RATES(:,6) = (ALGEBRAIC(:,5) - STATES(:,6))./ALGEBRAIC(:,16);
ALGEBRAIC(:,6) =  0.0451600.*exp( 0.0357700.*STATES(:,1));
ALGEBRAIC(:,17) =  0.0989000.*exp(  - 0.0623700.*STATES(:,1));
RATES(:,7) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,17).*STATES(:,7);
ALGEBRAIC(:,7) = ( 0.00541500.*exp((STATES(:,1)+33.5000)./ - 5.00000))./(1.00000+ 0.0513350.*exp((STATES(:,1)+33.5000)./ - 5.00000));
ALGEBRAIC(:,18) = ( 0.00541500.*exp((STATES(:,1)+33.5000)./5.00000))./(1.00000+ 0.0513350.*exp((STATES(:,1)+33.5000)./5.00000));
RATES(:,8) =  ALGEBRAIC(:,7).*(1.00000 - STATES(:,8)) -  ALGEBRAIC(:,18).*STATES(:,8);
ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+12.5000)./5.00000));
ALGEBRAIC(:,19) = 30.0000+200.000./(1.00000+exp((STATES(:,1)+20.0000)./9.50000));
RATES(:,10) = (ALGEBRAIC(:,8) - STATES(:,10))./ALGEBRAIC(:,19);
ALGEBRAIC(:,1) = STATES(:,1)+47.1300;
ALGEBRAIC(:,12) = ( 0.320000.*ALGEBRAIC(:,1))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,1)));
ALGEBRAIC(:,22) =  0.0800000.*exp( - STATES(:,1)./11.0000);
RATES(:,2) =  ALGEBRAIC(:,12).*(1.00000 - STATES(:,2)) -  ALGEBRAIC(:,22).*STATES(:,2);
ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+10.0000)./ - 6.24000));
ALGEBRAIC(:,20) = STATES(:,1)+40.0000;
ALGEBRAIC(:,23) = 1.00000./(( 0.250000.*exp(  - 0.0100000.*STATES(:,1)))./(1.00000+exp(  - 0.0700000.*STATES(:,1)))+( 0.0700000.*exp(  - 0.0500000.*ALGEBRAIC(:,20)))./(1.00000+exp( 0.0500000.*ALGEBRAIC(:,20))));
RATES(:,11) = (ALGEBRAIC(:,9) - STATES(:,11))./ALGEBRAIC(:,23);
ALGEBRAIC(:,21) =  CONSTANTS(:,9).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - CONSTANTS(:,51));
ALGEBRAIC(:,39) = ( (( (CONSTANTS(:,35)./CONSTANTS(:,38)).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,9).*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,30)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,40) =  ALGEBRAIC(:,39).*STATES(:,10).*STATES(:,11).*STATES(:,12);
ALGEBRAIC(:,41) = ( (( (( (CONSTANTS(:,36)./CONSTANTS(:,38)).*STATES(:,10).*STATES(:,11).*STATES(:,12))./(1.00000+ALGEBRAIC(:,39)./CONSTANTS(:,37))).*1000.00.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,18).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,16)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,26) = 1.00000./(1.00000+ 2.50000.*exp( 0.100000.*(STATES(:,1)+28.0000)));
ALGEBRAIC(:,27) =  CONSTANTS(:,17).*ALGEBRAIC(:,26).*STATES(:,5).*power((CONSTANTS(:,16)./4.00000), 1.0 ./ 2).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,28) =  CONSTANTS(:,19).*power(STATES(:,6), 2.00000).*(STATES(:,1) - CONSTANTS(:,53));
ALGEBRAIC(:,29) =  CONSTANTS(:,20).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,24) = 1.00000./(2.00000+exp( (( 1.62000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,1) - CONSTANTS(:,52))));
ALGEBRAIC(:,25) =  (( CONSTANTS(:,14).*ALGEBRAIC(:,24).*CONSTANTS(:,16))./(CONSTANTS(:,16)+CONSTANTS(:,15))).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,30) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
ALGEBRAIC(:,31) =  CONSTANTS(:,21).*ALGEBRAIC(:,30).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,34) =  (CONSTANTS(:,27)./( (power(CONSTANTS(:,26), 3.00000)+power(CONSTANTS(:,10), 3.00000)).*(CONSTANTS(:,25)+CONSTANTS(:,30)).*(1.00000+ CONSTANTS(:,28).*exp(( (CONSTANTS(:,29) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( exp(( CONSTANTS(:,29).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,11), 3.00000).*CONSTANTS(:,30) -  exp(( (CONSTANTS(:,29) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,10), 3.00000).*STATES(:,9));
ALGEBRAIC(:,32) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,54).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,33) = ( (( CONSTANTS(:,22).*ALGEBRAIC(:,32))./(1.00000+power(CONSTANTS(:,23)./CONSTANTS(:,11), 1.50000))).*CONSTANTS(:,16))./(CONSTANTS(:,16)+CONSTANTS(:,24));
ALGEBRAIC(:,35) = ( CONSTANTS(:,32).*STATES(:,9))./(CONSTANTS(:,31)+STATES(:,9));
ALGEBRAIC(:,36) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,30)./STATES(:,9));
ALGEBRAIC(:,37) =  CONSTANTS(:,33).*(STATES(:,1) - ALGEBRAIC(:,36));
ALGEBRAIC(:,38) =  CONSTANTS(:,34).*(STATES(:,1) - CONSTANTS(:,51));
ALGEBRAIC(:,11) = piecewise({VOI>=CONSTANTS(:,4)&VOI<=CONSTANTS(:,5)&(VOI - CONSTANTS(:,4)) -  floor((VOI - CONSTANTS(:,4))./CONSTANTS(:,6)).*CONSTANTS(:,6)<=CONSTANTS(:,7), CONSTANTS(:,8) }, 0.00000);
RATES(:,1) =  - (ALGEBRAIC(:,21)+ALGEBRAIC(:,40)+ALGEBRAIC(:,41)+ALGEBRAIC(:,27)+ALGEBRAIC(:,28)+ALGEBRAIC(:,29)+ALGEBRAIC(:,25)+ALGEBRAIC(:,31)+ALGEBRAIC(:,34)+ALGEBRAIC(:,33)+ALGEBRAIC(:,35)+ALGEBRAIC(:,38)+ALGEBRAIC(:,37)+ALGEBRAIC(:,11));
ALGEBRAIC(:,43) = 1.00000./(1.00000+power(2000.00./STATES(:,13), 3.00000));
ALGEBRAIC(:,44) = ( CONSTANTS(:,44).*STATES(:,10).*STATES(:,11).*STATES(:,12).*( ALGEBRAIC(:,43).*STATES(:,13) - STATES(:,9)))./(1.00000+ 1.65000.*exp(STATES(:,1)./20.0000));
ALGEBRAIC(:,45) =  CONSTANTS(:,45).*(STATES(:,13) - STATES(:,9));
ALGEBRAIC(:,42) = CONSTANTS(:,49)./(1.00000+power(CONSTANTS(:,50)./STATES(:,9), 2.00000));
ALGEBRAIC(:,47) = 1.00000./(1.00000+( CONSTANTS(:,47).*CONSTANTS(:,46))./power(CONSTANTS(:,46)+STATES(:,13), 2.00000));
RATES(:,13) = ( ALGEBRAIC(:,47).*((ALGEBRAIC(:,42) - ALGEBRAIC(:,45)) - ALGEBRAIC(:,44)).*CONSTANTS(:,42))./CONSTANTS(:,48);
ALGEBRAIC(:,46) = 1.00000./(1.00000+( CONSTANTS(:,41).*CONSTANTS(:,40))./power(CONSTANTS(:,40)+STATES(:,9), 2.00000));
RATES(:,9) =  ALGEBRAIC(:,46).*(((ALGEBRAIC(:,44)+ALGEBRAIC(:,45)) - ALGEBRAIC(:,42)) -  (( CONSTANTS(:,43).*CONSTANTS(:,38))./( 2.00000.*CONSTANTS(:,3).*CONSTANTS(:,42))).*((ALGEBRAIC(:,40)+ALGEBRAIC(:,37)+ALGEBRAIC(:,35)) -  2.00000.*ALGEBRAIC(:,34)));
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
utilOnes = 1;
else
statesRowCount = statesSize(1);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,10) = 1.00000./(1.00000+power(STATES(:,9)./CONSTANTS(:,39), 3.00000));
ALGEBRAIC(:,2) =  0.135000.*exp(((STATES(:,1)+80.0000) - CONSTANTS(:,12))./ - 6.80000);
ALGEBRAIC(:,13) = 7.50000./(1.00000+exp(  - 0.100000.*((STATES(:,1)+11.0000) - CONSTANTS(:,12))));
ALGEBRAIC(:,3) = ( 0.175000.*exp(((STATES(:,1)+100.000) - CONSTANTS(:,13))./ - 23.0000))./(1.00000+exp( 0.150000.*((STATES(:,1)+79.0000) - CONSTANTS(:,13))));
ALGEBRAIC(:,14) = 0.300000./(1.00000+exp(  - 0.100000.*((STATES(:,1)+32.0000) - CONSTANTS(:,13))));
ALGEBRAIC(:,4) = 1.00000./(1.00000+exp( - 2.18200 -  0.181900.*STATES(:,1)));
ALGEBRAIC(:,15) = 43.0000+1.00000./(exp( - 5.49500+ 0.169100.*STATES(:,1))+exp( - 7.67700 -  0.0128000.*STATES(:,1)));
ALGEBRAIC(:,16) = 1.00000./(( 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) - 16.0000)./ - 13.6000));
ALGEBRAIC(:,6) =  0.0451600.*exp( 0.0357700.*STATES(:,1));
ALGEBRAIC(:,17) =  0.0989000.*exp(  - 0.0623700.*STATES(:,1));
ALGEBRAIC(:,7) = ( 0.00541500.*exp((STATES(:,1)+33.5000)./ - 5.00000))./(1.00000+ 0.0513350.*exp((STATES(:,1)+33.5000)./ - 5.00000));
ALGEBRAIC(:,18) = ( 0.00541500.*exp((STATES(:,1)+33.5000)./5.00000))./(1.00000+ 0.0513350.*exp((STATES(:,1)+33.5000)./5.00000));
ALGEBRAIC(:,8) = 1.00000./(1.00000+exp((STATES(:,1)+12.5000)./5.00000));
ALGEBRAIC(:,19) = 30.0000+200.000./(1.00000+exp((STATES(:,1)+20.0000)./9.50000));
ALGEBRAIC(:,1) = STATES(:,1)+47.1300;
ALGEBRAIC(:,12) = ( 0.320000.*ALGEBRAIC(:,1))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,1)));
ALGEBRAIC(:,22) =  0.0800000.*exp( - STATES(:,1)./11.0000);
ALGEBRAIC(:,9) = 1.00000./(1.00000+exp((STATES(:,1)+10.0000)./ - 6.24000));
ALGEBRAIC(:,20) = STATES(:,1)+40.0000;
ALGEBRAIC(:,23) = 1.00000./(( 0.250000.*exp(  - 0.0100000.*STATES(:,1)))./(1.00000+exp(  - 0.0700000.*STATES(:,1)))+( 0.0700000.*exp(  - 0.0500000.*ALGEBRAIC(:,20)))./(1.00000+exp( 0.0500000.*ALGEBRAIC(:,20))));
ALGEBRAIC(:,21) =  CONSTANTS(:,9).*power(STATES(:,2), 3.00000).*STATES(:,3).*STATES(:,4).*(STATES(:,1) - CONSTANTS(:,51));
ALGEBRAIC(:,39) = ( (( (CONSTANTS(:,35)./CONSTANTS(:,38)).*4.00000.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( STATES(:,9).*exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  0.341000.*CONSTANTS(:,30)))./(exp(( 2.00000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,40) =  ALGEBRAIC(:,39).*STATES(:,10).*STATES(:,11).*STATES(:,12);
ALGEBRAIC(:,41) = ( (( (( (CONSTANTS(:,36)./CONSTANTS(:,38)).*STATES(:,10).*STATES(:,11).*STATES(:,12))./(1.00000+ALGEBRAIC(:,39)./CONSTANTS(:,37))).*1000.00.*STATES(:,1).*power(CONSTANTS(:,3), 2.00000))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*( CONSTANTS(:,18).*exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - CONSTANTS(:,16)))./(exp(( STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) - 1.00000);
ALGEBRAIC(:,26) = 1.00000./(1.00000+ 2.50000.*exp( 0.100000.*(STATES(:,1)+28.0000)));
ALGEBRAIC(:,27) =  CONSTANTS(:,17).*ALGEBRAIC(:,26).*STATES(:,5).*power((CONSTANTS(:,16)./4.00000), 1.0 ./ 2).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,28) =  CONSTANTS(:,19).*power(STATES(:,6), 2.00000).*(STATES(:,1) - CONSTANTS(:,53));
ALGEBRAIC(:,29) =  CONSTANTS(:,20).*STATES(:,7).*STATES(:,8).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,24) = 1.00000./(2.00000+exp( (( 1.62000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*(STATES(:,1) - CONSTANTS(:,52))));
ALGEBRAIC(:,25) =  (( CONSTANTS(:,14).*ALGEBRAIC(:,24).*CONSTANTS(:,16))./(CONSTANTS(:,16)+CONSTANTS(:,15))).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,30) = 1.00000./(1.00000+exp((7.48800 - STATES(:,1))./5.98000));
ALGEBRAIC(:,31) =  CONSTANTS(:,21).*ALGEBRAIC(:,30).*(STATES(:,1) - CONSTANTS(:,52));
ALGEBRAIC(:,34) =  (CONSTANTS(:,27)./( (power(CONSTANTS(:,26), 3.00000)+power(CONSTANTS(:,10), 3.00000)).*(CONSTANTS(:,25)+CONSTANTS(:,30)).*(1.00000+ CONSTANTS(:,28).*exp(( (CONSTANTS(:,29) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( exp(( CONSTANTS(:,29).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,11), 3.00000).*CONSTANTS(:,30) -  exp(( (CONSTANTS(:,29) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,10), 3.00000).*STATES(:,9));
ALGEBRAIC(:,32) = 1.00000./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0365000.*CONSTANTS(:,54).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,33) = ( (( CONSTANTS(:,22).*ALGEBRAIC(:,32))./(1.00000+power(CONSTANTS(:,23)./CONSTANTS(:,11), 1.50000))).*CONSTANTS(:,16))./(CONSTANTS(:,16)+CONSTANTS(:,24));
ALGEBRAIC(:,35) = ( CONSTANTS(:,32).*STATES(:,9))./(CONSTANTS(:,31)+STATES(:,9));
ALGEBRAIC(:,36) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./( 2.00000.*CONSTANTS(:,3))).*log(CONSTANTS(:,30)./STATES(:,9));
ALGEBRAIC(:,37) =  CONSTANTS(:,33).*(STATES(:,1) - ALGEBRAIC(:,36));
ALGEBRAIC(:,38) =  CONSTANTS(:,34).*(STATES(:,1) - CONSTANTS(:,51));
ALGEBRAIC(:,11) = piecewise({VOI>=CONSTANTS(:,4)&VOI<=CONSTANTS(:,5)&(VOI - CONSTANTS(:,4)) -  floor((VOI - CONSTANTS(:,4))./CONSTANTS(:,6)).*CONSTANTS(:,6)<=CONSTANTS(:,7), CONSTANTS(:,8) }, 0.00000);
ALGEBRAIC(:,43) = 1.00000./(1.00000+power(2000.00./STATES(:,13), 3.00000));
ALGEBRAIC(:,44) = ( CONSTANTS(:,44).*STATES(:,10).*STATES(:,11).*STATES(:,12).*( ALGEBRAIC(:,43).*STATES(:,13) - STATES(:,9)))./(1.00000+ 1.65000.*exp(STATES(:,1)./20.0000));
ALGEBRAIC(:,45) =  CONSTANTS(:,45).*(STATES(:,13) - STATES(:,9));
ALGEBRAIC(:,42) = CONSTANTS(:,49)./(1.00000+power(CONSTANTS(:,50)./STATES(:,9), 2.00000));
ALGEBRAIC(:,47) = 1.00000./(1.00000+( CONSTANTS(:,47).*CONSTANTS(:,46))./power(CONSTANTS(:,46)+STATES(:,13), 2.00000));
ALGEBRAIC(:,46) = 1.00000./(1.00000+( CONSTANTS(:,41).*CONSTANTS(:,40))./power(CONSTANTS(:,40)+STATES(:,9), 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
function strout = strpad(strin)
req_length = 160;
insize = size(strin,2);
if insize > req_length
strout = strin(1:req_length);
else
strout = [strin, blanks(req_length - insize)];
end
end

```
Source
Derived from workspace Fox, Mcharg, Gilmour, 2002 at changeset d296ce29bef2.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: