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 =21;
end
% There are a total of 8 entries in each of the rate and state variable arrays.
% There are a total of 55 entries in the constant variable array.
%

function [VOI, STATES, ALGEBRAIC, CONSTANTS] = solveModel()
    % Create ALGEBRAIC of correct size
    global algebraicVariableCount;  algebraicVariableCount = getAlgebraicVariableCount();
    % Initialise constants and state variables
    [INIT_STATES, CONSTANTS] = initConsts;

    % Set timespan to solve over 
    tspan = [0, 10];

    % Set numerical accuracy options for ODE solver
    options = odeset('RelTol', 1e-06, 'AbsTol', 1e-06, 'MaxStep', 1);

    % Solve model with ODE solver
    [VOI, STATES] = ode15s(@(VOI, STATES)computeRates(VOI, STATES, CONSTANTS), tspan, INIT_STATES, options);

    % Compute algebraic variables
    [RATES, ALGEBRAIC] = computeRates(VOI, STATES, CONSTANTS);
    ALGEBRAIC = computeAlgebraic(ALGEBRAIC, CONSTANTS, STATES, VOI);

    % Plot state variables against variable of integration
    [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends();
    figure();
    plot(VOI, STATES);
    xlabel(LEGEND_VOI);
    l = legend(LEGEND_STATES);
    set(l,'Interpreter','none');
end

function [LEGEND_STATES, LEGEND_ALGEBRAIC, LEGEND_VOI, LEGEND_CONSTANTS] = createLegends()
    LEGEND_STATES = ''; LEGEND_ALGEBRAIC = ''; LEGEND_VOI = ''; LEGEND_CONSTANTS = '';
    LEGEND_VOI = strpad('time in component environment (second)');
    LEGEND_STATES(:,1) = strpad('Vm in component membrane (millivolt)');
    LEGEND_ALGEBRAIC(:,9) = strpad('I_iCa in component membrane (picoampere)');
    LEGEND_ALGEBRAIC(:,12) = strpad('I_iNa in component membrane (picoampere)');
    LEGEND_CONSTANTS(:,1) = strpad('Cm in component membrane (picofarad)');
    LEGEND_ALGEBRAIC(:,3) = strpad('I_Ca in component I_Ca (picoampere)');
    LEGEND_ALGEBRAIC(:,10) = strpad('I_Na in component I_Na (picoampere)');
    LEGEND_ALGEBRAIC(:,5) = strpad('I_NSCC_Ca in component I_NSCC_Ca (picoampere)');
    LEGEND_ALGEBRAIC(:,8) = strpad('I_PM in component I_PM (picoampere)');
    LEGEND_ALGEBRAIC(:,7) = strpad('I_NSCC_Na in component I_NSCC_Na (picoampere)');
    LEGEND_CONSTANTS(:,2) = strpad('gCa in component I_Ca (picosiemens)');
    LEGEND_ALGEBRAIC(:,1) = strpad('ECa in component I_Ca (millivolt)');
    LEGEND_CONSTANTS(:,3) = strpad('T in component model_parameters (kelvin)');
    LEGEND_CONSTANTS(:,4) = strpad('R in component model_parameters (attojoule_per_zeptomole_kelvin)');
    LEGEND_CONSTANTS(:,5) = strpad('F in component model_parameters (femtocoulomb_per_zeptomole)');
    LEGEND_CONSTANTS(:,6) = strpad('CO in component model_parameters (micromolar)');
    LEGEND_STATES(:,2) = strpad('CS1 in component CS1 (micromolar)');
    LEGEND_CONSTANTS(:,7) = strpad('gNSCC_Ca_ in component I_NSCC_Ca (picosiemens)');
    LEGEND_ALGEBRAIC(:,4) = strpad('gNSCC_Ca in component I_NSCC_Ca (picosiemens)');
    LEGEND_CONSTANTS(:,8) = strpad('hNSCC in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,9) = strpad('ENSCC in component model_parameters (millivolt)');
    LEGEND_CONSTANTS(:,10) = strpad('KNSCC in component model_parameters (micromolar)');
    LEGEND_CONSTANTS(:,11) = strpad('gNSCC_Na_ in component I_NSCC_Na (picosiemens)');
    LEGEND_ALGEBRAIC(:,6) = strpad('gNSCC_Na in component I_NSCC_Na (picosiemens)');
    LEGEND_CONSTANTS(:,12) = strpad('gPM in component I_PM (femtoampere)');
    LEGEND_CONSTANTS(:,13) = strpad('KPM in component I_PM (micromolar)');
    LEGEND_CONSTANTS(:,14) = strpad('gNa in component I_Na (femtoampere)');
    LEGEND_CONSTANTS(:,15) = strpad('KNa in component I_Na (micromolar)');
    LEGEND_CONSTANTS(:,16) = strpad('hNa in component I_Na (dimensionless)');
    LEGEND_STATES(:,3) = strpad('NS1 in component NS1 (micromolar)');
    LEGEND_ALGEBRAIC(:,11) = strpad('JSERCA in component JSERCA (flux)');
    LEGEND_CONSTANTS(:,17) = strpad('VSERCA in component JSERCA (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,18) = strpad('A2 in component JSERCA (dimensionless)');
    LEGEND_CONSTANTS(:,19) = strpad('A4 in component JSERCA (per_micromolar)');
    LEGEND_CONSTANTS(:,20) = strpad('A5 in component JSERCA (per_micromolar)');
    LEGEND_CONSTANTS(:,21) = strpad('A6 in component JSERCA (per_micromolar2)');
    LEGEND_STATES(:,4) = strpad('CER in component CER (micromolar)');
    LEGEND_ALGEBRAIC(:,14) = strpad('JMCU in component JMCU (flux)');
    LEGEND_CONSTANTS(:,22) = strpad('VMCU in component JMCU (flux)');
    LEGEND_CONSTANTS(:,23) = strpad('KMCU in component JMCU (micromolar)');
    LEGEND_ALGEBRAIC(:,13) = strpad('epsilon_INH in component JMCU (dimensionless)');
    LEGEND_CONSTANTS(:,24) = strpad('KINH in component JMCU (micromolar)');
    LEGEND_CONSTANTS(:,25) = strpad('hINH in component JMCU (dimensionless)');
    LEGEND_STATES(:,5) = strpad('CS2 in component CS2 (micromolar)');
    LEGEND_STATES(:,6) = strpad('CMT in component CMT (micromolar)');
    LEGEND_ALGEBRAIC(:,15) = strpad('JNCX in component JNCX (flux)');
    LEGEND_CONSTANTS(:,26) = strpad('VNCX in component JNCX (flux)');
    LEGEND_CONSTANTS(:,27) = strpad('KNCX in component JNCX (micromolar)');
    LEGEND_ALGEBRAIC(:,16) = strpad('JS1S2 in component JS1S2 (flux)');
    LEGEND_CONSTANTS(:,28) = strpad('mu_S1S2 in component JS1S2 (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,20) = strpad('JIPR in component JIPR (flux)');
    LEGEND_CONSTANTS(:,29) = strpad('kIPR in component JIPR (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,30) = strpad('k_1 in component JIPR (flux)');
    LEGEND_CONSTANTS(:,31) = strpad('k1 in component JIPR (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,32) = strpad('k2 in component JIPR (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,33) = strpad('r2 in component JIPR (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,34) = strpad('r_2 in component JIPR (flux)');
    LEGEND_CONSTANTS(:,35) = strpad('r4 in component JIPR (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,36) = strpad('R1 in component JIPR (micromolar)');
    LEGEND_CONSTANTS(:,37) = strpad('R3 in component JIPR (micromolar)');
    LEGEND_ALGEBRAIC(:,18) = strpad('phi1 in component JIPR (first_order_rate_constant)');
    LEGEND_ALGEBRAIC(:,19) = strpad('phi_1 in component JIPR (flux)');
    LEGEND_ALGEBRAIC(:,21) = strpad('phi2 in component JIPR (first_order_rate_constant)');
    LEGEND_STATES(:,7) = strpad('phi3 in component JIPR (first_order_rate_constant)');
    LEGEND_STATES(:,8) = strpad('H in component JIPR (dimensionless)');
    LEGEND_CONSTANTS(:,38) = strpad('g_beta in component JIPR (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,39) = strpad('h_beta in component JIPR (dimensionless)');
    LEGEND_CONSTANTS(:,40) = strpad('g_alpha in component JIPR (per_second_squared)');
    LEGEND_CONSTANTS(:,41) = strpad('K_beta in component JIPR (micromolar)');
    LEGEND_CONSTANTS(:,51) = strpad('alpha_phi3 in component JIPR (per_second_squared)');
    LEGEND_ALGEBRAIC(:,2) = strpad('beta_phi3 in component JIPR (first_order_rate_constant)');
    LEGEND_CONSTANTS(:,42) = strpad('P in component model_parameters (micromolar)');
    LEGEND_CONSTANTS(:,50) = strpad('lambda_MT_S1 in component CS1 (dimensionless)');
    LEGEND_CONSTANTS(:,52) = strpad('lambda_ER_S1 in component CS1 (dimensionless)');
    LEGEND_CONSTANTS(:,43) = strpad('delta_s in component model_parameters (micromolar_coulomb)');
    LEGEND_CONSTANTS(:,44) = strpad('gamma_S1 in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,45) = strpad('gamma_MT in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,46) = strpad('gamma_ER in component model_parameters (dimensionless)');
    LEGEND_CONSTANTS(:,53) = strpad('lambda_MT_S2 in component CS2 (dimensionless)');
    LEGEND_CONSTANTS(:,54) = strpad('lambda_ER_S2 in component CS2 (dimensionless)');
    LEGEND_CONSTANTS(:,55) = strpad('lambda_S1_S2 in component CS2 (dimensionless)');
    LEGEND_CONSTANTS(:,47) = strpad('gamma_S2 in component model_parameters (dimensionless)');
    LEGEND_ALGEBRAIC(:,17) = strpad('fm in component CMT (dimensionless)');
    LEGEND_CONSTANTS(:,48) = strpad('Km in component CMT (micromolar)');
    LEGEND_CONSTANTS(:,49) = strpad('Bm in component CMT (micromolar)');
    LEGEND_RATES(:,1) = strpad('d/dt Vm in component membrane (millivolt)');
    LEGEND_RATES(:,8) = strpad('d/dt H in component JIPR (dimensionless)');
    LEGEND_RATES(:,7) = strpad('d/dt phi3 in component JIPR (first_order_rate_constant)');
    LEGEND_RATES(:,2) = strpad('d/dt CS1 in component CS1 (micromolar)');
    LEGEND_RATES(:,5) = strpad('d/dt CS2 in component CS2 (micromolar)');
    LEGEND_RATES(:,4) = strpad('d/dt CER in component CER (micromolar)');
    LEGEND_RATES(:,6) = strpad('d/dt CMT in component CMT (micromolar)');
    LEGEND_RATES(:,3) = strpad('d/dt NS1 in component NS1 (micromolar)');
    LEGEND_STATES  = LEGEND_STATES';
    LEGEND_ALGEBRAIC = LEGEND_ALGEBRAIC';
    LEGEND_RATES = LEGEND_RATES';
    LEGEND_CONSTANTS = LEGEND_CONSTANTS';
end

function [STATES, CONSTANTS] = initConsts()
    VOI = 0; CONSTANTS = []; STATES = []; ALGEBRAIC = [];
    STATES(:,1) = -70.1;
    CONSTANTS(:,1) = 20.0;
    CONSTANTS(:,2) = 0.01;
    CONSTANTS(:,3) = 310.16;
    CONSTANTS(:,4) = 8.314E-3;
    CONSTANTS(:,5) = 0.09649;
    CONSTANTS(:,6) = 1.8E3;
    STATES(:,2) = 0.120;
    CONSTANTS(:,7) = 0.12;
    CONSTANTS(:,8) = 3.0;
    CONSTANTS(:,9) = 0.0;
    CONSTANTS(:,10) = 0.12;
    CONSTANTS(:,11) = 220.0;
    CONSTANTS(:,12) = 420.0;
    CONSTANTS(:,13) = 1.0;
    CONSTANTS(:,14) = 1.5E4;
    CONSTANTS(:,15) = 1.0E4;
    CONSTANTS(:,16) = 4.0;
    STATES(:,3) = 1.01E4;
    CONSTANTS(:,17) = 1.0E5;
    CONSTANTS(:,18) = 6E-4;
    CONSTANTS(:,19) = 3.57;
    CONSTANTS(:,20) = 2.7E-5;
    CONSTANTS(:,21) = 2.31E-5;
    STATES(:,4) = 203.0;
    CONSTANTS(:,22) = 800.0;
    CONSTANTS(:,23) = 10.0;
    CONSTANTS(:,24) = 10.0;
    CONSTANTS(:,25) = 4.0;
    STATES(:,5) = 0.023;
    STATES(:,6) = 0.220;
    CONSTANTS(:,26) = 0.5;
    CONSTANTS(:,27) = 0.3;
    CONSTANTS(:,28) = 0.04;
    CONSTANTS(:,29) = 2000.0;
    CONSTANTS(:,30) = 6.4;
    CONSTANTS(:,31) = 0.0;
    CONSTANTS(:,32) = 4.0;
    CONSTANTS(:,33) = 200.0;
    CONSTANTS(:,34) = 0.0;
    CONSTANTS(:,35) = 750.0;
    CONSTANTS(:,36) = 36.0;
    CONSTANTS(:,37) = 300.0;
    STATES(:,7) = 0.306;
    STATES(:,8) = 0.787;
    CONSTANTS(:,38) = 300.0;
    CONSTANTS(:,39) = 2.0;
    CONSTANTS(:,40) = 0.02;
    CONSTANTS(:,41) = 2.0;
    CONSTANTS(:,42) = 1.0;
    CONSTANTS(:,43) = 26.0;
    CONSTANTS(:,44) = 100.0;
    CONSTANTS(:,45) = 200.0;
    CONSTANTS(:,46) = 20.0;
    CONSTANTS(:,47) = 1.0;
    CONSTANTS(:,48) = 0.01;
    CONSTANTS(:,49) = 100.0;
    CONSTANTS(:,50) = CONSTANTS(:,45)./CONSTANTS(:,44);
    CONSTANTS(:,51) = CONSTANTS(:,40);
    CONSTANTS(:,52) = CONSTANTS(:,46)./CONSTANTS(:,44);
    CONSTANTS(:,53) = CONSTANTS(:,45)./CONSTANTS(:,47);
    CONSTANTS(:,54) = CONSTANTS(:,46)./CONSTANTS(:,47);
    CONSTANTS(:,55) = CONSTANTS(:,44)./CONSTANTS(:,47);
    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(:,2) =  CONSTANTS(:,38).*(power(STATES(:,5), CONSTANTS(:,39))./(power(CONSTANTS(:,41), CONSTANTS(:,39))+power(STATES(:,5), CONSTANTS(:,39))));
    RATES(:,7) = CONSTANTS(:,51) -  ALGEBRAIC(:,2).*STATES(:,7);
    ALGEBRAIC(:,1) =  (( CONSTANTS(:,4).*CONSTANTS(:,3))./( 2.00000.*CONSTANTS(:,5))).*log(CONSTANTS(:,6)./STATES(:,2));
    ALGEBRAIC(:,3) =  CONSTANTS(:,2).*(STATES(:,1) - ALGEBRAIC(:,1));
    ALGEBRAIC(:,4) =  CONSTANTS(:,7).*(power(CONSTANTS(:,10), CONSTANTS(:,8))./(power(CONSTANTS(:,10), CONSTANTS(:,8))+power(STATES(:,2), CONSTANTS(:,8))));
    ALGEBRAIC(:,5) =  ALGEBRAIC(:,4).*(STATES(:,1) - CONSTANTS(:,9));
    ALGEBRAIC(:,8) =  CONSTANTS(:,12).*(power(STATES(:,2), 2.00000)./(power(CONSTANTS(:,13), 2.00000)+power(STATES(:,2), 2.00000)));
    ALGEBRAIC(:,9) = ALGEBRAIC(:,3)+ALGEBRAIC(:,5)+ALGEBRAIC(:,8);
    ALGEBRAIC(:,10) =  CONSTANTS(:,14).*(power(STATES(:,3), CONSTANTS(:,16))./(power(CONSTANTS(:,15), CONSTANTS(:,16))+power(STATES(:,3), CONSTANTS(:,16))));
    ALGEBRAIC(:,6) =  CONSTANTS(:,11).*(power(CONSTANTS(:,10), CONSTANTS(:,8))./(power(CONSTANTS(:,10), CONSTANTS(:,8))+power(STATES(:,2), CONSTANTS(:,8))));
    ALGEBRAIC(:,7) =  ALGEBRAIC(:,6).*(STATES(:,1) - CONSTANTS(:,9));
    ALGEBRAIC(:,12) = ALGEBRAIC(:,7)+ALGEBRAIC(:,10);
    RATES(:,1) =  - ((ALGEBRAIC(:,9)+ALGEBRAIC(:,12))./CONSTANTS(:,1));
    RATES(:,3) =   - (CONSTANTS(:,43)./1.00000).*ALGEBRAIC(:,12);
    ALGEBRAIC(:,11) = ( CONSTANTS(:,17).*(STATES(:,2) -  CONSTANTS(:,18).*STATES(:,4)))./(1.00000+ CONSTANTS(:,19).*STATES(:,2)+ CONSTANTS(:,20).*STATES(:,4)+ CONSTANTS(:,21).*STATES(:,2).*STATES(:,4));
    ALGEBRAIC(:,15) =  CONSTANTS(:,26).*(STATES(:,6)./(STATES(:,6)+CONSTANTS(:,27)));
    ALGEBRAIC(:,16) =  CONSTANTS(:,28).*(STATES(:,5) - STATES(:,2));
    RATES(:,2) = (ALGEBRAIC(:,16)+ CONSTANTS(:,50).*ALGEBRAIC(:,15)) - ( (CONSTANTS(:,43)./2.00000).*ALGEBRAIC(:,9)+ CONSTANTS(:,52).*ALGEBRAIC(:,11));
    ALGEBRAIC(:,13) = power(CONSTANTS(:,24), CONSTANTS(:,25))./(power(CONSTANTS(:,24), CONSTANTS(:,25))+power(STATES(:,6), CONSTANTS(:,25)));
    ALGEBRAIC(:,14) =  CONSTANTS(:,22).*(power(STATES(:,5), 2.00000)./(power(CONSTANTS(:,23), 2.00000)+power(STATES(:,5), 2.00000))).*ALGEBRAIC(:,13);
    ALGEBRAIC(:,17) = 1.00000./(1.00000+( CONSTANTS(:,48).*CONSTANTS(:,49))./power(CONSTANTS(:,48)+STATES(:,6), 2.00000));
    RATES(:,6) =  ALGEBRAIC(:,17).*(ALGEBRAIC(:,14) - ALGEBRAIC(:,15));
    ALGEBRAIC(:,18) = ( CONSTANTS(:,31).*CONSTANTS(:,36)+ CONSTANTS(:,33).*STATES(:,5))./(CONSTANTS(:,36)+STATES(:,5));
    ALGEBRAIC(:,19) = ( (CONSTANTS(:,30)+CONSTANTS(:,34)).*CONSTANTS(:,37))./(CONSTANTS(:,37)+STATES(:,5));
    ALGEBRAIC(:,21) = ( CONSTANTS(:,32).*CONSTANTS(:,37)+ CONSTANTS(:,35).*STATES(:,5))./(CONSTANTS(:,37)+STATES(:,5));
    RATES(:,8) =  STATES(:,7).*(1.00000 - STATES(:,8)) -  (( CONSTANTS(:,42).*ALGEBRAIC(:,18).*ALGEBRAIC(:,21))./( CONSTANTS(:,42).*ALGEBRAIC(:,18)+ALGEBRAIC(:,19))).*STATES(:,8);
    ALGEBRAIC(:,20) =  CONSTANTS(:,29).*power(( CONSTANTS(:,42).*ALGEBRAIC(:,18).*STATES(:,8))./( CONSTANTS(:,42).*ALGEBRAIC(:,18)+ALGEBRAIC(:,19)), 4.00000).*(STATES(:,4) - STATES(:,5));
    RATES(:,5) =  CONSTANTS(:,54).*ALGEBRAIC(:,20) - ( CONSTANTS(:,55).*ALGEBRAIC(:,16)+ CONSTANTS(:,53).*ALGEBRAIC(:,14));
    RATES(:,4) = ALGEBRAIC(:,11) - ALGEBRAIC(:,20);
   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(:,2) =  CONSTANTS(:,38).*(power(STATES(:,5), CONSTANTS(:,39))./(power(CONSTANTS(:,41), CONSTANTS(:,39))+power(STATES(:,5), CONSTANTS(:,39))));
    ALGEBRAIC(:,1) =  (( CONSTANTS(:,4).*CONSTANTS(:,3))./( 2.00000.*CONSTANTS(:,5))).*log(CONSTANTS(:,6)./STATES(:,2));
    ALGEBRAIC(:,3) =  CONSTANTS(:,2).*(STATES(:,1) - ALGEBRAIC(:,1));
    ALGEBRAIC(:,4) =  CONSTANTS(:,7).*(power(CONSTANTS(:,10), CONSTANTS(:,8))./(power(CONSTANTS(:,10), CONSTANTS(:,8))+power(STATES(:,2), CONSTANTS(:,8))));
    ALGEBRAIC(:,5) =  ALGEBRAIC(:,4).*(STATES(:,1) - CONSTANTS(:,9));
    ALGEBRAIC(:,8) =  CONSTANTS(:,12).*(power(STATES(:,2), 2.00000)./(power(CONSTANTS(:,13), 2.00000)+power(STATES(:,2), 2.00000)));
    ALGEBRAIC(:,9) = ALGEBRAIC(:,3)+ALGEBRAIC(:,5)+ALGEBRAIC(:,8);
    ALGEBRAIC(:,10) =  CONSTANTS(:,14).*(power(STATES(:,3), CONSTANTS(:,16))./(power(CONSTANTS(:,15), CONSTANTS(:,16))+power(STATES(:,3), CONSTANTS(:,16))));
    ALGEBRAIC(:,6) =  CONSTANTS(:,11).*(power(CONSTANTS(:,10), CONSTANTS(:,8))./(power(CONSTANTS(:,10), CONSTANTS(:,8))+power(STATES(:,2), CONSTANTS(:,8))));
    ALGEBRAIC(:,7) =  ALGEBRAIC(:,6).*(STATES(:,1) - CONSTANTS(:,9));
    ALGEBRAIC(:,12) = ALGEBRAIC(:,7)+ALGEBRAIC(:,10);
    ALGEBRAIC(:,11) = ( CONSTANTS(:,17).*(STATES(:,2) -  CONSTANTS(:,18).*STATES(:,4)))./(1.00000+ CONSTANTS(:,19).*STATES(:,2)+ CONSTANTS(:,20).*STATES(:,4)+ CONSTANTS(:,21).*STATES(:,2).*STATES(:,4));
    ALGEBRAIC(:,15) =  CONSTANTS(:,26).*(STATES(:,6)./(STATES(:,6)+CONSTANTS(:,27)));
    ALGEBRAIC(:,16) =  CONSTANTS(:,28).*(STATES(:,5) - STATES(:,2));
    ALGEBRAIC(:,13) = power(CONSTANTS(:,24), CONSTANTS(:,25))./(power(CONSTANTS(:,24), CONSTANTS(:,25))+power(STATES(:,6), CONSTANTS(:,25)));
    ALGEBRAIC(:,14) =  CONSTANTS(:,22).*(power(STATES(:,5), 2.00000)./(power(CONSTANTS(:,23), 2.00000)+power(STATES(:,5), 2.00000))).*ALGEBRAIC(:,13);
    ALGEBRAIC(:,17) = 1.00000./(1.00000+( CONSTANTS(:,48).*CONSTANTS(:,49))./power(CONSTANTS(:,48)+STATES(:,6), 2.00000));
    ALGEBRAIC(:,18) = ( CONSTANTS(:,31).*CONSTANTS(:,36)+ CONSTANTS(:,33).*STATES(:,5))./(CONSTANTS(:,36)+STATES(:,5));
    ALGEBRAIC(:,19) = ( (CONSTANTS(:,30)+CONSTANTS(:,34)).*CONSTANTS(:,37))./(CONSTANTS(:,37)+STATES(:,5));
    ALGEBRAIC(:,21) = ( CONSTANTS(:,32).*CONSTANTS(:,37)+ CONSTANTS(:,35).*STATES(:,5))./(CONSTANTS(:,37)+STATES(:,5));
    ALGEBRAIC(:,20) =  CONSTANTS(:,29).*power(( CONSTANTS(:,42).*ALGEBRAIC(:,18).*STATES(:,8))./( CONSTANTS(:,42).*ALGEBRAIC(:,18)+ALGEBRAIC(:,19)), 4.00000).*(STATES(:,4) - STATES(:,5));
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