# 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 =98;
end
% There are a total of 30 entries in each of the rate and state variable arrays.
% There are a total of 108 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('t in component lpc (s)');
LEGEND_CONSTANTS(:,1) = strpad('Vlvrd in component lpc (mL)');
LEGEND_CONSTANTS(:,2) = strpad('Vlvrs in component lpc (mL)');
LEGEND_CONSTANTS(:,3) = strpad('Vrvrd in component lpc (mL)');
LEGEND_CONSTANTS(:,4) = strpad('Vrvrs in component lpc (mL)');
LEGEND_CONSTANTS(:,5) = strpad('Vlard in component lpc (mL)');
LEGEND_CONSTANTS(:,6) = strpad('Vlars in component lpc (mL)');
LEGEND_CONSTANTS(:,7) = strpad('Vrard in component lpc (mL)');
LEGEND_CONSTANTS(:,8) = strpad('Vrars in component lpc (mL)');
LEGEND_CONSTANTS(:,9) = strpad('Rra in component lpc (resistance)');
LEGEND_CONSTANTS(:,10) = strpad('Rla in component lpc (resistance)');
LEGEND_CONSTANTS(:,11) = strpad('PRint in component lpc (s)');
LEGEND_CONSTANTS(:,12) = strpad('Emaxlv in component lpc (elastance)');
LEGEND_CONSTANTS(:,13) = strpad('Eminlv in component lpc (elastance)');
LEGEND_CONSTANTS(:,14) = strpad('Emaxrv in component lpc (elastance)');
LEGEND_CONSTANTS(:,15) = strpad('Eminrv in component lpc (elastance)');
LEGEND_CONSTANTS(:,16) = strpad('Emaxra in component lpc (elastance)');
LEGEND_CONSTANTS(:,17) = strpad('Eminra in component lpc (elastance)');
LEGEND_CONSTANTS(:,18) = strpad('Emaxla in component lpc (elastance)');
LEGEND_CONSTANTS(:,19) = strpad('Eminla in component lpc (elastance)');
LEGEND_CONSTANTS(:,20) = strpad('Pbs in component lpc (mmHg)');
LEGEND_CONSTANTS(:,21) = strpad('Vmyo in component lpc (mL)');
LEGEND_CONSTANTS(:,22) = strpad('TsvK in component lpc (s)');
LEGEND_CONSTANTS(:,23) = strpad('TsaK in component lpc (s)');
LEGEND_CONSTANTS(:,24) = strpad('HR in component lpc (ratepm)');
LEGEND_ALGEBRAIC(:,18) = strpad('Elv in component lpc (elastance)');
LEGEND_ALGEBRAIC(:,16) = strpad('Erv in component lpc (elastance)');
LEGEND_ALGEBRAIC(:,15) = strpad('Era in component lpc (elastance)');
LEGEND_ALGEBRAIC(:,17) = strpad('Ela in component lpc (elastance)');
LEGEND_ALGEBRAIC(:,59) = strpad('Vlvr in component lpc (mL)');
LEGEND_ALGEBRAIC(:,82) = strpad('Vrvr in component lpc (mL)');
LEGEND_ALGEBRAIC(:,56) = strpad('Vlar in component lpc (mL)');
LEGEND_ALGEBRAIC(:,71) = strpad('Vrar in component lpc (mL)');
LEGEND_ALGEBRAIC(:,89) = strpad('Fra in component lpc (flow)');
LEGEND_ALGEBRAIC(:,95) = strpad('Frv in component lpc (flow)');
LEGEND_ALGEBRAIC(:,81) = strpad('Fla in component lpc (flow)');
LEGEND_ALGEBRAIC(:,84) = strpad('Flv in component lpc (flow)');
LEGEND_ALGEBRAIC(:,73) = strpad('Pra in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,75) = strpad('Prac in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,85) = strpad('Prv in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,87) = strpad('Prvc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,58) = strpad('Pla in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,76) = strpad('Plac in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,60) = strpad('Plv in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,80) = strpad('Plvc in component lpc (mmHg)');
LEGEND_STATES(:,1) = strpad('Vra in component lpc (mL)');
LEGEND_STATES(:,2) = strpad('Vrv in component lpc (mL)');
LEGEND_STATES(:,3) = strpad('Vla in component lpc (mL)');
LEGEND_STATES(:,4) = strpad('Vlv in component lpc (mL)');
LEGEND_CONSTANTS(:,25) = strpad('COutput in component lpc (flow)');
LEGEND_CONSTANTS(:,104) = strpad('SV in component lpc (mL)');
LEGEND_ALGEBRAIC(:,7) = strpad('P_QRSwave in component lpc (mV)');
LEGEND_CONSTANTS(:,106) = strpad('Tsv in component lpc (s)');
LEGEND_CONSTANTS(:,108) = strpad('Tsa in component lpc (s)');
LEGEND_ALGEBRAIC(:,10) = strpad('trela in component lpc (s)');
LEGEND_ALGEBRAIC(:,8) = strpad('trelv in component lpc (s)');
LEGEND_CONSTANTS(:,26) = strpad('Rav in component lpc (resistance)');
LEGEND_CONSTANTS(:,27) = strpad('Raop in component lpc (resistance)');
LEGEND_CONSTANTS(:,28) = strpad('Rcrb in component lpc (resistance)');
LEGEND_CONSTANTS(:,29) = strpad('Raod in component lpc (resistance)');
LEGEND_CONSTANTS(:,30) = strpad('Rtaop in component lpc (resistance)');
LEGEND_CONSTANTS(:,31) = strpad('Rtaod in component lpc (resistance)');
LEGEND_CONSTANTS(:,32) = strpad('Rsap in component lpc (resistance)');
LEGEND_CONSTANTS(:,33) = strpad('Rsc in component lpc (resistance)');
LEGEND_CONSTANTS(:,34) = strpad('Rsv in component lpc (resistance)');
LEGEND_CONSTANTS(:,35) = strpad('Rsao in component lpc (resistance)');
LEGEND_CONSTANTS(:,36) = strpad('Caop in component lpc (capacitance)');
LEGEND_CONSTANTS(:,37) = strpad('Caod in component lpc (capacitance)');
LEGEND_CONSTANTS(:,38) = strpad('Csap in component lpc (capacitance)');
LEGEND_CONSTANTS(:,39) = strpad('Csc in component lpc (capacitance)');
LEGEND_CONSTANTS(:,40) = strpad('Laop in component lpc (inductance)');
LEGEND_CONSTANTS(:,41) = strpad('Laod in component lpc (inductance)');
LEGEND_CONSTANTS(:,42) = strpad('Kc in component lpc (mmHg)');
LEGEND_CONSTANTS(:,43) = strpad('Do in component lpc (mL)');
LEGEND_CONSTANTS(:,44) = strpad('Vsa_o in component lpc (mL)');
LEGEND_CONSTANTS(:,45) = strpad('Vsa_max in component lpc (mL)');
LEGEND_CONSTANTS(:,46) = strpad('Kp1 in component lpc (mmHg)');
LEGEND_CONSTANTS(:,47) = strpad('Kp2 in component lpc (mmHgmlm2)');
LEGEND_CONSTANTS(:,48) = strpad('Kr in component lpc (resistance)');
LEGEND_CONSTANTS(:,49) = strpad('tau_p in component lpc (perml)');
LEGEND_CONSTANTS(:,50) = strpad('Kv in component lpc (mmHg)');
LEGEND_CONSTANTS(:,51) = strpad('Vmax_sv in component lpc (mL)');
LEGEND_CONSTANTS(:,52) = strpad('D2 in component lpc (mmHg)');
LEGEND_CONSTANTS(:,53) = strpad('K1 in component lpc (dimensionless)');
LEGEND_CONSTANTS(:,54) = strpad('K2 in component lpc (mmHg)');
LEGEND_CONSTANTS(:,55) = strpad('KR in component lpc (resistance)');
LEGEND_CONSTANTS(:,56) = strpad('Ro in component lpc (resistance)');
LEGEND_CONSTANTS(:,57) = strpad('Vo in component lpc (mL)');
LEGEND_CONSTANTS(:,58) = strpad('Vmax_vc in component lpc (mL)');
LEGEND_CONSTANTS(:,59) = strpad('Vmin_vc in component lpc (mL)');
LEGEND_CONSTANTS(:,60) = strpad('COtau in component lpc (s)');
LEGEND_CONSTANTS(:,61) = strpad('Pplc in component lpc (mmHg)');
LEGEND_CONSTANTS(:,62) = strpad('Px2 in component lpc (mmHg)');
LEGEND_CONSTANTS(:,63) = strpad('Vx8 in component lpc (mL)');
LEGEND_CONSTANTS(:,64) = strpad('Vx75 in component lpc (mL)');
LEGEND_CONSTANTS(:,65) = strpad('Vx1 in component lpc (mL)');
LEGEND_CONSTANTS(:,66) = strpad('Px1 in component lpc (mmHg)');
LEGEND_CONSTANTS(:,67) = strpad('F_vaso in component lpc (dimensionless)');
LEGEND_ALGEBRAIC(:,53) = strpad('Rvc in component lpc (resistance)');
LEGEND_ALGEBRAIC(:,45) = strpad('Rsa in component lpc (resistance)');
LEGEND_ALGEBRAIC(:,1) = strpad('Paop in component lpc (mmHg)');
LEGEND_STATES(:,5) = strpad('Paopc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,51) = strpad('Paod in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,50) = strpad('Paodc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,37) = strpad('Psa_a in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,38) = strpad('Psa_p in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,39) = strpad('Psa in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,40) = strpad('Psap in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,42) = strpad('Psc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,43) = strpad('Psv in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,46) = strpad('Pvc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,48) = strpad('Pvcc in component lpc (mmHg)');
LEGEND_STATES(:,6) = strpad('MAP in component lpc (mmHg)');
LEGEND_STATES(:,7) = strpad('Faop in component lpc (flowLm)');
LEGEND_STATES(:,8) = strpad('Faod in component lpc (flow)');
LEGEND_ALGEBRAIC(:,41) = strpad('Fsap in component lpc (flow)');
LEGEND_ALGEBRAIC(:,47) = strpad('Fsa in component lpc (flow)');
LEGEND_ALGEBRAIC(:,44) = strpad('Fsc in component lpc (flow)');
LEGEND_ALGEBRAIC(:,49) = strpad('Fsv in component lpc (flow)');
LEGEND_ALGEBRAIC(:,79) = strpad('Fvc in component lpc (flow)');
LEGEND_ALGEBRAIC(:,52) = strpad('Fcrb in component lpc (flow)');
LEGEND_STATES(:,9) = strpad('Vaop in component lpc (mL)');
LEGEND_STATES(:,10) = strpad('Vaod in component lpc (mL)');
LEGEND_STATES(:,11) = strpad('Vsa in component lpc (mL)');
LEGEND_STATES(:,12) = strpad('Vsap in component lpc (mL)');
LEGEND_STATES(:,13) = strpad('Vsc in component lpc (mL)');
LEGEND_STATES(:,14) = strpad('Vsv in component lpc (mL)');
LEGEND_STATES(:,15) = strpad('Vvc in component lpc (mL)');
LEGEND_ALGEBRAIC(:,55) = strpad('Vtot in component lpc (mL)');
LEGEND_ALGEBRAIC(:,2) = strpad('SysArtVol in component lpc (mL)');
LEGEND_ALGEBRAIC(:,3) = strpad('SysVenVol in component lpc (mL)');
LEGEND_ALGEBRAIC(:,4) = strpad('PulArtVol in component lpc (mL)');
LEGEND_ALGEBRAIC(:,5) = strpad('PulVenVol in component lpc (mL)');
LEGEND_ALGEBRAIC(:,57) = strpad('VBcirc in component lpc (mL)');
LEGEND_CONSTANTS(:,105) = strpad('Ppl in component lpc (mmHg)');
LEGEND_CONSTANTS(:,68) = strpad('Rpuv in component lpc (resistance)');
LEGEND_CONSTANTS(:,69) = strpad('Rtpap in component lpc (resistance)');
LEGEND_CONSTANTS(:,70) = strpad('Rtpad in component lpc (resistance)');
LEGEND_CONSTANTS(:,71) = strpad('Rpap in component lpc (resistance)');
LEGEND_CONSTANTS(:,72) = strpad('Rpad in component lpc (resistance)');
LEGEND_CONSTANTS(:,73) = strpad('Rps in component lpc (resistance)');
LEGEND_CONSTANTS(:,74) = strpad('Rpa in component lpc (resistance)');
LEGEND_CONSTANTS(:,75) = strpad('Rpc in component lpc (resistance)');
LEGEND_CONSTANTS(:,76) = strpad('Rpv in component lpc (resistance)');
LEGEND_CONSTANTS(:,77) = strpad('Ctpap in component lpc (capacitance)');
LEGEND_CONSTANTS(:,78) = strpad('Ctpad in component lpc (capacitance)');
LEGEND_CONSTANTS(:,79) = strpad('Cpa in component lpc (capacitance)');
LEGEND_CONSTANTS(:,80) = strpad('Cpc in component lpc (capacitance)');
LEGEND_CONSTANTS(:,81) = strpad('Cpv in component lpc (capacitance)');
LEGEND_CONSTANTS(:,82) = strpad('Lpa in component lpc (inductance)');
LEGEND_CONSTANTS(:,83) = strpad('Lpad in component lpc (inductance)');
LEGEND_ALGEBRAIC(:,93) = strpad('Ppapc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,91) = strpad('Ppapc1 in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,29) = strpad('Ppapc2 in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,96) = strpad('Ppap in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,62) = strpad('Ppad in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,61) = strpad('Ppadc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,27) = strpad('Ppa in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,28) = strpad('Ppac in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,30) = strpad('Ppc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,31) = strpad('Ppcc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,33) = strpad('Ppv in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,34) = strpad('Ppvc in component lpc (mmHg)');
LEGEND_STATES(:,16) = strpad('Vpap in component lpc (mL)');
LEGEND_STATES(:,17) = strpad('Vpad in component lpc (mL)');
LEGEND_STATES(:,18) = strpad('Vpa in component lpc (mL)');
LEGEND_STATES(:,19) = strpad('Vpc in component lpc (mL)');
LEGEND_STATES(:,20) = strpad('Vpv in component lpc (mL)');
LEGEND_STATES(:,21) = strpad('Fpap in component lpc (flowLm)');
LEGEND_STATES(:,22) = strpad('Fpad in component lpc (flow)');
LEGEND_ALGEBRAIC(:,36) = strpad('Fps in component lpc (flow)');
LEGEND_ALGEBRAIC(:,32) = strpad('Fpa in component lpc (flow)');
LEGEND_ALGEBRAIC(:,35) = strpad('Fpc in component lpc (flow)');
LEGEND_ALGEBRAIC(:,78) = strpad('Fpv in component lpc (flow)');
LEGEND_CONSTANTS(:,84) = strpad('K_pcd in component lpc (mmHg)');
LEGEND_CONSTANTS(:,85) = strpad('phi_pcd in component lpc (mL)');
LEGEND_CONSTANTS(:,86) = strpad('Vpcd_o in component lpc (mL)');
LEGEND_CONSTANTS(:,87) = strpad('perifl in component lpc (mL)');
LEGEND_ALGEBRAIC(:,64) = strpad('Ppcd in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,65) = strpad('Ppcdc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,63) = strpad('Vpcd in component lpc (mL)');
LEGEND_CONSTANTS(:,88) = strpad('Rcorao in component lpc (resistance)');
LEGEND_CONSTANTS(:,89) = strpad('Rcorea in component lpc (resistance)');
LEGEND_CONSTANTS(:,90) = strpad('Rcorla in component lpc (resistance)');
LEGEND_CONSTANTS(:,91) = strpad('Rcorsa in component lpc (resistance)');
LEGEND_CONSTANTS(:,92) = strpad('Rcorcap in component lpc (resistance)');
LEGEND_CONSTANTS(:,93) = strpad('Rcorsv in component lpc (resistance)');
LEGEND_CONSTANTS(:,94) = strpad('Rcorlv in component lpc (resistance)');
LEGEND_CONSTANTS(:,95) = strpad('Rcorev in component lpc (resistance)');
LEGEND_CONSTANTS(:,96) = strpad('Ccorao in component lpc (capacitance)');
LEGEND_CONSTANTS(:,97) = strpad('Ccorea in component lpc (capacitance)');
LEGEND_CONSTANTS(:,98) = strpad('Ccorla in component lpc (capacitance)');
LEGEND_CONSTANTS(:,99) = strpad('Ccorsa in component lpc (capacitance)');
LEGEND_CONSTANTS(:,100) = strpad('Ccorcap in component lpc (capacitance)');
LEGEND_CONSTANTS(:,101) = strpad('Ccorsv in component lpc (capacitance)');
LEGEND_CONSTANTS(:,102) = strpad('Ccorlv in component lpc (capacitance)');
LEGEND_CONSTANTS(:,103) = strpad('Ccorev in component lpc (capacitance)');
LEGEND_ALGEBRAIC(:,83) = strpad('Pcorisfc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,19) = strpad('Pcoraoc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,66) = strpad('Pcoreac in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,90) = strpad('Pcorlac in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,94) = strpad('Pcorsac in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,86) = strpad('Pcorcapc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,72) = strpad('Pcorsvc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,69) = strpad('Pcorlvc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,68) = strpad('Pcorevc in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,9) = strpad('Pcorao in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,21) = strpad('Pcorea in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,23) = strpad('Pcorla in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,25) = strpad('Pcorsa in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,20) = strpad('Pcorcap in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,26) = strpad('Pcorsv in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,24) = strpad('Pcorlv in component lpc (mmHg)');
LEGEND_ALGEBRAIC(:,22) = strpad('Pcorev in component lpc (mmHg)');
LEGEND_STATES(:,23) = strpad('Vcorao in component lpc (mL)');
LEGEND_STATES(:,24) = strpad('Vcorea in component lpc (mL)');
LEGEND_STATES(:,25) = strpad('Vcorla in component lpc (mL)');
LEGEND_STATES(:,26) = strpad('Vcorsa in component lpc (mL)');
LEGEND_STATES(:,27) = strpad('Vcorcap in component lpc (mL)');
LEGEND_STATES(:,28) = strpad('Vcorsv in component lpc (mL)');
LEGEND_STATES(:,29) = strpad('Vcorlv in component lpc (mL)');
LEGEND_STATES(:,30) = strpad('Vcorev in component lpc (mL)');
LEGEND_ALGEBRAIC(:,54) = strpad('Vcorcirc in component lpc (mL)');
LEGEND_ALGEBRAIC(:,67) = strpad('Fcorao in component lpc (flow)');
LEGEND_ALGEBRAIC(:,92) = strpad('Fcorea in component lpc (flow)');
LEGEND_ALGEBRAIC(:,97) = strpad('Fcorla in component lpc (flow)');
LEGEND_ALGEBRAIC(:,98) = strpad('Fcorsa in component lpc (flow)');
LEGEND_ALGEBRAIC(:,88) = strpad('Fcorcap in component lpc (flow)');
LEGEND_ALGEBRAIC(:,74) = strpad('Fcorsv in component lpc (flow)');
LEGEND_ALGEBRAIC(:,70) = strpad('Fcorlv in component lpc (flow)');
LEGEND_ALGEBRAIC(:,77) = strpad('Fcorev in component lpc (flow)');
LEGEND_ALGEBRAIC(:,6) = strpad('beattime in component lpc (s)');
LEGEND_ALGEBRAIC(:,11) = strpad('yla in component lpc (dimensionless)');
LEGEND_ALGEBRAIC(:,12) = strpad('yra in component lpc (dimensionless)');
LEGEND_ALGEBRAIC(:,13) = strpad('ylv in component lpc (dimensionless)');
LEGEND_ALGEBRAIC(:,14) = strpad('yrv in component lpc (dimensionless)');
LEGEND_CONSTANTS(:,107) = strpad('hrf in component lpc (Hz)');
LEGEND_RATES(:,8) = strpad('d/dt Faod in component lpc (flow)');
LEGEND_RATES(:,7) = strpad('d/dt Faop in component lpc (flowLm)');
LEGEND_RATES(:,22) = strpad('d/dt Fpad in component lpc (flow)');
LEGEND_RATES(:,21) = strpad('d/dt Fpap in component lpc (flowLm)');
LEGEND_RATES(:,6) = strpad('d/dt MAP in component lpc (mmHg)');
LEGEND_RATES(:,5) = strpad('d/dt Paopc in component lpc (mmHg)');
LEGEND_RATES(:,9) = strpad('d/dt Vaop in component lpc (mL)');
LEGEND_RATES(:,17) = strpad('d/dt Vpad in component lpc (mL)');
LEGEND_RATES(:,10) = strpad('d/dt Vaod in component lpc (mL)');
LEGEND_RATES(:,23) = strpad('d/dt Vcorao in component lpc (mL)');
LEGEND_RATES(:,27) = strpad('d/dt Vcorcap in component lpc (mL)');
LEGEND_RATES(:,24) = strpad('d/dt Vcorea in component lpc (mL)');
LEGEND_RATES(:,30) = strpad('d/dt Vcorev in component lpc (mL)');
LEGEND_RATES(:,25) = strpad('d/dt Vcorla in component lpc (mL)');
LEGEND_RATES(:,29) = strpad('d/dt Vcorlv in component lpc (mL)');
LEGEND_RATES(:,26) = strpad('d/dt Vcorsa in component lpc (mL)');
LEGEND_RATES(:,28) = strpad('d/dt Vcorsv in component lpc (mL)');
LEGEND_RATES(:,3) = strpad('d/dt Vla in component lpc (mL)');
LEGEND_RATES(:,4) = strpad('d/dt Vlv in component lpc (mL)');
LEGEND_RATES(:,18) = strpad('d/dt Vpa in component lpc (mL)');
LEGEND_RATES(:,16) = strpad('d/dt Vpap in component lpc (mL)');
LEGEND_RATES(:,19) = strpad('d/dt Vpc in component lpc (mL)');
LEGEND_RATES(:,20) = strpad('d/dt Vpv in component lpc (mL)');
LEGEND_RATES(:,1) = strpad('d/dt Vra in component lpc (mL)');
LEGEND_RATES(:,2) = strpad('d/dt Vrv in component lpc (mL)');
LEGEND_RATES(:,11) = strpad('d/dt Vsa in component lpc (mL)');
LEGEND_RATES(:,12) = strpad('d/dt Vsap in component lpc (mL)');
LEGEND_RATES(:,13) = strpad('d/dt Vsc in component lpc (mL)');
LEGEND_RATES(:,14) = strpad('d/dt Vsv in component lpc (mL)');
LEGEND_RATES(:,15) = strpad('d/dt Vvc in component lpc (mL)');
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) = 72;
CONSTANTS(:,2) = 23;
CONSTANTS(:,3) = 103;
CONSTANTS(:,4) = 53;
CONSTANTS(:,5) = 10;
CONSTANTS(:,6) = 8;
CONSTANTS(:,7) = 10;
CONSTANTS(:,8) = 8;
CONSTANTS(:,9) = 0.001;
CONSTANTS(:,10) = 0.001;
CONSTANTS(:,11) = 0.12;
CONSTANTS(:,12) = 5.6;
CONSTANTS(:,13) = 0.186874659;
CONSTANTS(:,14) = 0.67;
CONSTANTS(:,15) = 0.1041640922;
CONSTANTS(:,16) = 0.1091675077;
CONSTANTS(:,17) = 0.0992431888;
CONSTANTS(:,18) = 0.1446191772;
CONSTANTS(:,19) = 0.1314719793;
CONSTANTS(:,20) = 0;
CONSTANTS(:,21) = 238;
CONSTANTS(:,22) = 0.35;
CONSTANTS(:,23) = 0.2;
CONSTANTS(:,24) = 77;
STATES(:,1) = 78.2537;
STATES(:,2) = 167.4806;
STATES(:,3) = 85.9126;
STATES(:,4) = 125.360568;
CONSTANTS(:,25) = 108.56912706;
CONSTANTS(:,26) = 1e-4;
CONSTANTS(:,27) = 1e-4;
CONSTANTS(:,28) = 6.8284472205;
CONSTANTS(:,29) = 0.025;
CONSTANTS(:,30) = 0.2;
CONSTANTS(:,31) = 0.3;
CONSTANTS(:,32) = 0.025;
CONSTANTS(:,33) = 0.1545054945;
CONSTANTS(:,34) = 0.1381298227;
CONSTANTS(:,35) = 0.5508058134;
CONSTANTS(:,36) = 0.3445734208;
CONSTANTS(:,37) = 1.4544677036;
CONSTANTS(:,38) = 1.4843409851;
CONSTANTS(:,39) = 7.9822364317;
CONSTANTS(:,40) = 3.5e-4;
CONSTANTS(:,41) = 3.5e-4;
CONSTANTS(:,42) = 497.7852450367;
CONSTANTS(:,43) = 50;
CONSTANTS(:,44) = 485.7624931891;
CONSTANTS(:,45) = 577.7106000108;
CONSTANTS(:,46) = 0.03;
CONSTANTS(:,47) = 0.05;
CONSTANTS(:,48) = 0.01;
CONSTANTS(:,49) = 0.1;
CONSTANTS(:,50) = 21.83;
CONSTANTS(:,51) = 3379.545;
CONSTANTS(:,52) = -5;
CONSTANTS(:,53) = 0.0968305478;
CONSTANTS(:,54) = 0.4;
CONSTANTS(:,55) = 0.001;
CONSTANTS(:,56) = 0.025;
CONSTANTS(:,57) = 129.6486;
CONSTANTS(:,58) = 350.5314;
CONSTANTS(:,59) = 50.010747;
CONSTANTS(:,60) = 15;
CONSTANTS(:,61) = -5.6;
CONSTANTS(:,62) = 2;
CONSTANTS(:,63) = 8;
CONSTANTS(:,64) = 75;
CONSTANTS(:,65) = 1;
CONSTANTS(:,66) = 1;
CONSTANTS(:,67) = 0.5;
STATES(:,5) = 87.93968;
STATES(:,6) = 90.6179;
STATES(:,7) = 0.698577;
STATES(:,8) = 23.5957;
STATES(:,9) = 31.1705;
STATES(:,10) = 138.4476;
STATES(:,11) = 519.7915;
STATES(:,12) = 129.6439;
STATES(:,13) = 256.8555;
STATES(:,14) = 2961.6507;
STATES(:,15) = 232.46638962;
CONSTANTS(:,68) = 1e-4;
CONSTANTS(:,69) = 0.05;
CONSTANTS(:,70) = 0.05;
CONSTANTS(:,71) = 1e-4;
CONSTANTS(:,72) = 0.03;
CONSTANTS(:,73) = 4.2958026137;
CONSTANTS(:,74) = 0.0565149137;
CONSTANTS(:,75) = 0.0309026688;
CONSTANTS(:,76) = 1e-4;
CONSTANTS(:,77) = 1.5365929068;
CONSTANTS(:,78) = 2.6893667388;
CONSTANTS(:,79) = 3.1321449506;
CONSTANTS(:,80) = 7.7147;
CONSTANTS(:,81) = 27.87028922;
CONSTANTS(:,82) = 1.801907e-4;
CONSTANTS(:,83) = 1.932239e-4;
STATES(:,16) = 33.1398;
STATES(:,17) = 60.11203897;
STATES(:,18) = 58.926;
STATES(:,19) = 107.57022;
STATES(:,20) = 293.0398;
STATES(:,21) = 1.2282;
STATES(:,22) = 57.1876;
CONSTANTS(:,84) = 1;
CONSTANTS(:,85) = 40;
CONSTANTS(:,86) = 785;
CONSTANTS(:,87) = 15;
CONSTANTS(:,88) = 2.642367;
CONSTANTS(:,89) = 2.642367;
CONSTANTS(:,90) = 5.073345;
CONSTANTS(:,91) = 5.073345;
CONSTANTS(:,92) = 4.227788;
CONSTANTS(:,93) = 0.4932479;
CONSTANTS(:,94) = 0.4932479;
CONSTANTS(:,95) = 0.4932479;
CONSTANTS(:,96) = 0.13;
CONSTANTS(:,97) = 0.05507;
CONSTANTS(:,98) = 0.09129;
CONSTANTS(:,99) = 0.15602;
CONSTANTS(:,100) = 1.8;
CONSTANTS(:,101) = 0.58155;
CONSTANTS(:,102) = 0.68372;
CONSTANTS(:,103) = 0.832299;
STATES(:,23) = 2.76087;
STATES(:,24) = 4.41135;
STATES(:,25) = 4.992799;
STATES(:,26) = 4.22047;
STATES(:,27) = 8.55228;
STATES(:,28) = 7.8362;
STATES(:,29) = 8.213955;
STATES(:,30) = 8.76758;
CONSTANTS(:,104) =  (CONSTANTS(:,25)./CONSTANTS(:,24)).*60.0000;
CONSTANTS(:,105) = CONSTANTS(:,61) - CONSTANTS(:,20);
CONSTANTS(:,106) =  CONSTANTS(:,22).*power((( 1.00000.*1.00000)./CONSTANTS(:,24)), 1.0 ./ 2).*7.74597;
CONSTANTS(:,107) = 60.0000./CONSTANTS(:,24);
CONSTANTS(:,108) =  CONSTANTS(:,23).*power((1.00000./CONSTANTS(:,24)), 1.0 ./ 2).*7.74597;
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(:,27) = STATES(:,18)./CONSTANTS(:,79) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,18)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,28) = ALGEBRAIC(:,27)+CONSTANTS(:,61);
ALGEBRAIC(:,30) = STATES(:,19)./CONSTANTS(:,80) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,19)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,31) = ALGEBRAIC(:,30)+CONSTANTS(:,61);
ALGEBRAIC(:,32) = (ALGEBRAIC(:,28) - ALGEBRAIC(:,31))./CONSTANTS(:,74);
ALGEBRAIC(:,33) = STATES(:,20)./CONSTANTS(:,81) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,20)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,34) = ALGEBRAIC(:,33)+CONSTANTS(:,61);
ALGEBRAIC(:,35) = (ALGEBRAIC(:,31) - ALGEBRAIC(:,34))./CONSTANTS(:,75);
RATES(:,19) = ALGEBRAIC(:,32) - ALGEBRAIC(:,35);
ALGEBRAIC(:,36) = (ALGEBRAIC(:,28) - ALGEBRAIC(:,34))./CONSTANTS(:,73);
RATES(:,18) = (STATES(:,22) - ALGEBRAIC(:,36)) - ALGEBRAIC(:,32);
ALGEBRAIC(:,37) =  CONSTANTS(:,42).*arbitrary_log((STATES(:,11) - CONSTANTS(:,44))./CONSTANTS(:,43)+1.00000, 10);
ALGEBRAIC(:,38) =  CONSTANTS(:,46).*exp( CONSTANTS(:,49).*(STATES(:,11) - CONSTANTS(:,44)))+ CONSTANTS(:,47).*power(STATES(:,11) - CONSTANTS(:,44), 2.00000);
ALGEBRAIC(:,39) =  CONSTANTS(:,67).*ALGEBRAIC(:,37)+ (1.00000 - CONSTANTS(:,67)).*ALGEBRAIC(:,38);
RATES(:,6) = (ALGEBRAIC(:,39) - STATES(:,6))./CONSTANTS(:,60);
ALGEBRAIC(:,40) = STATES(:,12)./CONSTANTS(:,38) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,12)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,41) = (ALGEBRAIC(:,40) - ALGEBRAIC(:,39))./CONSTANTS(:,32);
RATES(:,12) = STATES(:,8) - ALGEBRAIC(:,41);
ALGEBRAIC(:,45) = CONSTANTS(:,35)+ CONSTANTS(:,48).*exp( 4.00000.*CONSTANTS(:,67))+ CONSTANTS(:,48).*power(CONSTANTS(:,45)./STATES(:,11), 2.00000);
ALGEBRAIC(:,42) = STATES(:,13)./CONSTANTS(:,39) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,13)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,47) = (ALGEBRAIC(:,39) - ALGEBRAIC(:,42))./ALGEBRAIC(:,45);
RATES(:,11) = ALGEBRAIC(:,41) - ALGEBRAIC(:,47);
ALGEBRAIC(:,43) =  CONSTANTS(:,50).*arbitrary_log(CONSTANTS(:,51)./STATES(:,14) - 0.990000, 10).* - 1.00000;
ALGEBRAIC(:,44) = (ALGEBRAIC(:,42) - ALGEBRAIC(:,43))./CONSTANTS(:,33);
RATES(:,13) = ALGEBRAIC(:,47) - ALGEBRAIC(:,44);
ALGEBRAIC(:,46) = piecewise({STATES(:,15)>CONSTANTS(:,57), (CONSTANTS(:,52)+ CONSTANTS(:,54).*exp(CONSTANTS(:,57)./CONSTANTS(:,59))+( CONSTANTS(:,53).*(STATES(:,15) - CONSTANTS(:,57)))./1.00000) - CONSTANTS(:,62)./(exp(STATES(:,15)./CONSTANTS(:,63)) - 1.00000) }, (CONSTANTS(:,52)+ CONSTANTS(:,54).*exp(STATES(:,15)./CONSTANTS(:,59))) - CONSTANTS(:,62)./(exp(STATES(:,15)./CONSTANTS(:,63)) - 1.00000));
ALGEBRAIC(:,48) = ALGEBRAIC(:,46)+CONSTANTS(:,61);
ALGEBRAIC(:,49) = (ALGEBRAIC(:,43) - ALGEBRAIC(:,48))./CONSTANTS(:,34);
RATES(:,14) = ALGEBRAIC(:,44) - ALGEBRAIC(:,49);
ALGEBRAIC(:,50) =  ((((( CONSTANTS(:,31).*CONSTANTS(:,28).*STATES(:,7) -  CONSTANTS(:,31).*CONSTANTS(:,28).*STATES(:,8).*0.0600000)+ (( STATES(:,10).*CONSTANTS(:,28))./CONSTANTS(:,37)).*0.0600000) -  (( CONSTANTS(:,28).*CONSTANTS(:,62))./(exp(STATES(:,10)./CONSTANTS(:,63)) - 1.00000)).*0.0600000)+ ALGEBRAIC(:,48).*CONSTANTS(:,31).*0.0600000)./(CONSTANTS(:,28)+CONSTANTS(:,31))).*16.6667;
RATES(:,8) = ((ALGEBRAIC(:,50) -  STATES(:,8).*CONSTANTS(:,29)) - ALGEBRAIC(:,40))./CONSTANTS(:,41);
RATES(:,7) =  (((STATES(:,5) -  STATES(:,7).*CONSTANTS(:,27).*16.6667) - ALGEBRAIC(:,50))./CONSTANTS(:,40)).*0.0600000;
ALGEBRAIC(:,52) = (ALGEBRAIC(:,50) - ALGEBRAIC(:,48))./CONSTANTS(:,28);
RATES(:,10) =  ((STATES(:,7) -  STATES(:,8).*0.0600000) -  ALGEBRAIC(:,52).*0.0600000).*16.6667;
RATES(:,9) = ((STATES(:,5) - STATES(:,9)./CONSTANTS(:,36))+( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,9)./CONSTANTS(:,63)) - 1.00000))./CONSTANTS(:,30);
RATES(:,17) =  (STATES(:,21) -  STATES(:,22).*0.0600000).*16.6667;
ALGEBRAIC(:,61) = ( RATES(:,17).*CONSTANTS(:,70)+CONSTANTS(:,61)+STATES(:,17)./CONSTANTS(:,78)) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,17)./CONSTANTS(:,63)) - 1.00000);
RATES(:,22) = ((ALGEBRAIC(:,61) - ALGEBRAIC(:,28)) -  STATES(:,22).*CONSTANTS(:,72))./CONSTANTS(:,83);
ALGEBRAIC(:,54) = STATES(:,23)+STATES(:,24)+STATES(:,25)+STATES(:,26)+STATES(:,27)+STATES(:,28)+STATES(:,29)+STATES(:,30);
ALGEBRAIC(:,63) = STATES(:,2)+STATES(:,1)+STATES(:,4)+STATES(:,3)+CONSTANTS(:,87)+CONSTANTS(:,21)+ALGEBRAIC(:,54);
ALGEBRAIC(:,64) =  CONSTANTS(:,84).*exp((ALGEBRAIC(:,63) - CONSTANTS(:,86))./CONSTANTS(:,85)) - ( CONSTANTS(:,62).*1.00000)./(exp(ALGEBRAIC(:,63)./CONSTANTS(:,64)) - 1.00000);
ALGEBRAIC(:,65) = ALGEBRAIC(:,64)+CONSTANTS(:,61);
ALGEBRAIC(:,26) = STATES(:,28)./CONSTANTS(:,101) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,28)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,72) = ALGEBRAIC(:,26)+ALGEBRAIC(:,65);
ALGEBRAIC(:,24) = STATES(:,29)./CONSTANTS(:,102) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,29)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,69) = ALGEBRAIC(:,24)+ALGEBRAIC(:,65);
ALGEBRAIC(:,74) = (ALGEBRAIC(:,72) - ALGEBRAIC(:,69))./CONSTANTS(:,93);
ALGEBRAIC(:,22) = STATES(:,30)./CONSTANTS(:,103) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,30)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,68) = ALGEBRAIC(:,22)+ALGEBRAIC(:,65);
ALGEBRAIC(:,70) = (ALGEBRAIC(:,69) - ALGEBRAIC(:,68))./CONSTANTS(:,94);
RATES(:,29) = ALGEBRAIC(:,74) - ALGEBRAIC(:,70);
ALGEBRAIC(:,6) = VOI -  floor(VOI./CONSTANTS(:,107)).*CONSTANTS(:,107);
ALGEBRAIC(:,10) = ALGEBRAIC(:,6);
ALGEBRAIC(:,11) = piecewise({ALGEBRAIC(:,10)>=0.00000&ALGEBRAIC(:,10)<=CONSTANTS(:,108), (1.00000 - cos((  pi.*ALGEBRAIC(:,10))./CONSTANTS(:,108)))./2.00000 , ALGEBRAIC(:,10)< 1.50000.*CONSTANTS(:,108)&ALGEBRAIC(:,10)>=CONSTANTS(:,108), (1.00000+cos(( 2.00000.* pi.*(ALGEBRAIC(:,10) - CONSTANTS(:,108)))./CONSTANTS(:,108)))./2.00000 }, 0.00000);
ALGEBRAIC(:,12) = ALGEBRAIC(:,11);
ALGEBRAIC(:,15) =  (CONSTANTS(:,16) - CONSTANTS(:,17)).*ALGEBRAIC(:,12)+CONSTANTS(:,17);
ALGEBRAIC(:,71) =  (1.00000 - ALGEBRAIC(:,12)).*(CONSTANTS(:,7) - CONSTANTS(:,8))+CONSTANTS(:,8);
ALGEBRAIC(:,73) =  (STATES(:,1) - ALGEBRAIC(:,71)).*ALGEBRAIC(:,15) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,1)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,75) = ALGEBRAIC(:,73)+ALGEBRAIC(:,65);
ALGEBRAIC(:,77) = (ALGEBRAIC(:,68) - ALGEBRAIC(:,75))./CONSTANTS(:,95);
RATES(:,30) = ALGEBRAIC(:,70) - ALGEBRAIC(:,77);
ALGEBRAIC(:,17) =  (CONSTANTS(:,18) - CONSTANTS(:,19)).*ALGEBRAIC(:,11)+CONSTANTS(:,19);
ALGEBRAIC(:,56) =  (1.00000 - ALGEBRAIC(:,11)).*(CONSTANTS(:,5) - CONSTANTS(:,6))+CONSTANTS(:,6);
ALGEBRAIC(:,58) =  (STATES(:,3) - ALGEBRAIC(:,56)).*ALGEBRAIC(:,17) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,3)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,76) = ALGEBRAIC(:,58)+ALGEBRAIC(:,65);
ALGEBRAIC(:,78) = (ALGEBRAIC(:,34) - ALGEBRAIC(:,76))./CONSTANTS(:,76);
RATES(:,20) = (ALGEBRAIC(:,35)+ALGEBRAIC(:,36)) - ALGEBRAIC(:,78);
ALGEBRAIC(:,53) =  CONSTANTS(:,55).*power(CONSTANTS(:,58)./STATES(:,15), 2.00000)+CONSTANTS(:,56);
ALGEBRAIC(:,79) = (ALGEBRAIC(:,48) - ALGEBRAIC(:,75))./ALGEBRAIC(:,53);
RATES(:,15) = (ALGEBRAIC(:,49)+ALGEBRAIC(:,52)) - ALGEBRAIC(:,79);
ALGEBRAIC(:,8) = ALGEBRAIC(:,6) - CONSTANTS(:,11);
ALGEBRAIC(:,13) = piecewise({ALGEBRAIC(:,8)>=0.00000&ALGEBRAIC(:,8)<=CONSTANTS(:,106), (1.00000 - cos((  pi.*ALGEBRAIC(:,8))./CONSTANTS(:,106)))./2.00000 , ALGEBRAIC(:,8)< 1.50000.*CONSTANTS(:,106)&ALGEBRAIC(:,8)>=CONSTANTS(:,106), (1.00000+cos(( 2.00000.* pi.*(ALGEBRAIC(:,8) - CONSTANTS(:,106)))./CONSTANTS(:,106)))./2.00000 }, 0.00000);
ALGEBRAIC(:,18) =  (CONSTANTS(:,12) - CONSTANTS(:,13)).*ALGEBRAIC(:,13)+CONSTANTS(:,13);
ALGEBRAIC(:,59) =  (1.00000 - ALGEBRAIC(:,13)).*(CONSTANTS(:,1) - CONSTANTS(:,2))+CONSTANTS(:,2);
ALGEBRAIC(:,60) =  (STATES(:,4) - ALGEBRAIC(:,59)).*ALGEBRAIC(:,18) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,4)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,80) = ALGEBRAIC(:,60)+ALGEBRAIC(:,65);
ALGEBRAIC(:,81) = piecewise({ALGEBRAIC(:,76)>ALGEBRAIC(:,80), (ALGEBRAIC(:,76) - ALGEBRAIC(:,80))./CONSTANTS(:,10) }, 0.00000);
RATES(:,3) = ALGEBRAIC(:,78) - ALGEBRAIC(:,81);
ALGEBRAIC(:,84) = piecewise({ALGEBRAIC(:,80)>STATES(:,5), (ALGEBRAIC(:,80) - STATES(:,5))./CONSTANTS(:,26) }, 0.00000);
ALGEBRAIC(:,19) = STATES(:,5);
ALGEBRAIC(:,21) = STATES(:,24)./CONSTANTS(:,97) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,24)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,66) = ALGEBRAIC(:,21)+ALGEBRAIC(:,65);
ALGEBRAIC(:,67) = (ALGEBRAIC(:,19) - ALGEBRAIC(:,66))./CONSTANTS(:,88);
RATES(:,5) =  (((ALGEBRAIC(:,84) - RATES(:,9)) -  STATES(:,7).*16.6667) - ALGEBRAIC(:,67)).*(1.00000./CONSTANTS(:,96)+( (CONSTANTS(:,62)./1.00000).*exp(STATES(:,23)./CONSTANTS(:,65)))./power(exp(STATES(:,23)./CONSTANTS(:,65)) - 1.00000, 2.00000));
RATES(:,23) = ((ALGEBRAIC(:,84) - RATES(:,9)) -  STATES(:,7).*16.6667) - ALGEBRAIC(:,67);
RATES(:,4) = ALGEBRAIC(:,81) - ALGEBRAIC(:,84);
ALGEBRAIC(:,83) = abs((ALGEBRAIC(:,80) - ALGEBRAIC(:,65))./2.00000);
ALGEBRAIC(:,20) = STATES(:,27)./CONSTANTS(:,100) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,27)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,86) = ALGEBRAIC(:,20)+ALGEBRAIC(:,83);
ALGEBRAIC(:,88) = (ALGEBRAIC(:,86) - ALGEBRAIC(:,72))./CONSTANTS(:,92);
RATES(:,28) = ALGEBRAIC(:,88) - ALGEBRAIC(:,74);
ALGEBRAIC(:,14) = ALGEBRAIC(:,13);
ALGEBRAIC(:,16) =  (CONSTANTS(:,14) - CONSTANTS(:,15)).*ALGEBRAIC(:,14)+CONSTANTS(:,15);
ALGEBRAIC(:,82) =  (1.00000 - ALGEBRAIC(:,14)).*(CONSTANTS(:,3) - CONSTANTS(:,4))+CONSTANTS(:,4);
ALGEBRAIC(:,85) =  (STATES(:,2) - ALGEBRAIC(:,82)).*ALGEBRAIC(:,16) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,2)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,87) = ALGEBRAIC(:,85)+ALGEBRAIC(:,65);
ALGEBRAIC(:,89) = piecewise({ALGEBRAIC(:,75)>ALGEBRAIC(:,87), (ALGEBRAIC(:,75) - ALGEBRAIC(:,87))./CONSTANTS(:,9) }, 0.00000);
RATES(:,1) = (ALGEBRAIC(:,79) - ALGEBRAIC(:,89))+ALGEBRAIC(:,77);
ALGEBRAIC(:,23) = STATES(:,25)./CONSTANTS(:,98) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,25)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,90) = ALGEBRAIC(:,23)+ALGEBRAIC(:,83);
ALGEBRAIC(:,92) = (ALGEBRAIC(:,66) - ALGEBRAIC(:,90))./CONSTANTS(:,89);
RATES(:,24) = ALGEBRAIC(:,67) - ALGEBRAIC(:,92);
ALGEBRAIC(:,91) = ((((( CONSTANTS(:,68).*STATES(:,16))./CONSTANTS(:,77) - ( CONSTANTS(:,68).*CONSTANTS(:,62).*1.00000)./(exp(STATES(:,16)./CONSTANTS(:,63)) - 1.00000))+ ALGEBRAIC(:,87).*CONSTANTS(:,69)) -  CONSTANTS(:,68).*CONSTANTS(:,69).*STATES(:,21).*16.6667)+ CONSTANTS(:,61).*CONSTANTS(:,68))./(CONSTANTS(:,69)+CONSTANTS(:,68));
ALGEBRAIC(:,29) = ((STATES(:,16)./CONSTANTS(:,77)+CONSTANTS(:,61)) -  CONSTANTS(:,69).*STATES(:,21).*16.6667) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,16)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,93) = piecewise({ALGEBRAIC(:,87)>ALGEBRAIC(:,91), ALGEBRAIC(:,91) }, ALGEBRAIC(:,29));
RATES(:,21) =  (((ALGEBRAIC(:,93) - ALGEBRAIC(:,61)) -  STATES(:,21).*CONSTANTS(:,71).*16.6667)./CONSTANTS(:,82)).*0.0600000;
ALGEBRAIC(:,25) = STATES(:,26)./CONSTANTS(:,99) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,26)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,94) = ALGEBRAIC(:,25)+ALGEBRAIC(:,83);
ALGEBRAIC(:,97) = (ALGEBRAIC(:,90) - ALGEBRAIC(:,94))./CONSTANTS(:,90);
RATES(:,25) = ALGEBRAIC(:,92) - ALGEBRAIC(:,97);
ALGEBRAIC(:,95) = piecewise({ALGEBRAIC(:,87)>ALGEBRAIC(:,93), (ALGEBRAIC(:,87) - ALGEBRAIC(:,93))./CONSTANTS(:,68) }, 0.00000);
RATES(:,16) = ALGEBRAIC(:,95) -  STATES(:,21).*16.6667;
RATES(:,2) = ALGEBRAIC(:,89) - ALGEBRAIC(:,95);
ALGEBRAIC(:,98) = (ALGEBRAIC(:,94) - ALGEBRAIC(:,86))./CONSTANTS(:,91);
RATES(:,27) = ALGEBRAIC(:,98) - ALGEBRAIC(:,88);
RATES(:,26) = ALGEBRAIC(:,97) - ALGEBRAIC(:,98);
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(:,27) = STATES(:,18)./CONSTANTS(:,79) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,18)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,28) = ALGEBRAIC(:,27)+CONSTANTS(:,61);
ALGEBRAIC(:,30) = STATES(:,19)./CONSTANTS(:,80) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,19)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,31) = ALGEBRAIC(:,30)+CONSTANTS(:,61);
ALGEBRAIC(:,32) = (ALGEBRAIC(:,28) - ALGEBRAIC(:,31))./CONSTANTS(:,74);
ALGEBRAIC(:,33) = STATES(:,20)./CONSTANTS(:,81) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,20)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,34) = ALGEBRAIC(:,33)+CONSTANTS(:,61);
ALGEBRAIC(:,35) = (ALGEBRAIC(:,31) - ALGEBRAIC(:,34))./CONSTANTS(:,75);
ALGEBRAIC(:,36) = (ALGEBRAIC(:,28) - ALGEBRAIC(:,34))./CONSTANTS(:,73);
ALGEBRAIC(:,37) =  CONSTANTS(:,42).*arbitrary_log((STATES(:,11) - CONSTANTS(:,44))./CONSTANTS(:,43)+1.00000, 10);
ALGEBRAIC(:,38) =  CONSTANTS(:,46).*exp( CONSTANTS(:,49).*(STATES(:,11) - CONSTANTS(:,44)))+ CONSTANTS(:,47).*power(STATES(:,11) - CONSTANTS(:,44), 2.00000);
ALGEBRAIC(:,39) =  CONSTANTS(:,67).*ALGEBRAIC(:,37)+ (1.00000 - CONSTANTS(:,67)).*ALGEBRAIC(:,38);
ALGEBRAIC(:,40) = STATES(:,12)./CONSTANTS(:,38) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,12)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,41) = (ALGEBRAIC(:,40) - ALGEBRAIC(:,39))./CONSTANTS(:,32);
ALGEBRAIC(:,45) = CONSTANTS(:,35)+ CONSTANTS(:,48).*exp( 4.00000.*CONSTANTS(:,67))+ CONSTANTS(:,48).*power(CONSTANTS(:,45)./STATES(:,11), 2.00000);
ALGEBRAIC(:,42) = STATES(:,13)./CONSTANTS(:,39) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,13)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,47) = (ALGEBRAIC(:,39) - ALGEBRAIC(:,42))./ALGEBRAIC(:,45);
ALGEBRAIC(:,43) =  CONSTANTS(:,50).*arbitrary_log(CONSTANTS(:,51)./STATES(:,14) - 0.990000, 10).* - 1.00000;
ALGEBRAIC(:,44) = (ALGEBRAIC(:,42) - ALGEBRAIC(:,43))./CONSTANTS(:,33);
ALGEBRAIC(:,46) = piecewise({STATES(:,15)>CONSTANTS(:,57), (CONSTANTS(:,52)+ CONSTANTS(:,54).*exp(CONSTANTS(:,57)./CONSTANTS(:,59))+( CONSTANTS(:,53).*(STATES(:,15) - CONSTANTS(:,57)))./1.00000) - CONSTANTS(:,62)./(exp(STATES(:,15)./CONSTANTS(:,63)) - 1.00000) }, (CONSTANTS(:,52)+ CONSTANTS(:,54).*exp(STATES(:,15)./CONSTANTS(:,59))) - CONSTANTS(:,62)./(exp(STATES(:,15)./CONSTANTS(:,63)) - 1.00000));
ALGEBRAIC(:,48) = ALGEBRAIC(:,46)+CONSTANTS(:,61);
ALGEBRAIC(:,49) = (ALGEBRAIC(:,43) - ALGEBRAIC(:,48))./CONSTANTS(:,34);
ALGEBRAIC(:,50) =  ((((( CONSTANTS(:,31).*CONSTANTS(:,28).*STATES(:,7) -  CONSTANTS(:,31).*CONSTANTS(:,28).*STATES(:,8).*0.0600000)+ (( STATES(:,10).*CONSTANTS(:,28))./CONSTANTS(:,37)).*0.0600000) -  (( CONSTANTS(:,28).*CONSTANTS(:,62))./(exp(STATES(:,10)./CONSTANTS(:,63)) - 1.00000)).*0.0600000)+ ALGEBRAIC(:,48).*CONSTANTS(:,31).*0.0600000)./(CONSTANTS(:,28)+CONSTANTS(:,31))).*16.6667;
ALGEBRAIC(:,52) = (ALGEBRAIC(:,50) - ALGEBRAIC(:,48))./CONSTANTS(:,28);
ALGEBRAIC(:,61) = ( RATES(:,17).*CONSTANTS(:,70)+CONSTANTS(:,61)+STATES(:,17)./CONSTANTS(:,78)) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,17)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,54) = STATES(:,23)+STATES(:,24)+STATES(:,25)+STATES(:,26)+STATES(:,27)+STATES(:,28)+STATES(:,29)+STATES(:,30);
ALGEBRAIC(:,63) = STATES(:,2)+STATES(:,1)+STATES(:,4)+STATES(:,3)+CONSTANTS(:,87)+CONSTANTS(:,21)+ALGEBRAIC(:,54);
ALGEBRAIC(:,64) =  CONSTANTS(:,84).*exp((ALGEBRAIC(:,63) - CONSTANTS(:,86))./CONSTANTS(:,85)) - ( CONSTANTS(:,62).*1.00000)./(exp(ALGEBRAIC(:,63)./CONSTANTS(:,64)) - 1.00000);
ALGEBRAIC(:,65) = ALGEBRAIC(:,64)+CONSTANTS(:,61);
ALGEBRAIC(:,26) = STATES(:,28)./CONSTANTS(:,101) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,28)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,72) = ALGEBRAIC(:,26)+ALGEBRAIC(:,65);
ALGEBRAIC(:,24) = STATES(:,29)./CONSTANTS(:,102) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,29)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,69) = ALGEBRAIC(:,24)+ALGEBRAIC(:,65);
ALGEBRAIC(:,74) = (ALGEBRAIC(:,72) - ALGEBRAIC(:,69))./CONSTANTS(:,93);
ALGEBRAIC(:,22) = STATES(:,30)./CONSTANTS(:,103) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,30)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,68) = ALGEBRAIC(:,22)+ALGEBRAIC(:,65);
ALGEBRAIC(:,70) = (ALGEBRAIC(:,69) - ALGEBRAIC(:,68))./CONSTANTS(:,94);
ALGEBRAIC(:,6) = VOI -  floor(VOI./CONSTANTS(:,107)).*CONSTANTS(:,107);
ALGEBRAIC(:,10) = ALGEBRAIC(:,6);
ALGEBRAIC(:,11) = piecewise({ALGEBRAIC(:,10)>=0.00000&ALGEBRAIC(:,10)<=CONSTANTS(:,108), (1.00000 - cos((  pi.*ALGEBRAIC(:,10))./CONSTANTS(:,108)))./2.00000 , ALGEBRAIC(:,10)< 1.50000.*CONSTANTS(:,108)&ALGEBRAIC(:,10)>=CONSTANTS(:,108), (1.00000+cos(( 2.00000.* pi.*(ALGEBRAIC(:,10) - CONSTANTS(:,108)))./CONSTANTS(:,108)))./2.00000 }, 0.00000);
ALGEBRAIC(:,12) = ALGEBRAIC(:,11);
ALGEBRAIC(:,15) =  (CONSTANTS(:,16) - CONSTANTS(:,17)).*ALGEBRAIC(:,12)+CONSTANTS(:,17);
ALGEBRAIC(:,71) =  (1.00000 - ALGEBRAIC(:,12)).*(CONSTANTS(:,7) - CONSTANTS(:,8))+CONSTANTS(:,8);
ALGEBRAIC(:,73) =  (STATES(:,1) - ALGEBRAIC(:,71)).*ALGEBRAIC(:,15) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,1)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,75) = ALGEBRAIC(:,73)+ALGEBRAIC(:,65);
ALGEBRAIC(:,77) = (ALGEBRAIC(:,68) - ALGEBRAIC(:,75))./CONSTANTS(:,95);
ALGEBRAIC(:,17) =  (CONSTANTS(:,18) - CONSTANTS(:,19)).*ALGEBRAIC(:,11)+CONSTANTS(:,19);
ALGEBRAIC(:,56) =  (1.00000 - ALGEBRAIC(:,11)).*(CONSTANTS(:,5) - CONSTANTS(:,6))+CONSTANTS(:,6);
ALGEBRAIC(:,58) =  (STATES(:,3) - ALGEBRAIC(:,56)).*ALGEBRAIC(:,17) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,3)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,76) = ALGEBRAIC(:,58)+ALGEBRAIC(:,65);
ALGEBRAIC(:,78) = (ALGEBRAIC(:,34) - ALGEBRAIC(:,76))./CONSTANTS(:,76);
ALGEBRAIC(:,53) =  CONSTANTS(:,55).*power(CONSTANTS(:,58)./STATES(:,15), 2.00000)+CONSTANTS(:,56);
ALGEBRAIC(:,79) = (ALGEBRAIC(:,48) - ALGEBRAIC(:,75))./ALGEBRAIC(:,53);
ALGEBRAIC(:,8) = ALGEBRAIC(:,6) - CONSTANTS(:,11);
ALGEBRAIC(:,13) = piecewise({ALGEBRAIC(:,8)>=0.00000&ALGEBRAIC(:,8)<=CONSTANTS(:,106), (1.00000 - cos((  pi.*ALGEBRAIC(:,8))./CONSTANTS(:,106)))./2.00000 , ALGEBRAIC(:,8)< 1.50000.*CONSTANTS(:,106)&ALGEBRAIC(:,8)>=CONSTANTS(:,106), (1.00000+cos(( 2.00000.* pi.*(ALGEBRAIC(:,8) - CONSTANTS(:,106)))./CONSTANTS(:,106)))./2.00000 }, 0.00000);
ALGEBRAIC(:,18) =  (CONSTANTS(:,12) - CONSTANTS(:,13)).*ALGEBRAIC(:,13)+CONSTANTS(:,13);
ALGEBRAIC(:,59) =  (1.00000 - ALGEBRAIC(:,13)).*(CONSTANTS(:,1) - CONSTANTS(:,2))+CONSTANTS(:,2);
ALGEBRAIC(:,60) =  (STATES(:,4) - ALGEBRAIC(:,59)).*ALGEBRAIC(:,18) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,4)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,80) = ALGEBRAIC(:,60)+ALGEBRAIC(:,65);
ALGEBRAIC(:,81) = piecewise({ALGEBRAIC(:,76)>ALGEBRAIC(:,80), (ALGEBRAIC(:,76) - ALGEBRAIC(:,80))./CONSTANTS(:,10) }, 0.00000);
ALGEBRAIC(:,84) = piecewise({ALGEBRAIC(:,80)>STATES(:,5), (ALGEBRAIC(:,80) - STATES(:,5))./CONSTANTS(:,26) }, 0.00000);
ALGEBRAIC(:,19) = STATES(:,5);
ALGEBRAIC(:,21) = STATES(:,24)./CONSTANTS(:,97) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,24)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,66) = ALGEBRAIC(:,21)+ALGEBRAIC(:,65);
ALGEBRAIC(:,67) = (ALGEBRAIC(:,19) - ALGEBRAIC(:,66))./CONSTANTS(:,88);
ALGEBRAIC(:,83) = abs((ALGEBRAIC(:,80) - ALGEBRAIC(:,65))./2.00000);
ALGEBRAIC(:,20) = STATES(:,27)./CONSTANTS(:,100) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,27)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,86) = ALGEBRAIC(:,20)+ALGEBRAIC(:,83);
ALGEBRAIC(:,88) = (ALGEBRAIC(:,86) - ALGEBRAIC(:,72))./CONSTANTS(:,92);
ALGEBRAIC(:,14) = ALGEBRAIC(:,13);
ALGEBRAIC(:,16) =  (CONSTANTS(:,14) - CONSTANTS(:,15)).*ALGEBRAIC(:,14)+CONSTANTS(:,15);
ALGEBRAIC(:,82) =  (1.00000 - ALGEBRAIC(:,14)).*(CONSTANTS(:,3) - CONSTANTS(:,4))+CONSTANTS(:,4);
ALGEBRAIC(:,85) =  (STATES(:,2) - ALGEBRAIC(:,82)).*ALGEBRAIC(:,16) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,2)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,87) = ALGEBRAIC(:,85)+ALGEBRAIC(:,65);
ALGEBRAIC(:,89) = piecewise({ALGEBRAIC(:,75)>ALGEBRAIC(:,87), (ALGEBRAIC(:,75) - ALGEBRAIC(:,87))./CONSTANTS(:,9) }, 0.00000);
ALGEBRAIC(:,23) = STATES(:,25)./CONSTANTS(:,98) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,25)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,90) = ALGEBRAIC(:,23)+ALGEBRAIC(:,83);
ALGEBRAIC(:,92) = (ALGEBRAIC(:,66) - ALGEBRAIC(:,90))./CONSTANTS(:,89);
ALGEBRAIC(:,91) = ((((( CONSTANTS(:,68).*STATES(:,16))./CONSTANTS(:,77) - ( CONSTANTS(:,68).*CONSTANTS(:,62).*1.00000)./(exp(STATES(:,16)./CONSTANTS(:,63)) - 1.00000))+ ALGEBRAIC(:,87).*CONSTANTS(:,69)) -  CONSTANTS(:,68).*CONSTANTS(:,69).*STATES(:,21).*16.6667)+ CONSTANTS(:,61).*CONSTANTS(:,68))./(CONSTANTS(:,69)+CONSTANTS(:,68));
ALGEBRAIC(:,29) = ((STATES(:,16)./CONSTANTS(:,77)+CONSTANTS(:,61)) -  CONSTANTS(:,69).*STATES(:,21).*16.6667) - ( CONSTANTS(:,62).*1.00000)./(exp(STATES(:,16)./CONSTANTS(:,63)) - 1.00000);
ALGEBRAIC(:,93) = piecewise({ALGEBRAIC(:,87)>ALGEBRAIC(:,91), ALGEBRAIC(:,91) }, ALGEBRAIC(:,29));
ALGEBRAIC(:,25) = STATES(:,26)./CONSTANTS(:,99) - ( CONSTANTS(:,66).*1.00000)./(exp(STATES(:,26)./CONSTANTS(:,65)) - 1.00000);
ALGEBRAIC(:,94) = ALGEBRAIC(:,25)+ALGEBRAIC(:,83);
ALGEBRAIC(:,97) = (ALGEBRAIC(:,90) - ALGEBRAIC(:,94))./CONSTANTS(:,90);
ALGEBRAIC(:,95) = piecewise({ALGEBRAIC(:,87)>ALGEBRAIC(:,93), (ALGEBRAIC(:,87) - ALGEBRAIC(:,93))./CONSTANTS(:,68) }, 0.00000);
ALGEBRAIC(:,98) = (ALGEBRAIC(:,94) - ALGEBRAIC(:,86))./CONSTANTS(:,91);
ALGEBRAIC(:,1) = STATES(:,5) - CONSTANTS(:,61);
ALGEBRAIC(:,2) = STATES(:,9)+STATES(:,10)+STATES(:,11)+STATES(:,12);
ALGEBRAIC(:,3) = STATES(:,14)+STATES(:,15);
ALGEBRAIC(:,4) = STATES(:,16)+STATES(:,17)+STATES(:,18);
ALGEBRAIC(:,5) = STATES(:,20);
ALGEBRAIC(:,7) = piecewise({VOI>ALGEBRAIC(:,6)&VOI<ALGEBRAIC(:,6)+0.0200000, 5.00000 , VOI>ALGEBRAIC(:,6)+CONSTANTS(:,11)&VOI<ALGEBRAIC(:,6)+CONSTANTS(:,11)+0.0200000, 10.0000 }, 0.00000);
ALGEBRAIC(:,9) = ALGEBRAIC(:,1);
ALGEBRAIC(:,51) = ALGEBRAIC(:,50) - CONSTANTS(:,20);
ALGEBRAIC(:,55) = STATES(:,1)+STATES(:,2)+STATES(:,16)+STATES(:,17)+STATES(:,18)+STATES(:,19)+STATES(:,20)+STATES(:,3)+STATES(:,4)+STATES(:,9)+STATES(:,10)+STATES(:,11)+STATES(:,12)+STATES(:,13)+STATES(:,14)+STATES(:,15)+CONSTANTS(:,87)+ALGEBRAIC(:,54);
ALGEBRAIC(:,57) = ALGEBRAIC(:,55) - CONSTANTS(:,87);
ALGEBRAIC(:,62) = ALGEBRAIC(:,61) - CONSTANTS(:,61);
ALGEBRAIC(:,96) = ALGEBRAIC(:,93) - CONSTANTS(:,61);
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

% Compute a logarithm to any base" +
function x = arbitrary_log(a, base)
x = log(a) ./ log(base);
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 Heldt 2002 at changeset adaa6a7dad26.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: