# 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 =52;
end
% There are a total of 21 entries in each of the rate and state variable arrays.
% There are a total of 70 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 (millijoule_per_mole_kelvin)');
LEGEND_CONSTANTS(:,2) = strpad('T in component membrane (kelvin)');
LEGEND_CONSTANTS(:,3) = strpad('F in component membrane (coulomb_per_mole)');
LEGEND_CONSTANTS(:,4) = strpad('Cm in component membrane (microF)');
LEGEND_ALGEBRAIC(:,27) = strpad('i_K1 in component time_independent_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,44) = strpad('i_to in component transient_outward_current (nanoA)');
LEGEND_ALGEBRAIC(:,31) = strpad('i_K in component time_dependent_potassium_current (nanoA)');
LEGEND_ALGEBRAIC(:,37) = strpad('i_Ca_L_K_cyt in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,40) = strpad('i_Ca_L_K_ds in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,45) = strpad('i_NaK in component sodium_potassium_pump (nanoA)');
LEGEND_ALGEBRAIC(:,33) = strpad('i_Na in component fast_sodium_current (nanoA)');
LEGEND_ALGEBRAIC(:,34) = strpad('i_b_Na in component sodium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,38) = strpad('i_Ca_L_Na_cyt in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,41) = strpad('i_Ca_L_Na_ds in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,46) = strpad('i_NaCa_cyt in component sodium_calcium_exchanger (nanoA)');
LEGEND_ALGEBRAIC(:,47) = strpad('i_NaCa_ds in component sodium_calcium_exchanger (nanoA)');
LEGEND_ALGEBRAIC(:,36) = strpad('i_Ca_L_Ca_cyt in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,39) = strpad('i_Ca_L_Ca_ds in component L_type_Ca_channel (nanoA)');
LEGEND_ALGEBRAIC(:,43) = strpad('i_b_Ca in component calcium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,35) = strpad('i_b_K in component potassium_background_current (nanoA)');
LEGEND_ALGEBRAIC(:,7) = strpad('i_Stim in component membrane (nanoA)');
LEGEND_CONSTANTS(:,5) = strpad('stim_start in component membrane (second)');
LEGEND_CONSTANTS(:,6) = strpad('stim_end in component membrane (second)');
LEGEND_CONSTANTS(:,7) = strpad('stim_period in component membrane (second)');
LEGEND_CONSTANTS(:,8) = strpad('stim_duration in component membrane (second)');
LEGEND_CONSTANTS(:,9) = strpad('stim_amplitude in component membrane (nanoA)');
LEGEND_ALGEBRAIC(:,15) = strpad('E_Na in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,21) = strpad('E_K in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,23) = strpad('E_Ca in component reversal_potentials (millivolt)');
LEGEND_ALGEBRAIC(:,25) = strpad('E_mh in component reversal_potentials (millivolt)');
LEGEND_STATES(:,2) = strpad('K_o in component extracellular_potassium_concentration (millimolar)');
LEGEND_CONSTANTS(:,10) = strpad('Na_o in component extracellular_sodium_concentration (millimolar)');
LEGEND_STATES(:,3) = strpad('K_i in component intracellular_potassium_concentration (millimolar)');
LEGEND_STATES(:,4) = strpad('Na_i in component intracellular_sodium_concentration (millimolar)');
LEGEND_CONSTANTS(:,11) = strpad('Ca_o in component extracellular_calcium_concentration (millimolar)');
LEGEND_STATES(:,5) = strpad('Ca_i in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,12) = strpad('K_mk1 in component time_independent_potassium_current (millimolar)');
LEGEND_CONSTANTS(:,13) = strpad('g_K1 in component time_independent_potassium_current (microS)');
LEGEND_ALGEBRAIC(:,29) = strpad('I_K in component time_dependent_potassium_current (nanoA)');
LEGEND_CONSTANTS(:,14) = strpad('i_K_max in component time_dependent_potassium_current (nanoA)');
LEGEND_STATES(:,6) = strpad('x in component time_dependent_potassium_current_x_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,9) = strpad('alpha_x in component time_dependent_potassium_current_x_gate (per_second)');
LEGEND_ALGEBRAIC(:,17) = strpad('beta_x in component time_dependent_potassium_current_x_gate (per_second)');
LEGEND_CONSTANTS(:,15) = strpad('delta_x in component time_dependent_potassium_current_x_gate (millivolt)');
LEGEND_ALGEBRAIC(:,1) = strpad('E0_x in component time_dependent_potassium_current_x_gate (millivolt)');
LEGEND_CONSTANTS(:,16) = strpad('g_Na in component fast_sodium_current (microS)');
LEGEND_STATES(:,7) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,8) = 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(:,18) = strpad('beta_m in component fast_sodium_current_m_gate (per_second)');
LEGEND_CONSTANTS(:,17) = 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(:,18) = strpad('shift_h in component fast_sodium_current_h_gate (millivolt)');
LEGEND_CONSTANTS(:,19) = strpad('g_bna in component sodium_background_current (microS)');
LEGEND_CONSTANTS(:,20) = strpad('g_bk in component potassium_background_current (microS)');
LEGEND_ALGEBRAIC(:,42) = strpad('i_Ca_L in component L_type_Ca_channel (nanoA)');
LEGEND_CONSTANTS(:,21) = strpad('P_Ca_L in component L_type_Ca_channel (nanoA_per_millimolar)');
LEGEND_CONSTANTS(:,22) = strpad('P_CaK in component L_type_Ca_channel (dimensionless)');
LEGEND_CONSTANTS(:,23) = strpad('P_CaNa in component L_type_Ca_channel (dimensionless)');
LEGEND_STATES(:,9) = strpad('Ca_ds in component intracellular_calcium_concentration (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_STATES(:,12) = strpad('f2 in component L_type_Ca_channel_f2_gate (dimensionless)');
LEGEND_STATES(:,13) = strpad('f2ds in component L_type_Ca_channel_f2ds_gate (dimensionless)');
LEGEND_CONSTANTS(:,24) = strpad('Km_f2 in component L_type_Ca_channel (millimolar)');
LEGEND_CONSTANTS(:,25) = strpad('Km_f2ds in component L_type_Ca_channel (millimolar)');
LEGEND_CONSTANTS(:,26) = strpad('R_decay in component L_type_Ca_channel (per_second)');
LEGEND_CONSTANTS(:,27) = strpad('FrICa in component L_type_Ca_channel (dimensionless)');
LEGEND_ALGEBRAIC(:,12) = strpad('alpha_d in component L_type_Ca_channel_d_gate (per_second)');
LEGEND_ALGEBRAIC(:,19) = strpad('beta_d in component L_type_Ca_channel_d_gate (per_second)');
LEGEND_ALGEBRAIC(:,4) = strpad('E0_d in component L_type_Ca_channel_d_gate (millivolt)');
LEGEND_CONSTANTS(:,28) = strpad('speed_d in component L_type_Ca_channel_d_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,13) = strpad('alpha_f in component L_type_Ca_channel_f_gate (per_second)');
LEGEND_ALGEBRAIC(:,20) = strpad('beta_f in component L_type_Ca_channel_f_gate (per_second)');
LEGEND_CONSTANTS(:,29) = strpad('speed_f in component L_type_Ca_channel_f_gate (dimensionless)');
LEGEND_CONSTANTS(:,30) = strpad('delta_f in component L_type_Ca_channel_f_gate (millivolt)');
LEGEND_ALGEBRAIC(:,5) = strpad('E0_f in component L_type_Ca_channel_f_gate (millivolt)');
LEGEND_CONSTANTS(:,31) = strpad('g_bca in component calcium_background_current (microS)');
LEGEND_CONSTANTS(:,32) = strpad('g_to in component transient_outward_current (microS)');
LEGEND_CONSTANTS(:,33) = strpad('g_tos in component transient_outward_current (dimensionless)');
LEGEND_STATES(:,14) = strpad('s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_STATES(:,15) = strpad('r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,6) = strpad('alpha_s in component transient_outward_current_s_gate (per_second)');
LEGEND_ALGEBRAIC(:,14) = strpad('beta_s in component transient_outward_current_s_gate (per_second)');
LEGEND_CONSTANTS(:,34) = strpad('i_NaK_max in component sodium_potassium_pump (nanoA)');
LEGEND_CONSTANTS(:,35) = strpad('K_mK in component sodium_potassium_pump (millimolar)');
LEGEND_CONSTANTS(:,36) = strpad('K_mNa in component sodium_potassium_pump (millimolar)');
LEGEND_ALGEBRAIC(:,49) = strpad('i_NaCa in component sodium_calcium_exchanger (nanoA)');
LEGEND_CONSTANTS(:,37) = strpad('k_NaCa in component sodium_calcium_exchanger (nanoA)');
LEGEND_CONSTANTS(:,38) = strpad('n_NaCa in component sodium_calcium_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,39) = strpad('d_NaCa in component sodium_calcium_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,40) = strpad('gamma in component sodium_calcium_exchanger (dimensionless)');
LEGEND_CONSTANTS(:,41) = strpad('FRiNaCa in component sodium_calcium_exchanger (dimensionless)');
LEGEND_ALGEBRAIC(:,50) = strpad('i_up in component sarcoplasmic_reticulum_calcium_pump (millimolar_per_second)');
LEGEND_CONSTANTS(:,67) = strpad('K_1 in component sarcoplasmic_reticulum_calcium_pump (dimensionless)');
LEGEND_ALGEBRAIC(:,48) = strpad('K_2 in component sarcoplasmic_reticulum_calcium_pump (millimolar)');
LEGEND_CONSTANTS(:,42) = strpad('K_cyca in component sarcoplasmic_reticulum_calcium_pump (millimolar)');
LEGEND_CONSTANTS(:,43) = strpad('K_xcs in component sarcoplasmic_reticulum_calcium_pump (dimensionless)');
LEGEND_CONSTANTS(:,44) = strpad('K_srca in component sarcoplasmic_reticulum_calcium_pump (millimolar)');
LEGEND_CONSTANTS(:,45) = strpad('alpha_up in component sarcoplasmic_reticulum_calcium_pump (millimolar_per_second)');
LEGEND_CONSTANTS(:,46) = strpad('beta_up in component sarcoplasmic_reticulum_calcium_pump (millimolar_per_second)');
LEGEND_STATES(:,16) = strpad('Ca_up in component intracellular_calcium_concentration (millimolar)');
LEGEND_ALGEBRAIC(:,51) = strpad('i_trans in component calcium_translocation (millimolar_per_second)');
LEGEND_STATES(:,17) = strpad('Ca_rel in component intracellular_calcium_concentration (millimolar)');
LEGEND_ALGEBRAIC(:,52) = strpad('i_rel in component calcium_release (millimolar_per_second)');
LEGEND_ALGEBRAIC(:,8) = strpad('VoltDep in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,24) = strpad('RegBindSite in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,16) = strpad('CaiReg in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,26) = strpad('ActRate in component calcium_release (per_second)');
LEGEND_ALGEBRAIC(:,28) = strpad('InactRate in component calcium_release (per_second)');
LEGEND_CONSTANTS(:,47) = strpad('K_leak_rate in component calcium_release (per_second)');
LEGEND_CONSTANTS(:,48) = strpad('K_m_rel in component calcium_release (per_second)');
LEGEND_CONSTANTS(:,49) = strpad('K_m_Ca_cyt in component calcium_release (millimolar)');
LEGEND_CONSTANTS(:,50) = strpad('K_m_Ca_ds in component calcium_release (millimolar)');
LEGEND_ALGEBRAIC(:,32) = strpad('PrecFrac in component calcium_release (dimensionless)');
LEGEND_STATES(:,18) = strpad('ActFrac in component calcium_release (dimensionless)');
LEGEND_STATES(:,19) = strpad('ProdFrac in component calcium_release (dimensionless)');
LEGEND_ALGEBRAIC(:,30) = strpad('SpeedRel in component calcium_release (dimensionless)');
LEGEND_CONSTANTS(:,70) = strpad('V_i in component intracellular_calcium_concentration (micrometre3)');
LEGEND_CONSTANTS(:,51) = strpad('K_b in component extracellular_potassium_concentration (millimolar)');
LEGEND_CONSTANTS(:,52) = strpad('pf in component extracellular_potassium_concentration (per_second)');
LEGEND_CONSTANTS(:,69) = strpad('V_e in component intracellular_calcium_concentration (micrometre3)');
LEGEND_STATES(:,20) = strpad('Ca_Calmod in component intracellular_calcium_concentration (millimolar)');
LEGEND_STATES(:,21) = strpad('Ca_Trop in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,53) = strpad('Calmod in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,54) = strpad('Trop in component intracellular_calcium_concentration (millimolar)');
LEGEND_CONSTANTS(:,55) = strpad('alpha_Calmod in component intracellular_calcium_concentration (per_millimolar_second)');
LEGEND_CONSTANTS(:,56) = strpad('beta_Calmod in component intracellular_calcium_concentration (per_second)');
LEGEND_CONSTANTS(:,57) = strpad('alpha_Trop in component intracellular_calcium_concentration (per_millimolar_second)');
LEGEND_CONSTANTS(:,58) = strpad('beta_Trop in component intracellular_calcium_concentration (per_second)');
LEGEND_CONSTANTS(:,60) = strpad('length in component intracellular_calcium_concentration (micrometre)');
LEGEND_CONSTANTS(:,66) = strpad('V_Cell in component intracellular_calcium_concentration (micrometre3)');
LEGEND_CONSTANTS(:,68) = strpad('V_i_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,61) = strpad('V_ds_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,62) = strpad('V_rel_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,63) = strpad('V_e_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,64) = strpad('V_up_ratio in component intracellular_calcium_concentration (dimensionless)');
LEGEND_CONSTANTS(:,65) = strpad('Kdecay in component intracellular_calcium_concentration (per_second)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,6) = strpad('d/dt x in component time_dependent_potassium_current_x_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt h in component fast_sodium_current_h_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 f2 in component L_type_Ca_channel_f2_gate (dimensionless)');
LEGEND_RATES(:,13) = strpad('d/dt f2ds in component L_type_Ca_channel_f2ds_gate (dimensionless)');
LEGEND_RATES(:,14) = strpad('d/dt s in component transient_outward_current_s_gate (dimensionless)');
LEGEND_RATES(:,15) = strpad('d/dt r in component transient_outward_current_r_gate (dimensionless)');
LEGEND_RATES(:,18) = strpad('d/dt ActFrac in component calcium_release (dimensionless)');
LEGEND_RATES(:,19) = strpad('d/dt ProdFrac in component calcium_release (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt Na_i in component intracellular_sodium_concentration (millimolar)');
LEGEND_RATES(:,2) = strpad('d/dt K_o in component extracellular_potassium_concentration (millimolar)');
LEGEND_RATES(:,3) = strpad('d/dt K_i in component intracellular_potassium_concentration (millimolar)');
LEGEND_RATES(:,5) = strpad('d/dt Ca_i in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,20) = strpad('d/dt Ca_Calmod in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,21) = strpad('d/dt Ca_Trop in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,9) = strpad('d/dt Ca_ds in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,16) = strpad('d/dt Ca_up in component intracellular_calcium_concentration (millimolar)');
LEGEND_RATES(:,17) = strpad('d/dt Ca_rel in component intracellular_calcium_concentration (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) = -86.27784;
CONSTANTS(:,1) = 8314.472;
CONSTANTS(:,2) = 310;
CONSTANTS(:,3) = 96485.3415;
CONSTANTS(:,4) = 9.5e-5;
CONSTANTS(:,5) = 0.02;
CONSTANTS(:,6) = 9;
CONSTANTS(:,7) = 0.5;
CONSTANTS(:,8) = 0.002;
CONSTANTS(:,9) = -1.8;
STATES(:,2) = 5.3201028;
CONSTANTS(:,10) = 148.5;
STATES(:,3) = 140.1333;
STATES(:,4) = 6.835;
CONSTANTS(:,11) = 2.5;
STATES(:,5) = 7.07933e-5;
CONSTANTS(:,12) = 10;
CONSTANTS(:,13) = 0.12;
CONSTANTS(:,14) = 1.5;
STATES(:,6) = 2.3455e-6;
CONSTANTS(:,15) = 0.0001;
CONSTANTS(:,16) = 0.6;
STATES(:,7) = 0.003956;
STATES(:,8) = 0.9759885;
CONSTANTS(:,17) = 1e-5;
CONSTANTS(:,18) = 0;
CONSTANTS(:,19) = 0.0001;
CONSTANTS(:,20) = 0.004;
CONSTANTS(:,21) = 0.06;
CONSTANTS(:,22) = 0.003;
CONSTANTS(:,23) = 0.01;
STATES(:,9) = 0.0008364;
STATES(:,10) = 3.06884e-12;
STATES(:,11) = 0.9999977;
STATES(:,12) = 0.994096;
STATES(:,13) = 0.4387865;
CONSTANTS(:,24) = 100000;
CONSTANTS(:,25) = 0.001;
CONSTANTS(:,26) = 20;
CONSTANTS(:,27) = 1;
CONSTANTS(:,28) = 10;
CONSTANTS(:,29) = 2;
CONSTANTS(:,30) = 0.0001;
CONSTANTS(:,31) = 0.00025;
CONSTANTS(:,32) = 0.08;
CONSTANTS(:,33) = 0.15;
STATES(:,14) = 0.954689;
STATES(:,15) = 2.4223e-5;
CONSTANTS(:,34) = 0.7;
CONSTANTS(:,35) = 1;
CONSTANTS(:,36) = 40;
CONSTANTS(:,37) = 0.0002;
CONSTANTS(:,38) = 3;
CONSTANTS(:,39) = 0.005;
CONSTANTS(:,40) = 0.5;
CONSTANTS(:,41) = 0.001;
CONSTANTS(:,42) = 0.0003;
CONSTANTS(:,43) = 0.4;
CONSTANTS(:,44) = 0.5;
CONSTANTS(:,45) = 0.4;
CONSTANTS(:,46) = 0.03;
STATES(:,16) = 0.479749;
STATES(:,17) = 0.43984;
CONSTANTS(:,47) = 0.05;
CONSTANTS(:,48) = 250;
CONSTANTS(:,49) = 0.0005;
CONSTANTS(:,50) = 0.01;
STATES(:,18) = 0.0113161;
STATES(:,19) = 0.9402563;
CONSTANTS(:,51) = 5.4;
CONSTANTS(:,52) = 0.7;
STATES(:,20) = 0.0024448;
STATES(:,21) = 0.0017012;
CONSTANTS(:,53) = 0.02;
CONSTANTS(:,54) = 0.05;
CONSTANTS(:,55) = 100000;
CONSTANTS(:,56) = 50;
CONSTANTS(:,57) = 100000;
CONSTANTS(:,58) = 200;
CONSTANTS(:,59) = 12;
CONSTANTS(:,60) = 74;
CONSTANTS(:,61) = 0.1;
CONSTANTS(:,62) = 0.1;
CONSTANTS(:,63) = 0.4;
CONSTANTS(:,64) = 0.01;
CONSTANTS(:,65) = 10;
CONSTANTS(:,66) = ( 3.14159.*power(CONSTANTS(:,59)./1000.00, 2.00000).*CONSTANTS(:,60))./1000.00;
CONSTANTS(:,67) = ( CONSTANTS(:,42).*CONSTANTS(:,43))./CONSTANTS(:,44);
CONSTANTS(:,68) = ((1.00000 - CONSTANTS(:,63)) - CONSTANTS(:,64)) - CONSTANTS(:,62);
CONSTANTS(:,69) =  CONSTANTS(:,66).*CONSTANTS(:,63);
CONSTANTS(:,70) =  CONSTANTS(:,66).*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(:,12) = 1.00000 -  1.00000.*(STATES(:,5)./(CONSTANTS(:,24)+STATES(:,5))+STATES(:,12));
RATES(:,13) =  CONSTANTS(:,26).*(1.00000 - (STATES(:,9)./(CONSTANTS(:,25)+STATES(:,9))+STATES(:,13)));
RATES(:,15) =  333.000.*(1.00000./(1.00000+exp( - ((STATES(:,1)+4.00000) - 24.0000)./10.0000)) - STATES(:,15));
ALGEBRAIC(:,3) =  20.0000.*exp(  - 0.125000.*((STATES(:,1)+75.0000) - CONSTANTS(:,18)));
ALGEBRAIC(:,11) = 2000.00./(1.00000+ 320.000.*exp(  - 0.100000.*((STATES(:,1)+75.0000) - CONSTANTS(:,18))));
RATES(:,8) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,8)) -  ALGEBRAIC(:,11).*STATES(:,8);
ALGEBRAIC(:,6) =  0.260000.*0.0330000.*exp( - STATES(:,1)./14.8750);
ALGEBRAIC(:,14) = ( 0.260000.*33.0000)./(1.00000+exp( - (STATES(:,1)+10.0000)./7.00000));
RATES(:,14) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,14)) -  ALGEBRAIC(:,14).*STATES(:,14);
ALGEBRAIC(:,1) = (STATES(:,1)+22.0000) - 40.0000;
ALGEBRAIC(:,9) = piecewise({abs(ALGEBRAIC(:,1))<CONSTANTS(:,15), 2.50000 }, ( 3.00000.*0.500000.*ALGEBRAIC(:,1))./(1.00000 - exp( - ALGEBRAIC(:,1)./5.00000)));
ALGEBRAIC(:,17) = piecewise({abs(ALGEBRAIC(:,1))<CONSTANTS(:,15), 2.50000 }, ( 3.00000.*0.178000.*ALGEBRAIC(:,1))./(exp(ALGEBRAIC(:,1)./15.0000) - 1.00000));
RATES(:,6) =  ALGEBRAIC(:,9).*(1.00000 - STATES(:,6)) -  ALGEBRAIC(:,17).*STATES(:,6);
ALGEBRAIC(:,2) = STATES(:,1)+41.0000;
ALGEBRAIC(:,10) = piecewise({abs(ALGEBRAIC(:,2))<CONSTANTS(:,17), 2000.00 }, ( 200.000.*ALGEBRAIC(:,2))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,2))));
ALGEBRAIC(:,18) =  8000.00.*exp(  - 0.0560000.*(STATES(:,1)+66.0000));
RATES(:,7) =  ALGEBRAIC(:,10).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,18).*STATES(:,7);
ALGEBRAIC(:,4) = (STATES(:,1)+24.0000) - 20.0000;
ALGEBRAIC(:,12) = piecewise({abs(ALGEBRAIC(:,4))<0.000100000, 120.000 }, ( 30.0000.*ALGEBRAIC(:,4))./(1.00000 - exp( - ALGEBRAIC(:,4)./3.00000)));
ALGEBRAIC(:,19) = piecewise({abs(ALGEBRAIC(:,4))<0.000100000, 120.000 }, ( 12.0000.*ALGEBRAIC(:,4))./(exp(ALGEBRAIC(:,4)./7.50000) - 1.00000));
RATES(:,10) =  CONSTANTS(:,28).*( ALGEBRAIC(:,12).*(1.00000 - STATES(:,10)) -  ALGEBRAIC(:,19).*STATES(:,10));
ALGEBRAIC(:,5) = (STATES(:,1)+34.0000) - 10.0000;
ALGEBRAIC(:,13) = piecewise({abs(ALGEBRAIC(:,5))<CONSTANTS(:,30), 25.0000 }, ( 6.25000.*ALGEBRAIC(:,5))./(exp(ALGEBRAIC(:,5)./5.50000) - 1.00000));
ALGEBRAIC(:,20) = 12.0000./(1.00000+exp((  - 1.00000.*(STATES(:,1)+34.0000))./5.50000));
RATES(:,11) =  CONSTANTS(:,29).*( ALGEBRAIC(:,13).*(1.00000 - STATES(:,11)) -  ALGEBRAIC(:,20).*STATES(:,11));
ALGEBRAIC(:,16) = STATES(:,5)./(STATES(:,5)+CONSTANTS(:,49));
ALGEBRAIC(:,22) = STATES(:,9)./(STATES(:,9)+CONSTANTS(:,50));
ALGEBRAIC(:,24) = ALGEBRAIC(:,16)+ (1.00000 - ALGEBRAIC(:,16)).*ALGEBRAIC(:,22);
ALGEBRAIC(:,28) = 60.0000+ 500.000.*power(ALGEBRAIC(:,24), 2.00000);
ALGEBRAIC(:,30) = piecewise({STATES(:,1)< - 50.0000, 5.00000 }, 1.00000);
RATES(:,19) =  STATES(:,18).*ALGEBRAIC(:,30).*ALGEBRAIC(:,28) -  ALGEBRAIC(:,30).*1.00000.*STATES(:,19);
ALGEBRAIC(:,8) = exp( 0.0800000.*(STATES(:,1) - 40.0000));
ALGEBRAIC(:,26) =  0.00000.*ALGEBRAIC(:,8)+ 500.000.*power(ALGEBRAIC(:,24), 2.00000);
ALGEBRAIC(:,32) = (1.00000 - STATES(:,18)) - STATES(:,19);
RATES(:,18) =  ALGEBRAIC(:,32).*ALGEBRAIC(:,30).*ALGEBRAIC(:,26) -  STATES(:,18).*ALGEBRAIC(:,30).*ALGEBRAIC(:,28);
ALGEBRAIC(:,39) =  ((( CONSTANTS(:,27).*4.00000.*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,5).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
RATES(:,9) = (  - 1.00000.*ALGEBRAIC(:,39))./( 2.00000.*CONSTANTS(:,61).*1.00000.*CONSTANTS(:,70).*CONSTANTS(:,3)) -  STATES(:,9).*CONSTANTS(:,65);
ALGEBRAIC(:,21) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,2)./STATES(:,3));
ALGEBRAIC(:,27) = ( (( CONSTANTS(:,13).*STATES(:,2))./(STATES(:,2)+CONSTANTS(:,12))).*(STATES(:,1) - ALGEBRAIC(:,21)))./(1.00000+exp(( ((STATES(:,1) - ALGEBRAIC(:,21))+10.0000).*CONSTANTS(:,3).*1.67000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,44) =  CONSTANTS(:,32).*(CONSTANTS(:,33)+ STATES(:,14).*(1.00000 - CONSTANTS(:,33))).*STATES(:,15).*(STATES(:,1) - ALGEBRAIC(:,21));
ALGEBRAIC(:,29) = ( CONSTANTS(:,14).*(STATES(:,3) -  STATES(:,2).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./140.000;
ALGEBRAIC(:,31) =  STATES(:,6).*ALGEBRAIC(:,29);
ALGEBRAIC(:,37) =  ((( (1.00000 - CONSTANTS(:,27)).*CONSTANTS(:,22).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,12).*(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))) -  STATES(:,2).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,40) =  ((( CONSTANTS(:,27).*CONSTANTS(:,22).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  STATES(:,2).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,45) = ( (( CONSTANTS(:,34).*STATES(:,2))./(CONSTANTS(:,35)+STATES(:,2))).*STATES(:,4))./(CONSTANTS(:,36)+STATES(:,4));
ALGEBRAIC(:,35) =  CONSTANTS(:,20).*(STATES(:,1) - ALGEBRAIC(:,21));
RATES(:,2) = ( 1.00000.*(ALGEBRAIC(:,27)+ALGEBRAIC(:,44)+ALGEBRAIC(:,37)+ALGEBRAIC(:,40)+  - 2.00000.*ALGEBRAIC(:,45)+ALGEBRAIC(:,31)+ALGEBRAIC(:,35)))./( 1.00000.*CONSTANTS(:,69).*CONSTANTS(:,3)) -  CONSTANTS(:,52).*(STATES(:,2) - CONSTANTS(:,51));
RATES(:,3) =  ( - 1.00000./( 1.00000.*CONSTANTS(:,70).*CONSTANTS(:,3))).*((ALGEBRAIC(:,27)+ALGEBRAIC(:,31)+ALGEBRAIC(:,37)+ALGEBRAIC(:,40)+ALGEBRAIC(:,44)+ALGEBRAIC(:,35)) -  2.00000.*ALGEBRAIC(:,45));
ALGEBRAIC(:,25) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,10)+ 0.120000.*STATES(:,2))./(STATES(:,4)+ 0.120000.*STATES(:,3)));
ALGEBRAIC(:,33) =  CONSTANTS(:,16).*power(STATES(:,7), 3.00000).*STATES(:,8).*(STATES(:,1) - ALGEBRAIC(:,25));
ALGEBRAIC(:,15) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,10)./STATES(:,4));
ALGEBRAIC(:,34) =  CONSTANTS(:,19).*(STATES(:,1) - ALGEBRAIC(:,15));
ALGEBRAIC(:,38) =  ((( (1.00000 - CONSTANTS(:,27)).*CONSTANTS(:,23).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,10).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,41) =  ((( CONSTANTS(:,27).*CONSTANTS(:,23).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,10).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,46) = ( (1.00000 - CONSTANTS(:,41)).*CONSTANTS(:,37).*( exp(( CONSTANTS(:,40).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,4), CONSTANTS(:,38)).*CONSTANTS(:,11) -  exp(( (CONSTANTS(:,40) - 1.00000).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,10), CONSTANTS(:,38)).*STATES(:,5)))./( (1.00000+ CONSTANTS(:,39).*( STATES(:,5).*power(CONSTANTS(:,10), CONSTANTS(:,38))+ CONSTANTS(:,11).*power(STATES(:,4), CONSTANTS(:,38)))).*(1.00000+STATES(:,5)./0.00690000));
RATES(:,4) =  ( - 1.00000./( 1.00000.*CONSTANTS(:,70).*CONSTANTS(:,3))).*(ALGEBRAIC(:,33)+ALGEBRAIC(:,34)+ 3.00000.*ALGEBRAIC(:,45)+ 3.00000.*ALGEBRAIC(:,46)+ALGEBRAIC(:,38)+ALGEBRAIC(:,41));
ALGEBRAIC(:,47) = ( CONSTANTS(:,41).*CONSTANTS(:,37).*( exp(( CONSTANTS(:,40).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,4), CONSTANTS(:,38)).*CONSTANTS(:,11) -  exp(( (CONSTANTS(:,40) - 1.00000).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,10), CONSTANTS(:,38)).*STATES(:,9)))./( (1.00000+ CONSTANTS(:,39).*( STATES(:,9).*power(CONSTANTS(:,10), CONSTANTS(:,38))+ CONSTANTS(:,11).*power(STATES(:,4), CONSTANTS(:,38)))).*(1.00000+STATES(:,9)./0.00690000));
ALGEBRAIC(:,36) =  ((( (1.00000 - CONSTANTS(:,27)).*4.00000.*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,5).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,23) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,5));
ALGEBRAIC(:,43) =  CONSTANTS(:,31).*(STATES(:,1) - ALGEBRAIC(:,23));
ALGEBRAIC(:,7) = piecewise({VOI>=CONSTANTS(:,5)&VOI<=CONSTANTS(:,6)&(VOI - CONSTANTS(:,5)) -  floor((VOI - CONSTANTS(:,5))./CONSTANTS(:,7)).*CONSTANTS(:,7)<=CONSTANTS(:,8), CONSTANTS(:,9) }, 0.00000);
RATES(:,1) =  ( - 1.00000./CONSTANTS(:,4)).*(ALGEBRAIC(:,7)+ALGEBRAIC(:,27)+ALGEBRAIC(:,44)+ALGEBRAIC(:,31)+ALGEBRAIC(:,45)+ALGEBRAIC(:,33)+ALGEBRAIC(:,34)+ALGEBRAIC(:,38)+ALGEBRAIC(:,41)+ALGEBRAIC(:,46)+ALGEBRAIC(:,47)+ALGEBRAIC(:,36)+ALGEBRAIC(:,39)+ALGEBRAIC(:,37)+ALGEBRAIC(:,40)+ALGEBRAIC(:,43)+ALGEBRAIC(:,35));
ALGEBRAIC(:,48) = STATES(:,5)+ STATES(:,16).*CONSTANTS(:,67)+ CONSTANTS(:,42).*CONSTANTS(:,43)+CONSTANTS(:,42);
ALGEBRAIC(:,50) =  (STATES(:,5)./ALGEBRAIC(:,48)).*CONSTANTS(:,45) -  (( STATES(:,16).*CONSTANTS(:,67))./ALGEBRAIC(:,48)).*CONSTANTS(:,46);
ALGEBRAIC(:,51) =  50.0000.*(STATES(:,16) - STATES(:,17));
RATES(:,16) =  (CONSTANTS(:,68)./CONSTANTS(:,64)).*ALGEBRAIC(:,50) - ALGEBRAIC(:,51);
RATES(:,20) =  CONSTANTS(:,55).*STATES(:,5).*(CONSTANTS(:,53) - STATES(:,20)) -  CONSTANTS(:,56).*STATES(:,20);
ALGEBRAIC(:,52) =  ( power(STATES(:,18)./(STATES(:,18)+0.250000), 2.00000).*CONSTANTS(:,48)+CONSTANTS(:,47)).*STATES(:,17);
RATES(:,17) =  (CONSTANTS(:,64)./CONSTANTS(:,62)).*ALGEBRAIC(:,51) - ALGEBRAIC(:,52);
RATES(:,21) =  CONSTANTS(:,57).*STATES(:,5).*(CONSTANTS(:,54) - STATES(:,21)) -  CONSTANTS(:,58).*STATES(:,21);
RATES(:,5) = ((( ( - 1.00000./( 2.00000.*1.00000.*CONSTANTS(:,70).*CONSTANTS(:,3))).*((ALGEBRAIC(:,36)+ALGEBRAIC(:,43)) -  2.00000.*ALGEBRAIC(:,46))+ STATES(:,9).*CONSTANTS(:,61).*CONSTANTS(:,65)+( ALGEBRAIC(:,52).*CONSTANTS(:,62))./CONSTANTS(:,68)) - RATES(:,20)) - RATES(:,21)) - 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(:,3) =  20.0000.*exp(  - 0.125000.*((STATES(:,1)+75.0000) - CONSTANTS(:,18)));
ALGEBRAIC(:,11) = 2000.00./(1.00000+ 320.000.*exp(  - 0.100000.*((STATES(:,1)+75.0000) - CONSTANTS(:,18))));
ALGEBRAIC(:,6) =  0.260000.*0.0330000.*exp( - STATES(:,1)./14.8750);
ALGEBRAIC(:,14) = ( 0.260000.*33.0000)./(1.00000+exp( - (STATES(:,1)+10.0000)./7.00000));
ALGEBRAIC(:,1) = (STATES(:,1)+22.0000) - 40.0000;
ALGEBRAIC(:,9) = piecewise({abs(ALGEBRAIC(:,1))<CONSTANTS(:,15), 2.50000 }, ( 3.00000.*0.500000.*ALGEBRAIC(:,1))./(1.00000 - exp( - ALGEBRAIC(:,1)./5.00000)));
ALGEBRAIC(:,17) = piecewise({abs(ALGEBRAIC(:,1))<CONSTANTS(:,15), 2.50000 }, ( 3.00000.*0.178000.*ALGEBRAIC(:,1))./(exp(ALGEBRAIC(:,1)./15.0000) - 1.00000));
ALGEBRAIC(:,2) = STATES(:,1)+41.0000;
ALGEBRAIC(:,10) = piecewise({abs(ALGEBRAIC(:,2))<CONSTANTS(:,17), 2000.00 }, ( 200.000.*ALGEBRAIC(:,2))./(1.00000 - exp(  - 0.100000.*ALGEBRAIC(:,2))));
ALGEBRAIC(:,18) =  8000.00.*exp(  - 0.0560000.*(STATES(:,1)+66.0000));
ALGEBRAIC(:,4) = (STATES(:,1)+24.0000) - 20.0000;
ALGEBRAIC(:,12) = piecewise({abs(ALGEBRAIC(:,4))<0.000100000, 120.000 }, ( 30.0000.*ALGEBRAIC(:,4))./(1.00000 - exp( - ALGEBRAIC(:,4)./3.00000)));
ALGEBRAIC(:,19) = piecewise({abs(ALGEBRAIC(:,4))<0.000100000, 120.000 }, ( 12.0000.*ALGEBRAIC(:,4))./(exp(ALGEBRAIC(:,4)./7.50000) - 1.00000));
ALGEBRAIC(:,5) = (STATES(:,1)+34.0000) - 10.0000;
ALGEBRAIC(:,13) = piecewise({abs(ALGEBRAIC(:,5))<CONSTANTS(:,30), 25.0000 }, ( 6.25000.*ALGEBRAIC(:,5))./(exp(ALGEBRAIC(:,5)./5.50000) - 1.00000));
ALGEBRAIC(:,20) = 12.0000./(1.00000+exp((  - 1.00000.*(STATES(:,1)+34.0000))./5.50000));
ALGEBRAIC(:,16) = STATES(:,5)./(STATES(:,5)+CONSTANTS(:,49));
ALGEBRAIC(:,22) = STATES(:,9)./(STATES(:,9)+CONSTANTS(:,50));
ALGEBRAIC(:,24) = ALGEBRAIC(:,16)+ (1.00000 - ALGEBRAIC(:,16)).*ALGEBRAIC(:,22);
ALGEBRAIC(:,28) = 60.0000+ 500.000.*power(ALGEBRAIC(:,24), 2.00000);
ALGEBRAIC(:,30) = piecewise({STATES(:,1)< - 50.0000, 5.00000 }, 1.00000);
ALGEBRAIC(:,8) = exp( 0.0800000.*(STATES(:,1) - 40.0000));
ALGEBRAIC(:,26) =  0.00000.*ALGEBRAIC(:,8)+ 500.000.*power(ALGEBRAIC(:,24), 2.00000);
ALGEBRAIC(:,32) = (1.00000 - STATES(:,18)) - STATES(:,19);
ALGEBRAIC(:,39) =  ((( CONSTANTS(:,27).*4.00000.*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,5).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,21) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(STATES(:,2)./STATES(:,3));
ALGEBRAIC(:,27) = ( (( CONSTANTS(:,13).*STATES(:,2))./(STATES(:,2)+CONSTANTS(:,12))).*(STATES(:,1) - ALGEBRAIC(:,21)))./(1.00000+exp(( ((STATES(:,1) - ALGEBRAIC(:,21))+10.0000).*CONSTANTS(:,3).*1.67000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,44) =  CONSTANTS(:,32).*(CONSTANTS(:,33)+ STATES(:,14).*(1.00000 - CONSTANTS(:,33))).*STATES(:,15).*(STATES(:,1) - ALGEBRAIC(:,21));
ALGEBRAIC(:,29) = ( CONSTANTS(:,14).*(STATES(:,3) -  STATES(:,2).*exp((  - STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))))./140.000;
ALGEBRAIC(:,31) =  STATES(:,6).*ALGEBRAIC(:,29);
ALGEBRAIC(:,37) =  ((( (1.00000 - CONSTANTS(:,27)).*CONSTANTS(:,22).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,12).*(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))) -  STATES(:,2).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,40) =  ((( CONSTANTS(:,27).*CONSTANTS(:,22).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,3).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  STATES(:,2).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,45) = ( (( CONSTANTS(:,34).*STATES(:,2))./(CONSTANTS(:,35)+STATES(:,2))).*STATES(:,4))./(CONSTANTS(:,36)+STATES(:,4));
ALGEBRAIC(:,35) =  CONSTANTS(:,20).*(STATES(:,1) - ALGEBRAIC(:,21));
ALGEBRAIC(:,25) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log((CONSTANTS(:,10)+ 0.120000.*STATES(:,2))./(STATES(:,4)+ 0.120000.*STATES(:,3)));
ALGEBRAIC(:,33) =  CONSTANTS(:,16).*power(STATES(:,7), 3.00000).*STATES(:,8).*(STATES(:,1) - ALGEBRAIC(:,25));
ALGEBRAIC(:,15) =  (( CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,10)./STATES(:,4));
ALGEBRAIC(:,34) =  CONSTANTS(:,19).*(STATES(:,1) - ALGEBRAIC(:,15));
ALGEBRAIC(:,38) =  ((( (1.00000 - CONSTANTS(:,27)).*CONSTANTS(:,23).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,10).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,41) =  ((( CONSTANTS(:,27).*CONSTANTS(:,23).*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,13).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,4).*exp(( 50.0000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,10).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,46) = ( (1.00000 - CONSTANTS(:,41)).*CONSTANTS(:,37).*( exp(( CONSTANTS(:,40).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,4), CONSTANTS(:,38)).*CONSTANTS(:,11) -  exp(( (CONSTANTS(:,40) - 1.00000).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,10), CONSTANTS(:,38)).*STATES(:,5)))./( (1.00000+ CONSTANTS(:,39).*( STATES(:,5).*power(CONSTANTS(:,10), CONSTANTS(:,38))+ CONSTANTS(:,11).*power(STATES(:,4), CONSTANTS(:,38)))).*(1.00000+STATES(:,5)./0.00690000));
ALGEBRAIC(:,47) = ( CONSTANTS(:,41).*CONSTANTS(:,37).*( exp(( CONSTANTS(:,40).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(STATES(:,4), CONSTANTS(:,38)).*CONSTANTS(:,11) -  exp(( (CONSTANTS(:,40) - 1.00000).*(CONSTANTS(:,38) - 2.00000).*STATES(:,1).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))).*power(CONSTANTS(:,10), CONSTANTS(:,38)).*STATES(:,9)))./( (1.00000+ CONSTANTS(:,39).*( STATES(:,9).*power(CONSTANTS(:,10), CONSTANTS(:,38))+ CONSTANTS(:,11).*power(STATES(:,4), CONSTANTS(:,38)))).*(1.00000+STATES(:,9)./0.00690000));
ALGEBRAIC(:,36) =  ((( (1.00000 - CONSTANTS(:,27)).*4.00000.*CONSTANTS(:,21).*STATES(:,10).*STATES(:,11).*STATES(:,12).*(STATES(:,1) - 50.0000).*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2)))./(1.00000 - exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))))).*( STATES(:,5).*exp(( 100.000.*CONSTANTS(:,3))./( CONSTANTS(:,1).*CONSTANTS(:,2))) -  CONSTANTS(:,11).*exp((  - (STATES(:,1) - 50.0000).*CONSTANTS(:,3).*2.00000)./( CONSTANTS(:,1).*CONSTANTS(:,2))));
ALGEBRAIC(:,23) =  (( 0.500000.*CONSTANTS(:,1).*CONSTANTS(:,2))./CONSTANTS(:,3)).*log(CONSTANTS(:,11)./STATES(:,5));
ALGEBRAIC(:,43) =  CONSTANTS(:,31).*(STATES(:,1) - ALGEBRAIC(:,23));
ALGEBRAIC(:,7) = 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(:,48) = STATES(:,5)+ STATES(:,16).*CONSTANTS(:,67)+ CONSTANTS(:,42).*CONSTANTS(:,43)+CONSTANTS(:,42);
ALGEBRAIC(:,50) =  (STATES(:,5)./ALGEBRAIC(:,48)).*CONSTANTS(:,45) -  (( STATES(:,16).*CONSTANTS(:,67))./ALGEBRAIC(:,48)).*CONSTANTS(:,46);
ALGEBRAIC(:,51) =  50.0000.*(STATES(:,16) - STATES(:,17));
ALGEBRAIC(:,52) =  ( power(STATES(:,18)./(STATES(:,18)+0.250000), 2.00000).*CONSTANTS(:,48)+CONSTANTS(:,47)).*STATES(:,17);
ALGEBRAIC(:,42) = ALGEBRAIC(:,36)+ALGEBRAIC(:,37)+ALGEBRAIC(:,38)+ALGEBRAIC(:,39)+ALGEBRAIC(:,40)+ALGEBRAIC(:,41);
ALGEBRAIC(:,49) = ALGEBRAIC(:,46)+ALGEBRAIC(:,47);
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 Espinosa, 1998 at changeset 46bb541ea697.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: