# 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 =51;
end
% There are a total of 23 entries in each of the rate and state variable arrays.
% There are a total of 69 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_CONSTANTS(:,1) = strpad('R in component cell_parameters (millijoule_per_mole_kelvin)');
LEGEND_CONSTANTS(:,2) = strpad('T in component cell_parameters (kelvin)');
LEGEND_CONSTANTS(:,3) = strpad('F in component cell_parameters (coulomb_per_mole)');
LEGEND_CONSTANTS(:,4) = strpad('Cm in component cell_parameters (microF)');
LEGEND_CONSTANTS(:,5) = strpad('v_i in component cell_parameters (microlitre)');
LEGEND_CONSTANTS(:,6) = strpad('v_SR in component cell_parameters (microlitre)');
LEGEND_CONSTANTS(:,7) = strpad('Na_o in component cell_parameters (millimolar)');
LEGEND_CONSTANTS(:,8) = strpad('K_o in component cell_parameters (millimolar)');
LEGEND_CONSTANTS(:,9) = strpad('Ca_o in component cell_parameters (millimolar)');
LEGEND_STATES(:,1) = strpad('V in component membrane_potential (millivolt)');
LEGEND_ALGEBRAIC(:,22) = strpad('i_Na in component fast_sodium_current (nanoA)');
LEGEND_ALGEBRAIC(:,24) = strpad('i_K1 in component time_independent_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,25) = strpad('i_to in component transient_outward_current (nanoA)');
LEGEND_ALGEBRAIC(:,23) = strpad('i_K in component time_dependent_rectifier_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,29) = strpad('i_Ca_L in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,33) = strpad('i_NaK in component sodium_potassium_pump (nanoA)');
LEGEND_ALGEBRAIC(:,31) = strpad('i_NaCa in component sodium_calcium_exchanger (nanoA)');
LEGEND_ALGEBRAIC(:,40) = strpad('i_b_Na in component sodium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,37) = strpad('i_b_K in component potassium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,36) = strpad('i_b_Ca in component calcium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,1) = strpad('i_Stim in component membrane_potential (nanoA)');
LEGEND_CONSTANTS(:,10) = strpad('stim_start in component membrane_potential (second)');
LEGEND_CONSTANTS(:,11) = strpad('stim_end in component membrane_potential (second)');
LEGEND_CONSTANTS(:,12) = strpad('stim_period in component membrane_potential (second)');
LEGEND_CONSTANTS(:,13) = strpad('stim_duration in component membrane_potential (second)');
LEGEND_CONSTANTS(:,14) = strpad('stim_amplitude in component membrane_potential (nanoA)');
LEGEND_ALGEBRAIC(:,9) = strpad('E_Na in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,16) = strpad('E_K in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,20) = strpad('E_Ca in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,21) = strpad('E_mh in component reversal_potentials (millivolt)');
LEGEND_STATES(:,2) = strpad('K_i in component intracellular_potassium_concentration (millimolar)');
LEGEND_STATES(:,3) = strpad('Na_i in component intracellular_sodium_concentration (millimolar)');
LEGEND_STATES(:,4) = strpad('Ca_i in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,15) = strpad('g_Na in component fast_sodium_current (microS)');
LEGEND_STATES(:,5) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,6) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,10) = strpad('alpha_m in component fast_sodium_current_m_gate (per_second)');
LEGEND_ALGEBRAIC(:,17) = strpad('beta_m in component fast_sodium_current_m_gate (per_second)');
LEGEND_CONSTANTS(:,16) = strpad('delta_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,2) = strpad('E0_m in component fast_sodium_current_m_gate (millivolt)');
LEGEND_ALGEBRAIC(:,3) = strpad('alpha_h in component fast_sodium_current_h_gate (per_second)');
LEGEND_ALGEBRAIC(:,11) = strpad('beta_h in component fast_sodium_current_h_gate (per_second)');
LEGEND_CONSTANTS(:,17) = strpad('shift_h in component fast_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,18) = strpad('i_Kmax in component time_dependent_rectifier_potassium_current (nanoA)');
LEGEND_STATES(:,7) = strpad('x in component time_dependent_rectifier_potassium_current_x_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('alpha_x in component time_dependent_rectifier_potassium_current_x_gate (per_second)');
LEGEND_ALGEBRAIC(:,12) = strpad('beta_x in component time_dependent_rectifier_potassium_current_x_gate (per_second)');
LEGEND_CONSTANTS(:,19) = strpad('K_mk1 in component time_independent_potassium_current (millimolar)');
LEGEND_CONSTANTS(:,20) = strpad('g_K1 in component time_independent_potassium_current (microS)');
LEGEND_CONSTANTS(:,21) = strpad('g_to in component transient_outward_current (microS)');
LEGEND_STATES(:,8) = strpad('s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_STATES(:,9) = strpad('r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,5) = strpad('alpha_s in component transient_outward_current_s_gate (per_second)');
LEGEND_ALGEBRAIC(:,13) = strpad('beta_s in component transient_outward_current_s_gate (per_second)');
LEGEND_ALGEBRAIC(:,28) = strpad('i_Ca_L_Na in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,27) = strpad('i_Ca_L_K in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,26) = strpad('i_Ca_L_Ca in component L_type_Ca_channel (nanoA)');
LEGEND_CONSTANTS(:,22) = strpad('P_Ca_L_Ca in component L_type_Ca_channel (nanoA_per_millimolar)');
LEGEND_STATES(:,10) = strpad('d in component L_type_Ca_channel_d_gate (dimensionless)');
LEGEND_STATES(:,11) = strpad('f in component L_type_Ca_channel_f_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,14) = strpad('alpha_d in component L_type_Ca_channel_d_gate (per_second)');
LEGEND_ALGEBRAIC(:,18) = strpad('beta_d in component L_type_Ca_channel_d_gate (per_second)');
LEGEND_ALGEBRAIC(:,6) = strpad('E0_d in component L_type_Ca_channel_d_gate (millivolt)');
LEGEND_CONSTANTS(:,23) = strpad('speed_d in component L_type_Ca_channel_d_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,15) = strpad('alpha_f in component L_type_Ca_channel_f_gate (per_second)');
LEGEND_ALGEBRAIC(:,19) = strpad('beta_f in component L_type_Ca_channel_f_gate (per_second)');
LEGEND_CONSTANTS(:,24) = strpad('speed_f in component L_type_Ca_channel_f_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,7) = strpad('E0_f in component L_type_Ca_channel_f_gate (millivolt)');
LEGEND_CONSTANTS(:,25) = strpad('i_NaCa_max in component sodium_calcium_exchanger (nanoA_per_millimolar4)');
LEGEND_CONSTANTS(:,26) = strpad('gamma in component sodium_calcium_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,27) = strpad('i_NaK_max in component sodium_potassium_pump (nanoA)');
LEGEND_CONSTANTS(:,28) = strpad('K_mK in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,29) = strpad('K_mNa in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,30) = strpad('g_b_Ca in component calcium_background_current (microS)');
LEGEND_CONSTANTS(:,31) = strpad('g_b_K in component potassium_background_current (microS)');
LEGEND_CONSTANTS(:,32) = strpad('g_b_Na in component sodium_background_current (microS)');
LEGEND_STATES(:,12) = strpad('F_CaMK in component CaMKII_factor (dimensionless)');
LEGEND_ALGEBRAIC(:,8) = strpad('Inf_CaMK in component CaMKII_factor (dimensionless)');
LEGEND_CONSTANTS(:,33) = strpad('Tau_CaMK in component CaMKII_factor (second)');
LEGEND_STATES(:,13) = strpad('Cmdn_Ca in component calmodulin (millimolar)');
LEGEND_ALGEBRAIC(:,42) = strpad('j_rel in component RyR (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,41) = strpad('K_rel in component RyR (per_second)');
LEGEND_ALGEBRAIC(:,38) = strpad('F_rel in component RyR (dimensionless)');
LEGEND_STATES(:,14) = strpad('Ca_SR in component SR_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,34) = strpad('K_rel_max in component RyR (per_second)');
LEGEND_STATES(:,15) = strpad('F_SRCa_RyR in component RyR (millimolar)');
LEGEND_CONSTANTS(:,35) = strpad('Tau_SRCa_RyR in component RyR (second)');
LEGEND_ALGEBRAIC(:,30) = strpad('N_CaMK in component RyR (dimensionless)');
LEGEND_CONSTANTS(:,36) = strpad('gain_k1 in component RyR (dimensionless)');
LEGEND_CONSTANTS(:,37) = strpad('gain_k2 in component RyR (dimensionless)');
LEGEND_CONSTANTS(:,38) = strpad('gain_k3 in component RyR (dimensionless)');
LEGEND_CONSTANTS(:,39) = strpad('gain_k4 in component RyR (dimensionless)');
LEGEND_ALGEBRAIC(:,32) = strpad('k_1 in component RyR (per_second)');
LEGEND_ALGEBRAIC(:,34) = strpad('k_2 in component RyR (per_second)');
LEGEND_ALGEBRAIC(:,35) = strpad('k_3 in component RyR (per_second)');
LEGEND_CONSTANTS(:,54) = strpad('k_4 in component RyR (per_second)');
LEGEND_STATES(:,16) = strpad('F_1 in component RyR (dimensionless)');
LEGEND_STATES(:,17) = strpad('F_2 in component RyR (dimensionless)');
LEGEND_ALGEBRAIC(:,39) = strpad('F_3 in component RyR (dimensionless)');
LEGEND_CONSTANTS(:,40) = strpad('K_leak_rate in component RyR (per_second)');
LEGEND_ALGEBRAIC(:,45) = strpad('j_up in component SERCA (millimolar_per_second)');
LEGEND_CONSTANTS(:,41) = strpad('V_max_f in component SERCA (millimolar_per_second)');
LEGEND_CONSTANTS(:,42) = strpad('V_max_r in component SERCA (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,43) = strpad('f_b in component SERCA (dimensionless)');
LEGEND_ALGEBRAIC(:,44) = strpad('r_b in component SERCA (dimensionless)');
LEGEND_CONSTANTS(:,43) = strpad('Cmdn_tot in component calmodulin (millimolar)');
LEGEND_CONSTANTS(:,44) = strpad('alpha_cmdn in component calmodulin (per_millimolar_per_second)');
LEGEND_CONSTANTS(:,45) = strpad('beta_cmdn in component calmodulin (per_second)');
LEGEND_ALGEBRAIC(:,46) = strpad('dCmdn_Ca_dtime in component calmodulin (millimolar_per_second)');
LEGEND_STATES(:,18) = strpad('Trpn_Ca in component troponin (millimolar)');
LEGEND_CONSTANTS(:,46) = strpad('Trpn_tot in component troponin (millimolar)');
LEGEND_CONSTANTS(:,47) = strpad('alpha_trpn in component troponin (per_millimolar_per_second)');
LEGEND_CONSTANTS(:,48) = strpad('beta_trpn in component troponin (per_second)');
LEGEND_ALGEBRAIC(:,49) = strpad('Force_norm in component Force (dimensionless)');
LEGEND_ALGEBRAIC(:,50) = strpad('dTrpn_Ca_dtime in component troponin (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,51) = strpad('Force in component Force (N_per_mm2)');
LEGEND_CONSTANTS(:,49) = strpad('zeta in component Force (N_per_mm2)');
LEGEND_CONSTANTS(:,69) = strpad('Force_max in component Force (dimensionless)');
LEGEND_CONSTANTS(:,55) = strpad('phi_SL in component Force (dimensionless)');
LEGEND_CONSTANTS(:,66) = strpad('P_1_max in component Force (dimensionless)');
LEGEND_CONSTANTS(:,67) = strpad('P_2_max in component Force (dimensionless)');
LEGEND_CONSTANTS(:,68) = strpad('P_3_max in component Force (dimensionless)');
LEGEND_CONSTANTS(:,65) = strpad('sigma_paths in component Force (dimensionless)');
LEGEND_STATES(:,19) = strpad('N_0 in component Force (dimensionless)');
LEGEND_STATES(:,20) = strpad('P_0 in component Force (dimensionless)');
LEGEND_STATES(:,21) = strpad('P_1 in component Force (dimensionless)');
LEGEND_STATES(:,22) = strpad('P_2 in component Force (dimensionless)');
LEGEND_STATES(:,23) = strpad('P_3 in component Force (dimensionless)');
LEGEND_ALGEBRAIC(:,48) = strpad('N_1 in component Force (dimensionless)');
LEGEND_ALGEBRAIC(:,47) = strpad('alpha_tm in component Force (per_second)');
LEGEND_CONSTANTS(:,50) = strpad('beta_tm in component Force (per_second)');
LEGEND_CONSTANTS(:,58) = strpad('K_tm in component Force (dimensionless)');
LEGEND_CONSTANTS(:,59) = strpad('N_tm in component Force (dimensionless)');
LEGEND_CONSTANTS(:,51) = strpad('SL in component Force (micrometre)');
LEGEND_CONSTANTS(:,56) = strpad('SL_norm in component Force (dimensionless)');
LEGEND_CONSTANTS(:,57) = strpad('f_01 in component Force (per_second)');
LEGEND_CONSTANTS(:,60) = strpad('f_12 in component Force (per_second)');
LEGEND_CONSTANTS(:,64) = strpad('f_23 in component Force (per_second)');
LEGEND_CONSTANTS(:,61) = strpad('g_01 in component Force (per_second)');
LEGEND_CONSTANTS(:,62) = strpad('g_12 in component Force (per_second)');
LEGEND_CONSTANTS(:,63) = strpad('g_23 in component Force (per_second)');
LEGEND_CONSTANTS(:,52) = strpad('f_XB in component Force (per_second)');
LEGEND_CONSTANTS(:,53) = strpad('g_XB in component Force (per_second)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane_potential (millivolt)');
LEGEND_RATES(:,5) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,6) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt x in component time_dependent_rectifier_potassium_current_x_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_RATES(:,10) = strpad('d/dt d in component L_type_Ca_channel_d_gate (dimensionless)');
LEGEND_RATES(:,11) = strpad('d/dt f in component L_type_Ca_channel_f_gate (dimensionless)');
LEGEND_RATES(:,12) = strpad('d/dt F_CaMK in component CaMKII_factor (dimensionless)');
LEGEND_RATES(:,16) = strpad('d/dt F_1 in component RyR (dimensionless)');
LEGEND_RATES(:,17) = strpad('d/dt F_2 in component RyR (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt F_SRCa_RyR in component RyR (millimolar)');
LEGEND_RATES(:,13) = strpad('d/dt Cmdn_Ca in component calmodulin (millimolar)');
LEGEND_RATES(:,18) = strpad('d/dt Trpn_Ca in component troponin (millimolar)');
LEGEND_RATES(:,4) = strpad('d/dt Ca_i in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,14) = strpad('d/dt Ca_SR in component SR_calcium_concentration (millimolar)');
LEGEND_RATES(:,3) = strpad('d/dt Na_i in component intracellular_sodium_concentration (millimolar)');
LEGEND_RATES(:,2) = strpad('d/dt K_i in component intracellular_potassium_concentration (millimolar)');
LEGEND_RATES(:,19) = strpad('d/dt N_0 in component Force (dimensionless)');
LEGEND_RATES(:,20) = strpad('d/dt P_0 in component Force (dimensionless)');
LEGEND_RATES(:,21) = strpad('d/dt P_1 in component Force (dimensionless)');
LEGEND_RATES(:,22) = strpad('d/dt P_2 in component Force (dimensionless)');
LEGEND_RATES(:,23) = strpad('d/dt P_3 in component Force (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 = [];
CONSTANTS(:,1) = 8314.472;
CONSTANTS(:,2) = 310;
CONSTANTS(:,3) = 96485.3415;
CONSTANTS(:,4) = 9.5e-5;
CONSTANTS(:,5) = 1.6404e-5;
CONSTANTS(:,6) = 3.3477e-6;
CONSTANTS(:,7) = 140;
CONSTANTS(:,8) = 4;
CONSTANTS(:,9) = 2;
STATES(:,1) = -92.849333;
CONSTANTS(:,10) = 0;
CONSTANTS(:,11) = 1000;
CONSTANTS(:,12) = 0.5;
CONSTANTS(:,13) = 0.002;
CONSTANTS(:,14) = -4;
STATES(:,2) = 138.22;
STATES(:,3) = 5.8041;
STATES(:,4) = 9.91e-6;
CONSTANTS(:,15) = 2.5;
STATES(:,5) = 0.0013809;
STATES(:,6) = 0.99569;
CONSTANTS(:,16) = 1e-5;
CONSTANTS(:,17) = 0;
CONSTANTS(:,18) = 1;
STATES(:,7) = 5.1127e-2;
CONSTANTS(:,19) = 10;
CONSTANTS(:,20) = 1;
CONSTANTS(:,21) = 0.005;
STATES(:,8) = 0.95854;
STATES(:,9) = 1.5185e-8;
CONSTANTS(:,22) = 0.25;
STATES(:,10) = 1.7908e-8;
STATES(:,11) = 1;
CONSTANTS(:,23) = 3;
CONSTANTS(:,24) = 0.5;
CONSTANTS(:,25) = 0.0005;
CONSTANTS(:,26) = 0.5;
CONSTANTS(:,27) = 1.36;
CONSTANTS(:,28) = 1;
CONSTANTS(:,29) = 21.7;
CONSTANTS(:,30) = 0.00025;
CONSTANTS(:,31) = 0.0006;
CONSTANTS(:,32) = 0.0006;
STATES(:,12) = 1.028;
CONSTANTS(:,33) = 0.8;
STATES(:,13) = 3.9636e-6;
STATES(:,14) = 0.24886;
CONSTANTS(:,34) = 500;
STATES(:,15) = 0.25089;
CONSTANTS(:,35) = 0.05;
CONSTANTS(:,36) = 1;
CONSTANTS(:,37) = 1;
CONSTANTS(:,38) = 1;
CONSTANTS(:,39) = 1;
STATES(:,16) = 0.5268;
STATES(:,17) = 8.7508e-6;
CONSTANTS(:,40) = 0;
CONSTANTS(:,41) = 0.292;
CONSTANTS(:,42) = 0.391;
CONSTANTS(:,43) = 0.02;
CONSTANTS(:,44) = 10000;
CONSTANTS(:,45) = 500;
STATES(:,18) = 2.7661e-4;
CONSTANTS(:,46) = 0.07;
CONSTANTS(:,47) = 80000;
CONSTANTS(:,48) = 200;
CONSTANTS(:,49) = 0.1;
STATES(:,19) = 0.99917;
STATES(:,20) = 9.8593e-5;
STATES(:,21) = 1.3331e-4;
STATES(:,22) = 2.3505e-4;
STATES(:,23) = 1.5349e-4;
CONSTANTS(:,50) = 40;
CONSTANTS(:,51) = 2.15;
CONSTANTS(:,52) = 10;
CONSTANTS(:,53) = 30;
CONSTANTS(:,54) =  CONSTANTS(:,39).*1.80000;
CONSTANTS(:,55) = piecewise({CONSTANTS(:,51)>=1.70000&CONSTANTS(:,51)<=2.00000, (CONSTANTS(:,51) - 0.600000)./1.40000 , CONSTANTS(:,51)>2.00000&CONSTANTS(:,51)<=2.20000, 1.00000 , CONSTANTS(:,51)>2.20000&CONSTANTS(:,51)<=2.30000, (3.60000 - CONSTANTS(:,51))./1.40000 }, NaN);
CONSTANTS(:,56) = (CONSTANTS(:,51) - 1.70000)./0.700000;
CONSTANTS(:,57) =  3.00000.*CONSTANTS(:,52);
CONSTANTS(:,58) = 1.00000./(1.00000+(CONSTANTS(:,48)./CONSTANTS(:,47))./(0.00170000 -  0.000900000.*CONSTANTS(:,56)));
CONSTANTS(:,59) = 3.50000+ 2.50000.*CONSTANTS(:,56);
CONSTANTS(:,60) =  10.0000.*CONSTANTS(:,52);
CONSTANTS(:,61) =  CONSTANTS(:,53).*(2.00000 - CONSTANTS(:,56));
CONSTANTS(:,62) =  2.00000.*CONSTANTS(:,53).*(2.00000 - CONSTANTS(:,56));
CONSTANTS(:,63) =  3.00000.*CONSTANTS(:,53).*(2.00000 - CONSTANTS(:,56));
CONSTANTS(:,64) =  7.00000.*CONSTANTS(:,52);
CONSTANTS(:,65) =  1.00000.*CONSTANTS(:,53).*2.00000.*CONSTANTS(:,53).*3.00000.*CONSTANTS(:,53)+ 1.00000.*CONSTANTS(:,57).*2.00000.*CONSTANTS(:,53).*3.00000.*CONSTANTS(:,53)+ 1.00000.*CONSTANTS(:,57).*1.00000.*CONSTANTS(:,60).*3.00000.*CONSTANTS(:,53)+ 1.00000.*CONSTANTS(:,57).*1.00000.*CONSTANTS(:,60).*1.00000.*CONSTANTS(:,64);
CONSTANTS(:,66) = ( 1.00000.*CONSTANTS(:,57).*2.00000.*CONSTANTS(:,53).*3.00000.*CONSTANTS(:,53))./CONSTANTS(:,65);
CONSTANTS(:,67) = ( 1.00000.*CONSTANTS(:,57).*1.00000.*CONSTANTS(:,60).*3.00000.*CONSTANTS(:,53))./CONSTANTS(:,65);
CONSTANTS(:,68) = ( 1.00000.*CONSTANTS(:,57).*1.00000.*CONSTANTS(:,60).*1.00000.*CONSTANTS(:,64))./CONSTANTS(:,65);
CONSTANTS(:,69) = CONSTANTS(:,66)+ 2.00000.*CONSTANTS(:,67)+ 3.00000.*CONSTANTS(:,68);
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(:,9) =  333.000.*(1.00000./(1.00000+exp( - (STATES(:,1)+4.00000)./5.00000)) - STATES(:,9));
RATES(:,15) = (STATES(:,14) - STATES(:,15))./CONSTANTS(:,35);
RATES(:,13) =  CONSTANTS(:,44).*(CONSTANTS(:,43) - STATES(:,13)).*STATES(:,4) -  CONSTANTS(:,45).*STATES(:,13);
RATES(:,22) =   - (CONSTANTS(:,64)+CONSTANTS(:,62)).*STATES(:,22)+ CONSTANTS(:,60).*STATES(:,21)+ CONSTANTS(:,63).*STATES(:,23);
RATES(:,23) =   - CONSTANTS(:,63).*STATES(:,23)+ CONSTANTS(:,64).*STATES(:,22);
ALGEBRAIC(:,8) = STATES(:,13)./5.00000e-05;
RATES(:,12) = (ALGEBRAIC(:,8) - STATES(:,12))./CONSTANTS(:,33);
ALGEBRAIC(:,3) =  20.0000.*exp(  - 0.125000.*((STATES(:,1)+75.0000) - CONSTANTS(:,17)));
ALGEBRAIC(:,11) = 2000.00./(1.00000+ 320.000.*exp(  - 0.100000.*((STATES(:,1)+75.0000) - CONSTANTS(:,17))));
RATES(:,6) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,6)) -  ALGEBRAIC(:,11).*STATES(:,6);
ALGEBRAIC(:,4) = ( 0.500000.*exp( 0.0826000.*(STATES(:,1)+50.0000)))./(1.00000+exp( 0.0570000.*(STATES(:,1)+50.0000)));
ALGEBRAIC(:,12) = ( 1.30000.*exp(  - 0.0600000.*(STATES(:,1)+20.0000)))./(1.00000+exp(  - 0.0400000.*(STATES(:,1)+20.0000)));
RATES(:,7) =  ALGEBRAIC(:,4).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,12).*STATES(:,7);
ALGEBRAIC(:,5) =  0.0330000.*exp( - STATES(:,1)./17.0000);
ALGEBRAIC(:,13) = 33.0000./(1.00000+exp(  - 0.125000.*(STATES(:,1)+10.0000)));
RATES(:,8) =  ALGEBRAIC(:,5).*(1.00000 - STATES(:,8)) -  ALGEBRAIC(:,13).*STATES(:,8);
ALGEBRAIC(:,2) = STATES(:,1)+41.0000;
ALGEBRAIC(:,10) = piecewise({abs(ALGEBRAIC(:,2))<CONSTANTS(:,16), 2000.00 }, ( 200.000.*ALGEBRAIC(:,2))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,2))));
ALGEBRAIC(:,17) =  8000.00.*exp(  - 0.0560000.*(STATES(:,1)+66.0000));
RATES(:,5) =  ALGEBRAIC(:,10).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,17).*STATES(:,5);
ALGEBRAIC(:,6) = (STATES(:,1)+24.0000) - 5.00000;
ALGEBRAIC(:,14) = piecewise({abs(ALGEBRAIC(:,6))<1.00000e-05,  CONSTANTS(:,23).*120.000 }, ( CONSTANTS(:,23).*30.0000.*ALGEBRAIC(:,6))./(1.00000 - exp( - ALGEBRAIC(:,6)./4.00000)));
ALGEBRAIC(:,18) = piecewise({abs(ALGEBRAIC(:,6))<1.00000e-05,  CONSTANTS(:,23).*120.000 }, ( CONSTANTS(:,23).* - 12.0000.*ALGEBRAIC(:,6))./(1.00000 - exp(ALGEBRAIC(:,6)./10.0000)));
RATES(:,10) =  ALGEBRAIC(:,14).*(1.00000 - STATES(:,10)) -  ALGEBRAIC(:,18).*STATES(:,10);
ALGEBRAIC(:,7) = STATES(:,1)+34.0000;
ALGEBRAIC(:,15) = piecewise({abs(ALGEBRAIC(:,7))<1.00000e-05,  CONSTANTS(:,24).*25.0000 }, ( CONSTANTS(:,24).*6.25000.*ALGEBRAIC(:,7))./( - 1.00000+exp(ALGEBRAIC(:,7)./4.00000)));
ALGEBRAIC(:,19) = ( CONSTANTS(:,24).*50.0000)./(1.00000+exp( - ALGEBRAIC(:,7)./4.00000));
RATES(:,11) =  ALGEBRAIC(:,15).*(1.00000 - STATES(:,11)) -  ALGEBRAIC(:,19).*STATES(:,11);
ALGEBRAIC(:,28) =  (( 0.0100000.*STATES(:,10).*STATES(:,11).*CONSTANTS(:,22).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,7).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,27) =  (( 0.00200000.*STATES(:,10).*STATES(:,11).*CONSTANTS(:,22).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( STATES(:,2).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,8).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,26) =  (( 4.00000.*STATES(:,10).*STATES(:,11).*CONSTANTS(:,22).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp((  - 2.00000.*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( STATES(:,4).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,9).*exp((  - 2.00000.*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,29) = ALGEBRAIC(:,26)+ALGEBRAIC(:,27)+ALGEBRAIC(:,28);
ALGEBRAIC(:,32) =  CONSTANTS(:,36).*( 3.06250e+07.*power(STATES(:,4), 2.00000) -  245.000.*ALGEBRAIC(:,29));
ALGEBRAIC(:,34) = ( CONSTANTS(:,37).*450.000)./(1.00000+0.360000./STATES(:,14));
RATES(:,17) =  ALGEBRAIC(:,32).*STATES(:,16) -  ALGEBRAIC(:,34).*STATES(:,17);
ALGEBRAIC(:,30) = power(STATES(:,12)./0.700000, 2.00000);
ALGEBRAIC(:,35) =  CONSTANTS(:,38).*1.88500.*power(STATES(:,15)./0.220000, ALGEBRAIC(:,30));
ALGEBRAIC(:,39) = 1.00000 - (STATES(:,16)+STATES(:,17));
RATES(:,16) = ( ALGEBRAIC(:,35).*ALGEBRAIC(:,39) -  CONSTANTS(:,54).*STATES(:,16)) -  ALGEBRAIC(:,32).*STATES(:,16);
ALGEBRAIC(:,16) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,8)./STATES(:,2));
ALGEBRAIC(:,24) = ( (( CONSTANTS(:,20).*CONSTANTS(:,8))./(CONSTANTS(:,8)+CONSTANTS(:,19))).*(STATES(:,1) - ALGEBRAIC(:,16)))./(1.00000+exp(( 2.00000.*CONSTANTS(:,3).*((STATES(:,1) - ALGEBRAIC(:,16)) - 10.0000))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,25) =  CONSTANTS(:,21).*STATES(:,8).*STATES(:,9).*(STATES(:,1) - ALGEBRAIC(:,16));
ALGEBRAIC(:,23) = ( CONSTANTS(:,18).*STATES(:,7).*(STATES(:,2) -  CONSTANTS(:,8).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./140.000;
ALGEBRAIC(:,33) = ( (( (( CONSTANTS(:,27).*CONSTANTS(:,8))./(CONSTANTS(:,28)+CONSTANTS(:,8))).*STATES(:,3))./(CONSTANTS(:,29)+STATES(:,3))).*1.00000)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0353000.*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,37) =  CONSTANTS(:,31).*(STATES(:,1) - ALGEBRAIC(:,16));
RATES(:,2) =  - ((ALGEBRAIC(:,24)+ALGEBRAIC(:,23)+ALGEBRAIC(:,25)+ALGEBRAIC(:,37)+ALGEBRAIC(:,27)) -  2.00000.*ALGEBRAIC(:,33))./( CONSTANTS(:,5).*CONSTANTS(:,3));
ALGEBRAIC(:,21) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,7)+ 0.120000.*CONSTANTS(:,8))./(STATES(:,3)+ 0.120000.*STATES(:,2)));
ALGEBRAIC(:,22) =  CONSTANTS(:,15).*power(STATES(:,5), 3.00000).*STATES(:,6).*(STATES(:,1) - ALGEBRAIC(:,21));
ALGEBRAIC(:,31) = ( CONSTANTS(:,25).*( exp(( CONSTANTS(:,26).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), 3.00000).*CONSTANTS(:,9) -  exp(( (CONSTANTS(:,26) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,7), 3.00000).*STATES(:,4)))./(1.00000+STATES(:,4)./0.00690000);
ALGEBRAIC(:,9) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,7)./STATES(:,3));
ALGEBRAIC(:,40) =  CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,9));
ALGEBRAIC(:,20) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,9)./STATES(:,4));
ALGEBRAIC(:,36) =  CONSTANTS(:,30).*(STATES(:,1) - ALGEBRAIC(:,20));
ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,10)&VOI<=CONSTANTS(:,11)&(VOI - CONSTANTS(:,10)) -  floor((VOI - CONSTANTS(:,10))./CONSTANTS(:,12)).*CONSTANTS(:,12)<=CONSTANTS(:,13), CONSTANTS(:,14) }, 0.00000);
RATES(:,1) =  ( - 1.00000./CONSTANTS(:,4)).*(ALGEBRAIC(:,22)+ALGEBRAIC(:,40)+ALGEBRAIC(:,24)+ALGEBRAIC(:,23)+ALGEBRAIC(:,25)+ALGEBRAIC(:,37)+ALGEBRAIC(:,29)+ALGEBRAIC(:,36)+ALGEBRAIC(:,31)+ALGEBRAIC(:,33)+ALGEBRAIC(:,1));
RATES(:,3) =  - (ALGEBRAIC(:,22)+ALGEBRAIC(:,40)+ALGEBRAIC(:,28)+ 3.00000.*ALGEBRAIC(:,31)+ 3.00000.*ALGEBRAIC(:,33))./( CONSTANTS(:,5).*CONSTANTS(:,3));
ALGEBRAIC(:,41) = ( CONSTANTS(:,34).*STATES(:,15))./(STATES(:,15)+0.200000);
ALGEBRAIC(:,38) = power(STATES(:,17)./(STATES(:,17)+0.250000), 2.00000);
ALGEBRAIC(:,42) =  ( ALGEBRAIC(:,41).*ALGEBRAIC(:,38)+CONSTANTS(:,40)).*(STATES(:,14) - STATES(:,4));
ALGEBRAIC(:,43) = power(STATES(:,4)./0.000240000, 2.00000);
ALGEBRAIC(:,44) = power(STATES(:,14)./1.64000, 2.00000);
ALGEBRAIC(:,45) = ( STATES(:,12).*CONSTANTS(:,41).*ALGEBRAIC(:,43) -  CONSTANTS(:,42).*ALGEBRAIC(:,44))./(1.00000+ALGEBRAIC(:,43)+ALGEBRAIC(:,44));
RATES(:,14) = ( ALGEBRAIC(:,45).*CONSTANTS(:,5))./CONSTANTS(:,6) - ALGEBRAIC(:,42);
ALGEBRAIC(:,47) =  CONSTANTS(:,50).*power(STATES(:,18)./( CONSTANTS(:,46).*CONSTANTS(:,58)), CONSTANTS(:,59));
RATES(:,20) =   - (CONSTANTS(:,50)+CONSTANTS(:,57)).*STATES(:,20)+ ALGEBRAIC(:,47).*STATES(:,19)+ CONSTANTS(:,61).*STATES(:,21);
ALGEBRAIC(:,48) = 1.00000 - (STATES(:,19)+STATES(:,20)+STATES(:,21)+STATES(:,22)+STATES(:,23));
RATES(:,19) = ( CONSTANTS(:,50).*STATES(:,20) -  ALGEBRAIC(:,47).*STATES(:,19))+ CONSTANTS(:,61).*ALGEBRAIC(:,48);
RATES(:,21) =   - (CONSTANTS(:,50)+CONSTANTS(:,60)+CONSTANTS(:,61)).*STATES(:,21)+ ALGEBRAIC(:,47).*ALGEBRAIC(:,48)+ CONSTANTS(:,57).*STATES(:,20)+ CONSTANTS(:,62).*STATES(:,22);
ALGEBRAIC(:,49) = ( CONSTANTS(:,55).*(STATES(:,21)+ALGEBRAIC(:,48)+ 2.00000.*STATES(:,22)+ 3.00000.*STATES(:,23)))./CONSTANTS(:,69);
RATES(:,18) =  CONSTANTS(:,47).*(CONSTANTS(:,46) - STATES(:,18)).*STATES(:,4) -  (( CONSTANTS(:,48).*(1.00000+ 2.00000.*(1.00000 - ALGEBRAIC(:,49))))./3.00000).*STATES(:,18);
ALGEBRAIC(:,46) =  CONSTANTS(:,44).*(CONSTANTS(:,43) - STATES(:,13)).*STATES(:,4) -  CONSTANTS(:,45).*STATES(:,13);
ALGEBRAIC(:,50) =  CONSTANTS(:,47).*(CONSTANTS(:,46) - STATES(:,18)).*STATES(:,4) -  (( CONSTANTS(:,48).*(1.00000+ 2.00000.*(1.00000 - ALGEBRAIC(:,49))))./3.00000).*STATES(:,18);
RATES(:,4) = ((( - ((ALGEBRAIC(:,26)+ALGEBRAIC(:,36)) -  2.00000.*ALGEBRAIC(:,31))./( 2.00000.*CONSTANTS(:,5).*CONSTANTS(:,3)) - ALGEBRAIC(:,45))+( ALGEBRAIC(:,42).*CONSTANTS(:,6))./CONSTANTS(:,5)) - ALGEBRAIC(:,46)) - ALGEBRAIC(:,50);
RATES = RATES';
end

% Calculate algebraic variables
function ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI)
statesSize = size(STATES);
statesColumnCount = statesSize(2);
if ( statesColumnCount == 1)
STATES = STATES';
utilOnes = 1;
else
statesRowCount = statesSize(1);
utilOnes = ones(statesRowCount, 1);
end
ALGEBRAIC(:,8) = STATES(:,13)./5.00000e-05;
ALGEBRAIC(:,3) =  20.0000.*exp(  - 0.125000.*((STATES(:,1)+75.0000) - CONSTANTS(:,17)));
ALGEBRAIC(:,11) = 2000.00./(1.00000+ 320.000.*exp(  - 0.100000.*((STATES(:,1)+75.0000) - CONSTANTS(:,17))));
ALGEBRAIC(:,4) = ( 0.500000.*exp( 0.0826000.*(STATES(:,1)+50.0000)))./(1.00000+exp( 0.0570000.*(STATES(:,1)+50.0000)));
ALGEBRAIC(:,12) = ( 1.30000.*exp(  - 0.0600000.*(STATES(:,1)+20.0000)))./(1.00000+exp(  - 0.0400000.*(STATES(:,1)+20.0000)));
ALGEBRAIC(:,5) =  0.0330000.*exp( - STATES(:,1)./17.0000);
ALGEBRAIC(:,13) = 33.0000./(1.00000+exp(  - 0.125000.*(STATES(:,1)+10.0000)));
ALGEBRAIC(:,2) = STATES(:,1)+41.0000;
ALGEBRAIC(:,10) = piecewise({abs(ALGEBRAIC(:,2))<CONSTANTS(:,16), 2000.00 }, ( 200.000.*ALGEBRAIC(:,2))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,2))));
ALGEBRAIC(:,17) =  8000.00.*exp(  - 0.0560000.*(STATES(:,1)+66.0000));
ALGEBRAIC(:,6) = (STATES(:,1)+24.0000) - 5.00000;
ALGEBRAIC(:,14) = piecewise({abs(ALGEBRAIC(:,6))<1.00000e-05,  CONSTANTS(:,23).*120.000 }, ( CONSTANTS(:,23).*30.0000.*ALGEBRAIC(:,6))./(1.00000 - exp( - ALGEBRAIC(:,6)./4.00000)));
ALGEBRAIC(:,18) = piecewise({abs(ALGEBRAIC(:,6))<1.00000e-05,  CONSTANTS(:,23).*120.000 }, ( CONSTANTS(:,23).* - 12.0000.*ALGEBRAIC(:,6))./(1.00000 - exp(ALGEBRAIC(:,6)./10.0000)));
ALGEBRAIC(:,7) = STATES(:,1)+34.0000;
ALGEBRAIC(:,15) = piecewise({abs(ALGEBRAIC(:,7))<1.00000e-05,  CONSTANTS(:,24).*25.0000 }, ( CONSTANTS(:,24).*6.25000.*ALGEBRAIC(:,7))./( - 1.00000+exp(ALGEBRAIC(:,7)./4.00000)));
ALGEBRAIC(:,19) = ( CONSTANTS(:,24).*50.0000)./(1.00000+exp( - ALGEBRAIC(:,7)./4.00000));
ALGEBRAIC(:,28) =  (( 0.0100000.*STATES(:,10).*STATES(:,11).*CONSTANTS(:,22).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,7).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,27) =  (( 0.00200000.*STATES(:,10).*STATES(:,11).*CONSTANTS(:,22).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( STATES(:,2).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,8).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,26) =  (( 4.00000.*STATES(:,10).*STATES(:,11).*CONSTANTS(:,22).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2).*(1.00000 - exp((  - 2.00000.*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))).*( STATES(:,4).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,9).*exp((  - 2.00000.*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,29) = ALGEBRAIC(:,26)+ALGEBRAIC(:,27)+ALGEBRAIC(:,28);
ALGEBRAIC(:,32) =  CONSTANTS(:,36).*( 3.06250e+07.*power(STATES(:,4), 2.00000) -  245.000.*ALGEBRAIC(:,29));
ALGEBRAIC(:,34) = ( CONSTANTS(:,37).*450.000)./(1.00000+0.360000./STATES(:,14));
ALGEBRAIC(:,30) = power(STATES(:,12)./0.700000, 2.00000);
ALGEBRAIC(:,35) =  CONSTANTS(:,38).*1.88500.*power(STATES(:,15)./0.220000, ALGEBRAIC(:,30));
ALGEBRAIC(:,39) = 1.00000 - (STATES(:,16)+STATES(:,17));
ALGEBRAIC(:,16) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,8)./STATES(:,2));
ALGEBRAIC(:,24) = ( (( CONSTANTS(:,20).*CONSTANTS(:,8))./(CONSTANTS(:,8)+CONSTANTS(:,19))).*(STATES(:,1) - ALGEBRAIC(:,16)))./(1.00000+exp(( 2.00000.*CONSTANTS(:,3).*((STATES(:,1) - ALGEBRAIC(:,16)) - 10.0000))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,25) =  CONSTANTS(:,21).*STATES(:,8).*STATES(:,9).*(STATES(:,1) - ALGEBRAIC(:,16));
ALGEBRAIC(:,23) = ( CONSTANTS(:,18).*STATES(:,7).*(STATES(:,2) -  CONSTANTS(:,8).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./140.000;
ALGEBRAIC(:,33) = ( (( (( CONSTANTS(:,27).*CONSTANTS(:,8))./(CONSTANTS(:,28)+CONSTANTS(:,8))).*STATES(:,3))./(CONSTANTS(:,29)+STATES(:,3))).*1.00000)./(1.00000+ 0.124500.*exp((  - 0.100000.*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))+ 0.0353000.*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,37) =  CONSTANTS(:,31).*(STATES(:,1) - ALGEBRAIC(:,16));
ALGEBRAIC(:,21) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,7)+ 0.120000.*CONSTANTS(:,8))./(STATES(:,3)+ 0.120000.*STATES(:,2)));
ALGEBRAIC(:,22) =  CONSTANTS(:,15).*power(STATES(:,5), 3.00000).*STATES(:,6).*(STATES(:,1) - ALGEBRAIC(:,21));
ALGEBRAIC(:,31) = ( CONSTANTS(:,25).*( exp(( CONSTANTS(:,26).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,3), 3.00000).*CONSTANTS(:,9) -  exp(( (CONSTANTS(:,26) - 1.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,7), 3.00000).*STATES(:,4)))./(1.00000+STATES(:,4)./0.00690000);
ALGEBRAIC(:,9) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,7)./STATES(:,3));
ALGEBRAIC(:,40) =  CONSTANTS(:,32).*(STATES(:,1) - ALGEBRAIC(:,9));
ALGEBRAIC(:,20) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,9)./STATES(:,4));
ALGEBRAIC(:,36) =  CONSTANTS(:,30).*(STATES(:,1) - ALGEBRAIC(:,20));
ALGEBRAIC(:,1) = piecewise({VOI>=CONSTANTS(:,10)&VOI<=CONSTANTS(:,11)&(VOI - CONSTANTS(:,10)) -  floor((VOI - CONSTANTS(:,10))./CONSTANTS(:,12)).*CONSTANTS(:,12)<=CONSTANTS(:,13), CONSTANTS(:,14) }, 0.00000);
ALGEBRAIC(:,41) = ( CONSTANTS(:,34).*STATES(:,15))./(STATES(:,15)+0.200000);
ALGEBRAIC(:,38) = power(STATES(:,17)./(STATES(:,17)+0.250000), 2.00000);
ALGEBRAIC(:,42) =  ( ALGEBRAIC(:,41).*ALGEBRAIC(:,38)+CONSTANTS(:,40)).*(STATES(:,14) - STATES(:,4));
ALGEBRAIC(:,43) = power(STATES(:,4)./0.000240000, 2.00000);
ALGEBRAIC(:,44) = power(STATES(:,14)./1.64000, 2.00000);
ALGEBRAIC(:,45) = ( STATES(:,12).*CONSTANTS(:,41).*ALGEBRAIC(:,43) -  CONSTANTS(:,42).*ALGEBRAIC(:,44))./(1.00000+ALGEBRAIC(:,43)+ALGEBRAIC(:,44));
ALGEBRAIC(:,47) =  CONSTANTS(:,50).*power(STATES(:,18)./( CONSTANTS(:,46).*CONSTANTS(:,58)), CONSTANTS(:,59));
ALGEBRAIC(:,48) = 1.00000 - (STATES(:,19)+STATES(:,20)+STATES(:,21)+STATES(:,22)+STATES(:,23));
ALGEBRAIC(:,49) = ( CONSTANTS(:,55).*(STATES(:,21)+ALGEBRAIC(:,48)+ 2.00000.*STATES(:,22)+ 3.00000.*STATES(:,23)))./CONSTANTS(:,69);
ALGEBRAIC(:,46) =  CONSTANTS(:,44).*(CONSTANTS(:,43) - STATES(:,13)).*STATES(:,4) -  CONSTANTS(:,45).*STATES(:,13);
ALGEBRAIC(:,50) =  CONSTANTS(:,47).*(CONSTANTS(:,46) - STATES(:,18)).*STATES(:,4) -  (( CONSTANTS(:,48).*(1.00000+ 2.00000.*(1.00000 - ALGEBRAIC(:,49))))./3.00000).*STATES(:,18);
ALGEBRAIC(:,51) =  CONSTANTS(:,49).*ALGEBRAIC(:,49);
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 Iribe, Kohl, Noble, 2006 at changeset 78cd0f4ae9b3.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: