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 =30;
end
% There are a total of 36 entries in each of the rate and state variable arrays.
% There are a total of 136 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 (minute)');
    LEGEND_STATES(:,1) = strpad('mass in component mass (dimensionless)');
    LEGEND_CONSTANTS(:,1) = strpad('kg in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,2) = strpad('Cln2 in component Cln2 (dimensionless)');
    LEGEND_CONSTANTS(:,2) = strpad('ks_n2_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,3) = strpad('ks_n2__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,4) = strpad('kd_n2 in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,28) = strpad('SBF in component SBF_MBF (dimensionless)');
    LEGEND_STATES(:,3) = strpad('Clb5 in component Clb5 (dimensionless)');
    LEGEND_CONSTANTS(:,5) = strpad('ks_b5_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,6) = strpad('ks_b5__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,7) = strpad('kdi_f5 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,8) = strpad('kdi_b5 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,9) = strpad('kas_b5 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,10) = strpad('kas_f5 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,11) = strpad('kd3_f6 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,12) = strpad('kd3_c1 in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,21) = strpad('Vd_b5 in component Vd_b5 (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,27) = strpad('MBF in component SBF_MBF (dimensionless)');
    LEGEND_STATES(:,4) = strpad('C5P in component C5P (dimensionless)');
    LEGEND_STATES(:,5) = strpad('C5 in component C5 (dimensionless)');
    LEGEND_STATES(:,6) = strpad('F5P in component F5P (dimensionless)');
    LEGEND_STATES(:,7) = strpad('F5 in component F5 (dimensionless)');
    LEGEND_STATES(:,8) = strpad('Sic1 in component Sic1 (dimensionless)');
    LEGEND_STATES(:,9) = strpad('Cdc6 in component Cdc6 (dimensionless)');
    LEGEND_STATES(:,10) = strpad('Clb2 in component Clb2 (dimensionless)');
    LEGEND_CONSTANTS(:,13) = strpad('ks_b2_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,14) = strpad('ks_b2__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,15) = strpad('kdi_b2 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,16) = strpad('kdi_f2 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,17) = strpad('kas_b2 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,18) = strpad('kas_f2 in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,22) = strpad('Vd_b2 in component Vd_b2 (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,8) = strpad('Mcm1 in component Mcm1 (dimensionless)');
    LEGEND_STATES(:,11) = strpad('C2P in component C2P (dimensionless)');
    LEGEND_STATES(:,12) = strpad('C2 in component C2 (dimensionless)');
    LEGEND_STATES(:,13) = strpad('F2P in component F2P (dimensionless)');
    LEGEND_STATES(:,14) = strpad('F2 in component F2 (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('ks_c1_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,20) = strpad('ks_c1__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,21) = strpad('kpp_c1 in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,24) = strpad('Vkp_c1 in component Vkp_c1 (first_order_rate_constant)');
    LEGEND_STATES(:,15) = strpad('Swi5 in component Swi5 (dimensionless)');
    LEGEND_STATES(:,16) = strpad('Cdc14 in component Cdc14 (dimensionless)');
    LEGEND_STATES(:,17) = strpad('Sic1P in component Sic1P (dimensionless)');
    LEGEND_CONSTANTS(:,22) = strpad('ks_f6_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,23) = strpad('ks_f6__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,24) = strpad('ks_f6___ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,25) = strpad('kpp_f6 in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,29) = strpad('Vkp_f6 in component Vkp_f6 (first_order_rate_constant)');
    LEGEND_STATES(:,18) = strpad('Cdc6P in component Cdc6P (dimensionless)');
    LEGEND_STATES(:,19) = strpad('Pds1 in component Pds1 (dimensionless)');
    LEGEND_CONSTANTS(:,26) = strpad('ks_pds_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,27) = strpad('ks1_pds__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,28) = strpad('ks2_pds__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,29) = strpad('kdi_esp in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,30) = strpad('Vd_pds in component Vd_pds (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,30) = strpad('kas_esp in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,19) = strpad('PE in component PE (dimensionless)');
    LEGEND_STATES(:,20) = strpad('Esp1 in component Esp1 (dimensionless)');
    LEGEND_STATES(:,21) = strpad('ORI in component ORI (dimensionless)');
    LEGEND_CONSTANTS(:,31) = strpad('ks_ori in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,32) = strpad('kd_ori in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,33) = strpad('epsilon_ori_b5 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,34) = strpad('epsilon_ori_b2 in component model_parameters (dimensionless)');
    LEGEND_STATES(:,22) = strpad('BUD in component BUD (dimensionless)');
    LEGEND_CONSTANTS(:,35) = strpad('ks_bud in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,36) = strpad('kd_bud in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,37) = strpad('epsilon_bud_n2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('epsilon_bud_n3 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,39) = strpad('epsilon_bud_b5 in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,11) = strpad('Cln3 in component Cln3 (dimensionless)');
    LEGEND_STATES(:,23) = strpad('SPN in component SPN (dimensionless)');
    LEGEND_CONSTANTS(:,40) = strpad('ks_spn in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,41) = strpad('kd_spn in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,42) = strpad('Jspn in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,26) = strpad('G_sbf in component G_sbf (dimensionless)');
    LEGEND_CONSTANTS(:,43) = strpad('Ji_sbf in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,44) = strpad('Ja_sbf in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,25) = strpad('Vi_sbf in component Vi_sbf (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,23) = strpad('Va_sbf in component Va_sbf (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,1) = strpad('G_mcm in component G_mcm (dimensionless)');
    LEGEND_CONSTANTS(:,45) = strpad('Ji_mcm in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,46) = strpad('Ja_mcm in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,47) = strpad('ki_mcm in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,48) = strpad('ka_mcm in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,49) = strpad('C0 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,50) = strpad('Dn3 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,51) = strpad('Jn3 in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,13) = strpad('Bck2 in component Bck2 (dimensionless)');
    LEGEND_CONSTANTS(:,52) = strpad('B0 in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,2) = strpad('Clb5_T in component Clb5_T (dimensionless)');
    LEGEND_ALGEBRAIC(:,3) = strpad('Clb2_T in component Clb2_T (dimensionless)');
    LEGEND_ALGEBRAIC(:,16) = strpad('Sic1_T in component Sic1_T (dimensionless)');
    LEGEND_STATES(:,24) = strpad('Swi5_T in component Swi5_T (dimensionless)');
    LEGEND_CONSTANTS(:,53) = strpad('ks_swi_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,54) = strpad('ks_swi__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,55) = strpad('kd_swi in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,56) = strpad('ka_swi in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,57) = strpad('ki_swi in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,25) = strpad('APC_P in component APC_P (dimensionless)');
    LEGEND_CONSTANTS(:,58) = strpad('ka_apc in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,59) = strpad('ki_apc in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,60) = strpad('Ja_apc in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,61) = strpad('Ji_apc in component model_parameters (dimensionless)');
    LEGEND_STATES(:,26) = strpad('Cdc20_T in component Cdc20_T (dimensionless)');
    LEGEND_CONSTANTS(:,62) = strpad('ks_20_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,63) = strpad('ks_20__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,64) = strpad('kd_20 in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,27) = strpad('Cdc20_A in component Cdc20_A (dimensionless)');
    LEGEND_CONSTANTS(:,65) = strpad('ka_20_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,66) = strpad('ka_20__ in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,4) = strpad('kmad2 in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,28) = strpad('Cdh1_T in component Cdh1_T (dimensionless)');
    LEGEND_CONSTANTS(:,67) = strpad('ks_cdh in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,68) = strpad('kd_cdh in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,29) = strpad('Cdh1 in component Cdh1 (dimensionless)');
    LEGEND_CONSTANTS(:,69) = strpad('Ja_cdh in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,70) = strpad('Ji_cdh in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,14) = strpad('Va_cdh in component Va_cdh (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,17) = strpad('Vi_cdh in component Vi_cdh (first_order_rate_constant)');
    LEGEND_STATES(:,30) = strpad('Tem1 in component Tem1 (dimensionless)');
    LEGEND_ALGEBRAIC(:,5) = strpad('kbub2 in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,9) = strpad('klte1 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,71) = strpad('Ja_tem in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,72) = strpad('Ji_tem in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,73) = strpad('Tem1_T in component model_parameters (dimensionless)');
    LEGEND_STATES(:,31) = strpad('Cdc15 in component Cdc15 (dimensionless)');
    LEGEND_CONSTANTS(:,74) = strpad('ka_15_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,75) = strpad('ka_15__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,76) = strpad('ka_15___ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,77) = strpad('ki_15 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,78) = strpad('Cdc15_T in component model_parameters (dimensionless)');
    LEGEND_STATES(:,32) = strpad('Cdc14_T in component Cdc14_T (dimensionless)');
    LEGEND_CONSTANTS(:,79) = strpad('ks_14 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,80) = strpad('kd_14 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,81) = strpad('kd_net in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,82) = strpad('kdi_rent in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,83) = strpad('kdi_rentp in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,84) = strpad('kas_rent in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,85) = strpad('kas_rentp in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,33) = strpad('RENT in component RENT (dimensionless)');
    LEGEND_ALGEBRAIC(:,6) = strpad('RENTP in component RENTP (dimensionless)');
    LEGEND_STATES(:,34) = strpad('Net1 in component Net1 (dimensionless)');
    LEGEND_ALGEBRAIC(:,10) = strpad('Net1P in component Net1P (dimensionless)');
    LEGEND_STATES(:,35) = strpad('Net1_T in component Net1_T (dimensionless)');
    LEGEND_CONSTANTS(:,86) = strpad('ks_net in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,18) = strpad('Cdc6_T in component Cdc6_T (dimensionless)');
    LEGEND_ALGEBRAIC(:,20) = strpad('CKI_T in component CKI_T (dimensionless)');
    LEGEND_CONSTANTS(:,87) = strpad('Esp1_T in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,88) = strpad('kd_b5_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,89) = strpad('kd_b5__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,90) = strpad('kd_b2_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,91) = strpad('kd_b2__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,92) = strpad('kd_b2p in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,93) = strpad('ka_sbf in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,94) = strpad('epsilon_sbf_n2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,95) = strpad('epsilon_sbf_n3 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,96) = strpad('epsilon_sbf_b5 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,97) = strpad('ki_sbf_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,98) = strpad('ki_sbf__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,99) = strpad('kd1_c1 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,100) = strpad('kd2_c1 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,101) = strpad('Jd2_c1 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,102) = strpad('epsilon_c1_n2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,103) = strpad('epsilon_c1_n3 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,104) = strpad('epsilon_c1_k2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,105) = strpad('epsilon_c1_b5 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,106) = strpad('epsilon_c1_b2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,107) = strpad('Jd2_f6 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,108) = strpad('kd1_f6 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,109) = strpad('kd2_f6 in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,110) = strpad('epsilon_f6_n2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,111) = strpad('epsilon_f6_n3 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,112) = strpad('epsilon_f6_k2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,113) = strpad('epsilon_f6_b5 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,114) = strpad('epsilon_f6_b2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,115) = strpad('ka_cdh_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,116) = strpad('ka_cdh__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,117) = strpad('ki_cdh_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,118) = strpad('ki_cdh__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,119) = strpad('epsilon_cdh_n2 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,120) = strpad('epsilon_cdh_n3 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,121) = strpad('epsilon_cdh_b5 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,122) = strpad('epsilon_cdh_b2 in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,12) = strpad('Vpp_net in component Vpp_net (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,123) = strpad('kpp_net_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,124) = strpad('kpp_net__ in component model_parameters (first_order_rate_constant)');
    LEGEND_STATES(:,36) = strpad('PPX in component PPX (dimensionless)');
    LEGEND_ALGEBRAIC(:,15) = strpad('Vkp_net in component Vkp_net (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,125) = strpad('kkp_net_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,126) = strpad('kkp_net__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,127) = strpad('ks_ppx in component model_parameters (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,7) = strpad('Vd_ppx in component Vd_ppx (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,128) = strpad('kd_ppx_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,129) = strpad('kd_ppx__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,130) = strpad('Jpds in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,131) = strpad('J20_ppx in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,132) = strpad('kd1_pds_ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,133) = strpad('kd2_pds__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,134) = strpad('kd3_pds__ in component model_parameters (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,135) = strpad('Kez in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,136) = strpad('Kez2 in component model_parameters (dimensionless)');
    LEGEND_RATES(:,1) = strpad('d/dt mass in component mass (dimensionless)');
    LEGEND_RATES(:,2) = strpad('d/dt Cln2 in component Cln2 (dimensionless)');
    LEGEND_RATES(:,3) = strpad('d/dt Clb5 in component Clb5 (dimensionless)');
    LEGEND_RATES(:,10) = strpad('d/dt Clb2 in component Clb2 (dimensionless)');
    LEGEND_RATES(:,8) = strpad('d/dt Sic1 in component Sic1 (dimensionless)');
    LEGEND_RATES(:,17) = strpad('d/dt Sic1P in component Sic1P (dimensionless)');
    LEGEND_RATES(:,12) = strpad('d/dt C2 in component C2 (dimensionless)');
    LEGEND_RATES(:,5) = strpad('d/dt C5 in component C5 (dimensionless)');
    LEGEND_RATES(:,11) = strpad('d/dt C2P in component C2P (dimensionless)');
    LEGEND_RATES(:,4) = strpad('d/dt C5P in component C5P (dimensionless)');
    LEGEND_RATES(:,9) = strpad('d/dt Cdc6 in component Cdc6 (dimensionless)');
    LEGEND_RATES(:,18) = strpad('d/dt Cdc6P in component Cdc6P (dimensionless)');
    LEGEND_RATES(:,14) = strpad('d/dt F2 in component F2 (dimensionless)');
    LEGEND_RATES(:,19) = strpad('d/dt Pds1 in component Pds1 (dimensionless)');
    LEGEND_RATES(:,20) = strpad('d/dt Esp1 in component Esp1 (dimensionless)');
    LEGEND_RATES(:,21) = strpad('d/dt ORI in component ORI (dimensionless)');
    LEGEND_RATES(:,22) = strpad('d/dt BUD in component BUD (dimensionless)');
    LEGEND_RATES(:,23) = strpad('d/dt SPN in component SPN (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt F5 in component F5 (dimensionless)');
    LEGEND_RATES(:,13) = strpad('d/dt F2P in component F2P (dimensionless)');
    LEGEND_RATES(:,6) = strpad('d/dt F5P in component F5P (dimensionless)');
    LEGEND_RATES(:,24) = strpad('d/dt Swi5_T in component Swi5_T (dimensionless)');
    LEGEND_RATES(:,15) = strpad('d/dt Swi5 in component Swi5 (dimensionless)');
    LEGEND_RATES(:,25) = strpad('d/dt APC_P in component APC_P (dimensionless)');
    LEGEND_RATES(:,26) = strpad('d/dt Cdc20_T in component Cdc20_T (dimensionless)');
    LEGEND_RATES(:,27) = strpad('d/dt Cdc20_A in component Cdc20_A (dimensionless)');
    LEGEND_RATES(:,28) = strpad('d/dt Cdh1_T in component Cdh1_T (dimensionless)');
    LEGEND_RATES(:,29) = strpad('d/dt Cdh1 in component Cdh1 (dimensionless)');
    LEGEND_RATES(:,30) = strpad('d/dt Tem1 in component Tem1 (dimensionless)');
    LEGEND_RATES(:,31) = strpad('d/dt Cdc15 in component Cdc15 (dimensionless)');
    LEGEND_RATES(:,32) = strpad('d/dt Cdc14_T in component Cdc14_T (dimensionless)');
    LEGEND_RATES(:,16) = strpad('d/dt Cdc14 in component Cdc14 (dimensionless)');
    LEGEND_RATES(:,35) = strpad('d/dt Net1_T in component Net1_T (dimensionless)');
    LEGEND_RATES(:,34) = strpad('d/dt Net1 in component Net1 (dimensionless)');
    LEGEND_RATES(:,33) = strpad('d/dt RENT in component RENT (dimensionless)');
    LEGEND_RATES(:,36) = strpad('d/dt PPX in component PPX (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 = [];
    STATES(:,1) = 1.206;
    CONSTANTS(:,1) = 0.007702;
    STATES(:,2) = 0.0652;
    CONSTANTS(:,2) = 0;
    CONSTANTS(:,3) = 0.15;
    CONSTANTS(:,4) = 0.12;
    STATES(:,3) = 0.0518;
    CONSTANTS(:,5) = 0.0008;
    CONSTANTS(:,6) = 0.005;
    CONSTANTS(:,7) = 0.01;
    CONSTANTS(:,8) = 0.06;
    CONSTANTS(:,9) = 50;
    CONSTANTS(:,10) = 0.01;
    CONSTANTS(:,11) = 1;
    CONSTANTS(:,12) = 1;
    STATES(:,4) = 0.0069;
    STATES(:,5) = 0.0701;
    STATES(:,6) = 7.9e-6;
    STATES(:,7) = 7.2e-5;
    STATES(:,8) = 0.0229;
    STATES(:,9) = 0.1076;
    STATES(:,10) = 0.1469;
    CONSTANTS(:,13) = 0.001;
    CONSTANTS(:,14) = 0.04;
    CONSTANTS(:,15) = 0.05;
    CONSTANTS(:,16) = 0.5;
    CONSTANTS(:,17) = 50;
    CONSTANTS(:,18) = 15;
    STATES(:,11) = 0.024;
    STATES(:,12) = 0.2384;
    STATES(:,13) = 0.0274;
    STATES(:,14) = 0.2361;
    CONSTANTS(:,19) = 0.012;
    CONSTANTS(:,20) = 0.12;
    CONSTANTS(:,21) = 4;
    STATES(:,15) = 0.9562;
    STATES(:,16) = 0.4683;
    STATES(:,17) = 0.0064;
    CONSTANTS(:,22) = 0.024;
    CONSTANTS(:,23) = 0.12;
    CONSTANTS(:,24) = 0.004;
    CONSTANTS(:,25) = 4;
    STATES(:,18) = 0.0155;
    STATES(:,19) = 0.0256;
    CONSTANTS(:,26) = 0;
    CONSTANTS(:,27) = 0.03;
    CONSTANTS(:,28) = 0.055;
    CONSTANTS(:,29) = 0.5;
    CONSTANTS(:,30) = 50;
    STATES(:,20) = 0.3013;
    STATES(:,21) = 0.0009;
    CONSTANTS(:,31) = 2;
    CONSTANTS(:,32) = 0.06;
    CONSTANTS(:,33) = 0.9;
    CONSTANTS(:,34) = 0.45;
    STATES(:,22) = 0.0085;
    CONSTANTS(:,35) = 0.2;
    CONSTANTS(:,36) = 0.06;
    CONSTANTS(:,37) = 0.25;
    CONSTANTS(:,38) = 0.05;
    CONSTANTS(:,39) = 1;
    STATES(:,23) = 0.0305;
    CONSTANTS(:,40) = 0.1;
    CONSTANTS(:,41) = 0.06;
    CONSTANTS(:,42) = 0.14;
    CONSTANTS(:,43) = 0.01;
    CONSTANTS(:,44) = 0.01;
    CONSTANTS(:,45) = 0.1;
    CONSTANTS(:,46) = 0.1;
    CONSTANTS(:,47) = 0.15;
    CONSTANTS(:,48) = 1;
    CONSTANTS(:,49) = 0.4;
    CONSTANTS(:,50) = 1;
    CONSTANTS(:,51) = 6;
    CONSTANTS(:,52) = 0.054;
    STATES(:,24) = 0.9765;
    CONSTANTS(:,53) = 0.005;
    CONSTANTS(:,54) = 0.08;
    CONSTANTS(:,55) = 0.08;
    CONSTANTS(:,56) = 2;
    CONSTANTS(:,57) = 0.05;
    STATES(:,25) = 0.1015;
    CONSTANTS(:,58) = 0.1;
    CONSTANTS(:,59) = 0.15;
    CONSTANTS(:,60) = 0.1;
    CONSTANTS(:,61) = 0.1;
    STATES(:,26) = 1.9163;
    CONSTANTS(:,62) = 0.006;
    CONSTANTS(:,63) = 0.6;
    CONSTANTS(:,64) = 0.3;
    STATES(:,27) = 0.4443;
    CONSTANTS(:,65) = 0.05;
    CONSTANTS(:,66) = 0.2;
    STATES(:,28) = 1;
    CONSTANTS(:,67) = 0.01;
    CONSTANTS(:,68) = 0.01;
    STATES(:,29) = 0.9305;
    CONSTANTS(:,69) = 0.03;
    CONSTANTS(:,70) = 0.03;
    STATES(:,30) = 0.9039;
    CONSTANTS(:,71) = 0.1;
    CONSTANTS(:,72) = 0.1;
    CONSTANTS(:,73) = 1;
    STATES(:,31) = 0.6565;
    CONSTANTS(:,74) = 0.002;
    CONSTANTS(:,75) = 1;
    CONSTANTS(:,76) = 0.001;
    CONSTANTS(:,77) = 0.5;
    CONSTANTS(:,78) = 1;
    STATES(:,32) = 2;
    CONSTANTS(:,79) = 0.2;
    CONSTANTS(:,80) = 0.1;
    CONSTANTS(:,81) = 0.03;
    CONSTANTS(:,82) = 1;
    CONSTANTS(:,83) = 2;
    CONSTANTS(:,84) = 200;
    CONSTANTS(:,85) = 1;
    STATES(:,33) = 1.0495;
    STATES(:,34) = 0.0186;
    STATES(:,35) = 2.8;
    CONSTANTS(:,86) = 0.084;
    CONSTANTS(:,87) = 1;
    CONSTANTS(:,88) = 0.01;
    CONSTANTS(:,89) = 0.16;
    CONSTANTS(:,90) = 0.003;
    CONSTANTS(:,91) = 0.4;
    CONSTANTS(:,92) = 0.15;
    CONSTANTS(:,93) = 0.38;
    CONSTANTS(:,94) = 2;
    CONSTANTS(:,95) = 10;
    CONSTANTS(:,96) = 2;
    CONSTANTS(:,97) = 0.6;
    CONSTANTS(:,98) = 8;
    CONSTANTS(:,99) = 0.01;
    CONSTANTS(:,100) = 1;
    CONSTANTS(:,101) = 0.05;
    CONSTANTS(:,102) = 0.06;
    CONSTANTS(:,103) = 0.3;
    CONSTANTS(:,104) = 0.03;
    CONSTANTS(:,105) = 0.1;
    CONSTANTS(:,106) = 0.45;
    CONSTANTS(:,107) = 0.05;
    CONSTANTS(:,108) = 0.01;
    CONSTANTS(:,109) = 1;
    CONSTANTS(:,110) = 0.06;
    CONSTANTS(:,111) = 0.3;
    CONSTANTS(:,112) = 0.03;
    CONSTANTS(:,113) = 0.1;
    CONSTANTS(:,114) = 0.55;
    CONSTANTS(:,115) = 0.01;
    CONSTANTS(:,116) = 0.8;
    CONSTANTS(:,117) = 0.001;
    CONSTANTS(:,118) = 0.08;
    CONSTANTS(:,119) = 0.4;
    CONSTANTS(:,120) = 0.25;
    CONSTANTS(:,121) = 8;
    CONSTANTS(:,122) = 1.2;
    CONSTANTS(:,123) = 0.05;
    CONSTANTS(:,124) = 3;
    STATES(:,36) = 0.1232;
    CONSTANTS(:,125) = 0.01;
    CONSTANTS(:,126) = 0.6;
    CONSTANTS(:,127) = 0.1;
    CONSTANTS(:,128) = 0.17;
    CONSTANTS(:,129) = 2;
    CONSTANTS(:,130) = 0.04;
    CONSTANTS(:,131) = 0.15;
    CONSTANTS(:,132) = 0.01;
    CONSTANTS(:,133) = 0.2;
    CONSTANTS(:,134) = 0.04;
    CONSTANTS(:,135) = 0.3;
    CONSTANTS(:,136) = 0.2;
    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(:,1) =  STATES(:,1).*CONSTANTS(:,1);
    RATES(:,21) =  CONSTANTS(:,31).*( CONSTANTS(:,33).*STATES(:,3)+ CONSTANTS(:,34).*STATES(:,10)) -  CONSTANTS(:,32).*STATES(:,21);
    RATES(:,23) = ( CONSTANTS(:,40).*STATES(:,10))./(CONSTANTS(:,42)+STATES(:,10)) -  CONSTANTS(:,41).*STATES(:,23);
    RATES(:,25) = ( CONSTANTS(:,58).*STATES(:,10).*(1.00000 - STATES(:,25)))./((CONSTANTS(:,60)+1.00000) - STATES(:,25)) - ( CONSTANTS(:,59).*STATES(:,25))./(CONSTANTS(:,61)+STATES(:,25));
    RATES(:,28) = CONSTANTS(:,67) -  CONSTANTS(:,68).*STATES(:,28);
    RATES(:,31) =  ( CONSTANTS(:,74).*(CONSTANTS(:,73) - STATES(:,30))+ CONSTANTS(:,75).*STATES(:,30)+ CONSTANTS(:,76).*STATES(:,16)).*(CONSTANTS(:,78) - STATES(:,31)) -  CONSTANTS(:,77).*STATES(:,31);
    RATES(:,32) = CONSTANTS(:,79) -  CONSTANTS(:,80).*STATES(:,32);
    RATES(:,35) = CONSTANTS(:,86) -  CONSTANTS(:,81).*STATES(:,35);
    ALGEBRAIC(:,4) = piecewise({STATES(:,21)>1.00000&STATES(:,23)<1.00000, 8.00000 }, 0.0100000);
    RATES(:,27) =  (CONSTANTS(:,65)+ CONSTANTS(:,66).*STATES(:,25)).*(STATES(:,26) - STATES(:,27)) -  (ALGEBRAIC(:,4)+CONSTANTS(:,64)).*STATES(:,27);
    ALGEBRAIC(:,7) = CONSTANTS(:,128)+( CONSTANTS(:,129).*(CONSTANTS(:,131)+STATES(:,27)).*CONSTANTS(:,130))./(CONSTANTS(:,130)+STATES(:,19));
    RATES(:,36) = CONSTANTS(:,127) -  ALGEBRAIC(:,7).*STATES(:,36);
    ALGEBRAIC(:,1) = ( 2.00000.*CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10))./((CONSTANTS(:,47)+ CONSTANTS(:,46).*CONSTANTS(:,47)+ CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10)+power((power((CONSTANTS(:,47)+ CONSTANTS(:,46).*CONSTANTS(:,47)+ CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10)) -  CONSTANTS(:,48).*STATES(:,10), 2.00000) -  4.00000.*(CONSTANTS(:,47) -  CONSTANTS(:,48).*STATES(:,10)).*CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10)), 1.0 ./ 2)) -  CONSTANTS(:,48).*STATES(:,10));
    ALGEBRAIC(:,8) = ALGEBRAIC(:,1);
    RATES(:,24) = (CONSTANTS(:,53)+ CONSTANTS(:,54).*ALGEBRAIC(:,8)) -  CONSTANTS(:,55).*STATES(:,24);
    RATES(:,15) = (CONSTANTS(:,53)+ CONSTANTS(:,54).*ALGEBRAIC(:,8)+ CONSTANTS(:,56).*STATES(:,16).*(STATES(:,24) - STATES(:,15))) -  (CONSTANTS(:,55)+ CONSTANTS(:,57).*STATES(:,10)).*STATES(:,15);
    RATES(:,26) = (CONSTANTS(:,62)+ CONSTANTS(:,63).*ALGEBRAIC(:,8)) -  CONSTANTS(:,64).*STATES(:,26);
    ALGEBRAIC(:,5) = piecewise({STATES(:,21)>1.00000&STATES(:,23)<1.00000, 1.00000 }, 0.200000);
    ALGEBRAIC(:,9) = piecewise({STATES(:,23)>1.00000&STATES(:,10)>CONSTANTS(:,135), 1.00000 }, 0.100000);
    RATES(:,30) = ( ALGEBRAIC(:,9).*(CONSTANTS(:,73) - STATES(:,30)))./((CONSTANTS(:,71)+CONSTANTS(:,73)) - STATES(:,30)) - ( ALGEBRAIC(:,5).*STATES(:,30))./(CONSTANTS(:,72)+STATES(:,30));
    ALGEBRAIC(:,6) = STATES(:,32) - (STATES(:,33)+STATES(:,16));
    ALGEBRAIC(:,10) = (STATES(:,35)+STATES(:,16)) - (STATES(:,34)+STATES(:,32));
    RATES(:,16) = (CONSTANTS(:,79)+ CONSTANTS(:,81).*(STATES(:,33)+ALGEBRAIC(:,6))+ CONSTANTS(:,82).*STATES(:,33)+ CONSTANTS(:,83).*ALGEBRAIC(:,6)) - ( CONSTANTS(:,80).*STATES(:,16)+ ( CONSTANTS(:,84).*STATES(:,34)+ CONSTANTS(:,85).*ALGEBRAIC(:,10)).*STATES(:,16));
    ALGEBRAIC(:,11) = ( CONSTANTS(:,49).*CONSTANTS(:,50).*STATES(:,1))./(CONSTANTS(:,51)+ CONSTANTS(:,50).*STATES(:,1));
    RATES(:,22) =  CONSTANTS(:,35).*( CONSTANTS(:,37).*STATES(:,2)+ CONSTANTS(:,38).*ALGEBRAIC(:,11)+ CONSTANTS(:,39).*STATES(:,3)) -  CONSTANTS(:,36).*STATES(:,22);
    ALGEBRAIC(:,12) = CONSTANTS(:,123)+ CONSTANTS(:,124).*STATES(:,36);
    ALGEBRAIC(:,15) =  (CONSTANTS(:,125)+ CONSTANTS(:,126).*STATES(:,31)).*STATES(:,1);
    RATES(:,34) = (CONSTANTS(:,86)+ CONSTANTS(:,80).*STATES(:,33)+ CONSTANTS(:,82).*STATES(:,33)+ ALGEBRAIC(:,12).*ALGEBRAIC(:,10)) - ( CONSTANTS(:,81).*STATES(:,34)+ CONSTANTS(:,84).*STATES(:,16).*STATES(:,34)+ ALGEBRAIC(:,15).*STATES(:,34));
    RATES(:,33) = ( CONSTANTS(:,84).*STATES(:,16).*STATES(:,34)+ ALGEBRAIC(:,12).*ALGEBRAIC(:,6)) - ( (CONSTANTS(:,80)+CONSTANTS(:,81)).*STATES(:,33)+ CONSTANTS(:,82).*STATES(:,33)+ ALGEBRAIC(:,15).*STATES(:,33));
    ALGEBRAIC(:,14) = CONSTANTS(:,115)+ CONSTANTS(:,116).*STATES(:,16);
    ALGEBRAIC(:,17) = CONSTANTS(:,117)+ CONSTANTS(:,118).*( CONSTANTS(:,120).*ALGEBRAIC(:,11)+ CONSTANTS(:,119).*STATES(:,2)+ CONSTANTS(:,121).*STATES(:,3)+ CONSTANTS(:,122).*STATES(:,10));
    RATES(:,29) = (CONSTANTS(:,67)+( ALGEBRAIC(:,14).*(STATES(:,28) - STATES(:,29)))./((CONSTANTS(:,69)+STATES(:,28)) - STATES(:,29))) - ( CONSTANTS(:,68).*STATES(:,29)+( ALGEBRAIC(:,17).*STATES(:,29))./(CONSTANTS(:,70)+STATES(:,29)));
    ALGEBRAIC(:,22) = CONSTANTS(:,90)+ CONSTANTS(:,91).*STATES(:,29)+ CONSTANTS(:,92).*STATES(:,27);
    RATES(:,10) = ( (CONSTANTS(:,13)+ CONSTANTS(:,14).*ALGEBRAIC(:,8)).*STATES(:,1)+ CONSTANTS(:,12).*STATES(:,11)+ CONSTANTS(:,15).*STATES(:,12)+ CONSTANTS(:,11).*STATES(:,13)+ CONSTANTS(:,16).*STATES(:,14)) -  (ALGEBRAIC(:,22)+ CONSTANTS(:,17).*STATES(:,8)+ CONSTANTS(:,18).*STATES(:,9)).*STATES(:,10);
    ALGEBRAIC(:,21) = CONSTANTS(:,88)+ CONSTANTS(:,89).*STATES(:,27);
    ALGEBRAIC(:,13) =  CONSTANTS(:,52).*STATES(:,1);
    ALGEBRAIC(:,16) = STATES(:,8)+STATES(:,17)+STATES(:,12)+STATES(:,11)+STATES(:,5)+STATES(:,4);
    ALGEBRAIC(:,24) = CONSTANTS(:,99)+( CONSTANTS(:,100).*( CONSTANTS(:,103).*ALGEBRAIC(:,11)+ CONSTANTS(:,104).*ALGEBRAIC(:,13)+ CONSTANTS(:,102).*STATES(:,2)+ CONSTANTS(:,105).*STATES(:,3)+ CONSTANTS(:,106).*STATES(:,10)))./(CONSTANTS(:,101)+ALGEBRAIC(:,16));
    RATES(:,8) = (CONSTANTS(:,19)+ CONSTANTS(:,20).*STATES(:,15)+ (ALGEBRAIC(:,22)+CONSTANTS(:,15)).*STATES(:,12)+ (ALGEBRAIC(:,21)+CONSTANTS(:,8)).*STATES(:,5)+ CONSTANTS(:,21).*STATES(:,16).*STATES(:,17)) -  ( CONSTANTS(:,17).*STATES(:,10)+ CONSTANTS(:,9).*STATES(:,3)+ALGEBRAIC(:,24)).*STATES(:,8);
    RATES(:,17) = ( ALGEBRAIC(:,24).*STATES(:,8) -  ( CONSTANTS(:,21).*STATES(:,16)+CONSTANTS(:,12)).*STATES(:,17))+ ALGEBRAIC(:,22).*STATES(:,11)+ ALGEBRAIC(:,21).*STATES(:,4);
    RATES(:,12) = ( CONSTANTS(:,17).*STATES(:,10).*STATES(:,8)+ CONSTANTS(:,21).*STATES(:,16).*STATES(:,11)) -  (CONSTANTS(:,15)+ALGEBRAIC(:,22)+ALGEBRAIC(:,24)).*STATES(:,12);
    RATES(:,5) = ( CONSTANTS(:,9).*STATES(:,3).*STATES(:,8)+ CONSTANTS(:,21).*STATES(:,16).*STATES(:,4)) -  (CONSTANTS(:,8)+ALGEBRAIC(:,21)+ALGEBRAIC(:,24)).*STATES(:,5);
    RATES(:,11) =  ALGEBRAIC(:,24).*STATES(:,12) -  ( CONSTANTS(:,21).*STATES(:,16)+CONSTANTS(:,12)+ALGEBRAIC(:,22)).*STATES(:,11);
    RATES(:,4) =  ALGEBRAIC(:,24).*STATES(:,5) -  ( CONSTANTS(:,21).*STATES(:,16)+CONSTANTS(:,12)+ALGEBRAIC(:,21)).*STATES(:,4);
    ALGEBRAIC(:,25) = CONSTANTS(:,97)+ CONSTANTS(:,98).*STATES(:,10);
    ALGEBRAIC(:,23) =  CONSTANTS(:,93).*( CONSTANTS(:,94).*STATES(:,2)+ CONSTANTS(:,95).*(ALGEBRAIC(:,11)+ALGEBRAIC(:,13))+ CONSTANTS(:,96).*STATES(:,3));
    ALGEBRAIC(:,26) = ( 2.00000.*CONSTANTS(:,43).*ALGEBRAIC(:,23))./((ALGEBRAIC(:,25)+ CONSTANTS(:,44).*ALGEBRAIC(:,25)+ CONSTANTS(:,43).*ALGEBRAIC(:,23)+power((power((ALGEBRAIC(:,25)+ CONSTANTS(:,44).*ALGEBRAIC(:,25)+ CONSTANTS(:,43).*ALGEBRAIC(:,23)) - ALGEBRAIC(:,23), 2.00000) -  4.00000.*(ALGEBRAIC(:,25) - ALGEBRAIC(:,23)).*CONSTANTS(:,43).*ALGEBRAIC(:,23)), 1.0 ./ 2)) - ALGEBRAIC(:,23));
    ALGEBRAIC(:,27) = ALGEBRAIC(:,26);
    RATES(:,3) = ( (CONSTANTS(:,5)+ CONSTANTS(:,6).*ALGEBRAIC(:,27)).*STATES(:,1)+ CONSTANTS(:,12).*STATES(:,4)+ CONSTANTS(:,8).*STATES(:,5)+ CONSTANTS(:,11).*STATES(:,6)+ CONSTANTS(:,7).*STATES(:,7)) -  (ALGEBRAIC(:,21)+ CONSTANTS(:,9).*STATES(:,8)+ CONSTANTS(:,10).*STATES(:,9)).*STATES(:,3);
    ALGEBRAIC(:,28) = ALGEBRAIC(:,27);
    RATES(:,2) =  (CONSTANTS(:,2)+ CONSTANTS(:,3).*ALGEBRAIC(:,28)).*STATES(:,1) -  CONSTANTS(:,4).*STATES(:,2);
    ALGEBRAIC(:,18) = STATES(:,9)+STATES(:,18)+STATES(:,14)+STATES(:,13)+STATES(:,7)+STATES(:,6);
    ALGEBRAIC(:,29) = CONSTANTS(:,108)+( CONSTANTS(:,109).*( CONSTANTS(:,111).*ALGEBRAIC(:,11)+ CONSTANTS(:,112).*ALGEBRAIC(:,13)+ CONSTANTS(:,110).*STATES(:,2)+ CONSTANTS(:,113).*STATES(:,3)+ CONSTANTS(:,114).*STATES(:,10)))./(CONSTANTS(:,107)+ALGEBRAIC(:,18));
    RATES(:,9) = (CONSTANTS(:,22)+ CONSTANTS(:,23).*STATES(:,15)+ CONSTANTS(:,24).*ALGEBRAIC(:,28)+ (ALGEBRAIC(:,22)+CONSTANTS(:,16)).*STATES(:,14)+ (ALGEBRAIC(:,21)+CONSTANTS(:,7)).*STATES(:,7)+ CONSTANTS(:,25).*STATES(:,16).*STATES(:,18)) -  ( CONSTANTS(:,18).*STATES(:,10)+ CONSTANTS(:,10).*STATES(:,3)+ALGEBRAIC(:,29)).*STATES(:,9);
    RATES(:,18) = ( ALGEBRAIC(:,29).*STATES(:,9) -  ( CONSTANTS(:,25).*STATES(:,16)+CONSTANTS(:,11)).*STATES(:,18))+ ALGEBRAIC(:,22).*STATES(:,13)+ ALGEBRAIC(:,21).*STATES(:,6);
    RATES(:,14) = ( CONSTANTS(:,18).*STATES(:,10).*STATES(:,9)+ CONSTANTS(:,25).*STATES(:,16).*STATES(:,13)) -  (CONSTANTS(:,16)+ALGEBRAIC(:,22)+ALGEBRAIC(:,29)).*STATES(:,14);
    ALGEBRAIC(:,30) = CONSTANTS(:,132)+ CONSTANTS(:,133).*STATES(:,27)+ CONSTANTS(:,134).*STATES(:,29);
    ALGEBRAIC(:,19) = CONSTANTS(:,87) - STATES(:,20);
    RATES(:,19) = (CONSTANTS(:,26)+ CONSTANTS(:,27).*ALGEBRAIC(:,28)+ CONSTANTS(:,28).*ALGEBRAIC(:,8)+ CONSTANTS(:,29).*ALGEBRAIC(:,19)) -  (ALGEBRAIC(:,30)+ CONSTANTS(:,30).*STATES(:,20)).*STATES(:,19);
    RATES(:,20) =   - CONSTANTS(:,30).*STATES(:,19).*STATES(:,20)+ (CONSTANTS(:,29)+ALGEBRAIC(:,30)).*ALGEBRAIC(:,19);
    RATES(:,7) = ( CONSTANTS(:,10).*STATES(:,3).*STATES(:,9)+ CONSTANTS(:,25).*STATES(:,16).*STATES(:,6)) -  (CONSTANTS(:,7)+ALGEBRAIC(:,21)+ALGEBRAIC(:,29)).*STATES(:,7);
    RATES(:,13) =  ALGEBRAIC(:,29).*STATES(:,14) -  ( CONSTANTS(:,25).*STATES(:,16)+CONSTANTS(:,11)+ALGEBRAIC(:,22)).*STATES(:,13);
    RATES(:,6) =  ALGEBRAIC(:,29).*STATES(:,7) -  ( CONSTANTS(:,25).*STATES(:,16)+CONSTANTS(:,11)+ALGEBRAIC(:,21)).*STATES(:,6);
   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(:,4) = piecewise({STATES(:,21)>1.00000&STATES(:,23)<1.00000, 8.00000 }, 0.0100000);
    ALGEBRAIC(:,7) = CONSTANTS(:,128)+( CONSTANTS(:,129).*(CONSTANTS(:,131)+STATES(:,27)).*CONSTANTS(:,130))./(CONSTANTS(:,130)+STATES(:,19));
    ALGEBRAIC(:,1) = ( 2.00000.*CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10))./((CONSTANTS(:,47)+ CONSTANTS(:,46).*CONSTANTS(:,47)+ CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10)+power((power((CONSTANTS(:,47)+ CONSTANTS(:,46).*CONSTANTS(:,47)+ CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10)) -  CONSTANTS(:,48).*STATES(:,10), 2.00000) -  4.00000.*(CONSTANTS(:,47) -  CONSTANTS(:,48).*STATES(:,10)).*CONSTANTS(:,45).*CONSTANTS(:,48).*STATES(:,10)), 1.0 ./ 2)) -  CONSTANTS(:,48).*STATES(:,10));
    ALGEBRAIC(:,8) = ALGEBRAIC(:,1);
    ALGEBRAIC(:,5) = piecewise({STATES(:,21)>1.00000&STATES(:,23)<1.00000, 1.00000 }, 0.200000);
    ALGEBRAIC(:,9) = piecewise({STATES(:,23)>1.00000&STATES(:,10)>CONSTANTS(:,135), 1.00000 }, 0.100000);
    ALGEBRAIC(:,6) = STATES(:,32) - (STATES(:,33)+STATES(:,16));
    ALGEBRAIC(:,10) = (STATES(:,35)+STATES(:,16)) - (STATES(:,34)+STATES(:,32));
    ALGEBRAIC(:,11) = ( CONSTANTS(:,49).*CONSTANTS(:,50).*STATES(:,1))./(CONSTANTS(:,51)+ CONSTANTS(:,50).*STATES(:,1));
    ALGEBRAIC(:,12) = CONSTANTS(:,123)+ CONSTANTS(:,124).*STATES(:,36);
    ALGEBRAIC(:,15) =  (CONSTANTS(:,125)+ CONSTANTS(:,126).*STATES(:,31)).*STATES(:,1);
    ALGEBRAIC(:,14) = CONSTANTS(:,115)+ CONSTANTS(:,116).*STATES(:,16);
    ALGEBRAIC(:,17) = CONSTANTS(:,117)+ CONSTANTS(:,118).*( CONSTANTS(:,120).*ALGEBRAIC(:,11)+ CONSTANTS(:,119).*STATES(:,2)+ CONSTANTS(:,121).*STATES(:,3)+ CONSTANTS(:,122).*STATES(:,10));
    ALGEBRAIC(:,22) = CONSTANTS(:,90)+ CONSTANTS(:,91).*STATES(:,29)+ CONSTANTS(:,92).*STATES(:,27);
    ALGEBRAIC(:,21) = CONSTANTS(:,88)+ CONSTANTS(:,89).*STATES(:,27);
    ALGEBRAIC(:,13) =  CONSTANTS(:,52).*STATES(:,1);
    ALGEBRAIC(:,16) = STATES(:,8)+STATES(:,17)+STATES(:,12)+STATES(:,11)+STATES(:,5)+STATES(:,4);
    ALGEBRAIC(:,24) = CONSTANTS(:,99)+( CONSTANTS(:,100).*( CONSTANTS(:,103).*ALGEBRAIC(:,11)+ CONSTANTS(:,104).*ALGEBRAIC(:,13)+ CONSTANTS(:,102).*STATES(:,2)+ CONSTANTS(:,105).*STATES(:,3)+ CONSTANTS(:,106).*STATES(:,10)))./(CONSTANTS(:,101)+ALGEBRAIC(:,16));
    ALGEBRAIC(:,25) = CONSTANTS(:,97)+ CONSTANTS(:,98).*STATES(:,10);
    ALGEBRAIC(:,23) =  CONSTANTS(:,93).*( CONSTANTS(:,94).*STATES(:,2)+ CONSTANTS(:,95).*(ALGEBRAIC(:,11)+ALGEBRAIC(:,13))+ CONSTANTS(:,96).*STATES(:,3));
    ALGEBRAIC(:,26) = ( 2.00000.*CONSTANTS(:,43).*ALGEBRAIC(:,23))./((ALGEBRAIC(:,25)+ CONSTANTS(:,44).*ALGEBRAIC(:,25)+ CONSTANTS(:,43).*ALGEBRAIC(:,23)+power((power((ALGEBRAIC(:,25)+ CONSTANTS(:,44).*ALGEBRAIC(:,25)+ CONSTANTS(:,43).*ALGEBRAIC(:,23)) - ALGEBRAIC(:,23), 2.00000) -  4.00000.*(ALGEBRAIC(:,25) - ALGEBRAIC(:,23)).*CONSTANTS(:,43).*ALGEBRAIC(:,23)), 1.0 ./ 2)) - ALGEBRAIC(:,23));
    ALGEBRAIC(:,27) = ALGEBRAIC(:,26);
    ALGEBRAIC(:,28) = ALGEBRAIC(:,27);
    ALGEBRAIC(:,18) = STATES(:,9)+STATES(:,18)+STATES(:,14)+STATES(:,13)+STATES(:,7)+STATES(:,6);
    ALGEBRAIC(:,29) = CONSTANTS(:,108)+( CONSTANTS(:,109).*( CONSTANTS(:,111).*ALGEBRAIC(:,11)+ CONSTANTS(:,112).*ALGEBRAIC(:,13)+ CONSTANTS(:,110).*STATES(:,2)+ CONSTANTS(:,113).*STATES(:,3)+ CONSTANTS(:,114).*STATES(:,10)))./(CONSTANTS(:,107)+ALGEBRAIC(:,18));
    ALGEBRAIC(:,30) = CONSTANTS(:,132)+ CONSTANTS(:,133).*STATES(:,27)+ CONSTANTS(:,134).*STATES(:,29);
    ALGEBRAIC(:,19) = CONSTANTS(:,87) - STATES(:,20);
    ALGEBRAIC(:,2) = STATES(:,3)+STATES(:,5)+STATES(:,4)+STATES(:,7)+STATES(:,6);
    ALGEBRAIC(:,3) = STATES(:,10)+STATES(:,12)+STATES(:,11)+STATES(:,14)+STATES(:,13);
    ALGEBRAIC(:,20) = ALGEBRAIC(:,16)+ALGEBRAIC(:,18);
end

% Compute result of a piecewise function
function x = piecewise(cases, default)
    set = [0];
    for i = 1:2:length(cases)
        if (length(cases{i+1}) == 1)
            x(cases{i} & ~set,:) = cases{i+1};
        else
            x(cases{i} & ~set,:) = cases{i+1}(cases{i} & ~set);
        end
        set = set | cases{i};
        if(set), break, end
    end
    if (length(default) == 1)
        x(~set,:) = default;
    else
        x(~set,:) = default(~set);
    end
end

% Pad out or shorten strings to a set length
function strout = strpad(strin)
    req_length = 160;
    insize = size(strin,2);
    if insize > req_length
        strout = strin(1:req_length);
    else
        strout = [strin, blanks(req_length - insize)];
    end
end