# 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 =11;
end
% There are a total of 10 entries in each of the rate and state variable arrays.
% There are a total of 27 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_ALGEBRAIC(:,3) = strpad('Rate_Ca_influx_across_the_SR in component Ca_influx_across_the_SR (flux)');
LEGEND_CONSTANTS(:,1) = strpad('Ca_e in component extracellular_calcium (molar)');
LEGEND_STATES(:,1) = strpad('Ca_f in component fuzzy_space_calcium (molar)');
LEGEND_CONSTANTS(:,2) = strpad('k1 in component Ca_influx_across_the_SR (first_order_rate_constant)');
LEGEND_STATES(:,2) = strpad('Ca_2_S1 in component Ca_bound_to_the_SRRC_fast_activating_binding_site (molar)');
LEGEND_STATES(:,3) = strpad('Ca_S2 in component Ca_bound_to_the_SRRC_slow_inactivating_binding_site (molar)');
LEGEND_STATES(:,4) = strpad('S1 in component SRRC_fast_activating_binding_site (molar)');
LEGEND_STATES(:,5) = strpad('S2 in component SRRC_slow_inactivating_binding_site (molar)');
LEGEND_STATES(:,6) = strpad('Ca_s in component SR_calcium (molar)');
LEGEND_ALGEBRAIC(:,1) = strpad('dCa2_S1_dt in component Ca_movement_through_the_SRRC (flux)');
LEGEND_ALGEBRAIC(:,2) = strpad('dCa_S2_dt in component Ca_movement_through_the_SRRC (flux)');
LEGEND_CONSTANTS(:,3) = strpad('k_on1 in component Ca_movement_through_the_SRRC (second_order_rate_constant)');
LEGEND_CONSTANTS(:,4) = strpad('k_off1 in component Ca_movement_through_the_SRRC (first_order_rate_constant)');
LEGEND_CONSTANTS(:,5) = strpad('k_on2 in component Ca_movement_through_the_SRRC (second_order_rate_constant)');
LEGEND_CONSTANTS(:,6) = strpad('k_off2 in component Ca_movement_through_the_SRRC (first_order_rate_constant)');
LEGEND_CONSTANTS(:,7) = strpad('k_s in component Ca_movement_through_the_SRRC (first_order_rate_constant)');
LEGEND_STATES(:,7) = strpad('cas1 in component Ca_movement_through_the_SRRC (dimensionless)');
LEGEND_STATES(:,8) = strpad('cas2 in component Ca_movement_through_the_SRRC (dimensionless)');
LEGEND_ALGEBRAIC(:,5) = strpad('dcas1_dt in component Ca_movement_through_the_SRRC (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,6) = strpad('dcas2_dt in component Ca_movement_through_the_SRRC (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,4) = strpad('r_o in component Ca_movement_through_the_SRRC (dimensionless)');
LEGEND_ALGEBRAIC(:,7) = strpad('Rate_Ca_movement_through_the_SRRC in component Ca_movement_through_the_SRRC (flux)');
LEGEND_CONSTANTS(:,8) = strpad('Km_NaCaX in component Ca_efflux_across_the_SR_by_NaCa_exchange (molar)');
LEGEND_CONSTANTS(:,9) = strpad('Vmax_NaCaX in component Ca_efflux_across_the_SR_by_NaCa_exchange (flux)');
LEGEND_ALGEBRAIC(:,8) = strpad('Rate_Ca_efflux_across_the_SR_by_NaCa_exchange in component Ca_efflux_across_the_SR_by_NaCa_exchange (flux)');
LEGEND_STATES(:,9) = strpad('Ca_c in component cytosolic_calcium (molar)');
LEGEND_CONSTANTS(:,10) = strpad('kf in component Ca_movement_between_the_fuzzy_space_and_cytosol (first_order_rate_constant)');
LEGEND_ALGEBRAIC(:,9) = strpad('Rate_Ca_movement_between_the_fuzzy_space_and_cytosol in component Ca_movement_between_the_fuzzy_space_and_cytosol (flux)');
LEGEND_CONSTANTS(:,11) = strpad('Km_s in component Ca_uptake_by_SR_Ca_ATPase (molar)');
LEGEND_CONSTANTS(:,12) = strpad('Vmax_s in component Ca_uptake_by_SR_Ca_ATPase (flux)');
LEGEND_ALGEBRAIC(:,10) = strpad('Rate_Ca_uptake_by_SR_Ca_ATPase in component Ca_uptake_by_SR_Ca_ATPase (flux)');
LEGEND_STATES(:,10) = strpad('Ca_CSQ in component calsequestrin_bound_calcium (molar)');
LEGEND_CONSTANTS(:,13) = strpad('K_ons in component Ca_buffering_in_the_SR (second_order_rate_constant)');
LEGEND_CONSTANTS(:,14) = strpad('K_offs in component Ca_buffering_in_the_SR (first_order_rate_constant)');
LEGEND_CONSTANTS(:,15) = strpad('Bmax_s in component Ca_buffering_in_the_SR (molar)');
LEGEND_ALGEBRAIC(:,11) = strpad('Rate_Ca_buffering_in_the_SR in component Ca_buffering_in_the_SR (flux)');
LEGEND_CONSTANTS(:,16) = strpad('Rt in component fuzzy_space_calcium (molar)');
LEGEND_CONSTANTS(:,17) = strpad('Bmax_f1 in component fuzzy_space_calcium (molar)');
LEGEND_CONSTANTS(:,18) = strpad('Bmax_f2 in component fuzzy_space_calcium (molar)');
LEGEND_CONSTANTS(:,19) = strpad('Kb_f1 in component fuzzy_space_calcium (molar)');
LEGEND_CONSTANTS(:,20) = strpad('Kb_f2 in component fuzzy_space_calcium (molar)');
LEGEND_CONSTANTS(:,21) = strpad('V_f in component fuzzy_space_calcium (dimensionless)');
LEGEND_CONSTANTS(:,22) = strpad('Bmax_c in component cytosolic_calcium (molar)');
LEGEND_CONSTANTS(:,23) = strpad('dye_c in component cytosolic_calcium (molar)');
LEGEND_CONSTANTS(:,24) = strpad('Kb_c in component cytosolic_calcium (molar)');
LEGEND_CONSTANTS(:,25) = strpad('Kb_dye in component cytosolic_calcium (molar)');
LEGEND_CONSTANTS(:,26) = strpad('V_c in component cytosolic_calcium (dimensionless)');
LEGEND_CONSTANTS(:,27) = strpad('V_s in component SR_calcium (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt cas1 in component Ca_movement_through_the_SRRC (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt cas2 in component Ca_movement_through_the_SRRC (dimensionless)');
LEGEND_RATES(:,1) = strpad('d/dt Ca_f in component fuzzy_space_calcium (molar)');
LEGEND_RATES(:,9) = strpad('d/dt Ca_c in component cytosolic_calcium (molar)');
LEGEND_RATES(:,6) = strpad('d/dt Ca_s in component SR_calcium (molar)');
LEGEND_RATES(:,10) = strpad('d/dt Ca_CSQ in component calsequestrin_bound_calcium (molar)');
LEGEND_RATES(:,4) = strpad('d/dt S1 in component SRRC_fast_activating_binding_site (molar)');
LEGEND_RATES(:,5) = strpad('d/dt S2 in component SRRC_slow_inactivating_binding_site (molar)');
LEGEND_RATES(:,2) = strpad('d/dt Ca_2_S1 in component Ca_bound_to_the_SRRC_fast_activating_binding_site (molar)');
LEGEND_RATES(:,3) = strpad('d/dt Ca_S2 in component Ca_bound_to_the_SRRC_slow_inactivating_binding_site (molar)');
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) = 0.002;
STATES(:,1) = 0.12e-6;
CONSTANTS(:,2) = 0.2;
STATES(:,2) = 0;
STATES(:,3) = 0;
STATES(:,4) = 0;
STATES(:,5) = 0;
STATES(:,6) = 201e-6;
CONSTANTS(:,3) = 2000000000;
CONSTANTS(:,4) = 1400;
CONSTANTS(:,5) = 13000000;
CONSTANTS(:,6) = 3.9;
CONSTANTS(:,7) = 9;
STATES(:,7) = 0;
STATES(:,8) = 0;
CONSTANTS(:,8) = 0.000036;
CONSTANTS(:,9) = 0.0012;
STATES(:,9) = 1e-7;
CONSTANTS(:,10) = 2500;
CONSTANTS(:,11) = 0.00000025;
CONSTANTS(:,12) = 0.000525;
STATES(:,10) = 0;
CONSTANTS(:,13) = 8772;
CONSTANTS(:,14) = 5.596536;
CONSTANTS(:,15) = 0.008;
CONSTANTS(:,16) = 0.00000015;
CONSTANTS(:,17) = 0.0002;
CONSTANTS(:,18) = 0.0011;
CONSTANTS(:,19) = 0.000017;
CONSTANTS(:,20) = 0.000013;
CONSTANTS(:,21) = 0.0013;
CONSTANTS(:,22) = 0.00012;
CONSTANTS(:,23) = 0;
CONSTANTS(:,24) = 0.00000096;
CONSTANTS(:,25) = 2e-7;
CONSTANTS(:,26) = 0.9287;
CONSTANTS(:,27) = 0.07;
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(:,1) =  CONSTANTS(:,3).*STATES(:,1).*STATES(:,4) -  (power(CONSTANTS(:,4), 2.00000)./( CONSTANTS(:,3).*STATES(:,1))).*STATES(:,2);
RATES(:,4) =  - ALGEBRAIC(:,1);
ALGEBRAIC(:,2) =  CONSTANTS(:,5).*STATES(:,1).*STATES(:,5) -  CONSTANTS(:,6).*STATES(:,3);
RATES(:,5) =  - ALGEBRAIC(:,2);
RATES(:,2) = ALGEBRAIC(:,1);
RATES(:,3) = ALGEBRAIC(:,2);
ALGEBRAIC(:,5) =  CONSTANTS(:,3).*STATES(:,1).*(1.00000 - STATES(:,7)) -  (power(CONSTANTS(:,4), 2.00000)./( CONSTANTS(:,3).*STATES(:,1))).*STATES(:,7);
RATES(:,7) = ALGEBRAIC(:,5);
ALGEBRAIC(:,6) =  CONSTANTS(:,5).*STATES(:,1).*(1.00000 - STATES(:,8)) -  CONSTANTS(:,6).*STATES(:,8);
RATES(:,8) = ALGEBRAIC(:,6);
ALGEBRAIC(:,3) =  CONSTANTS(:,2).*(CONSTANTS(:,1) - STATES(:,1));
ALGEBRAIC(:,4) =  STATES(:,7).*(1.00000 - STATES(:,8));
ALGEBRAIC(:,7) =  CONSTANTS(:,7).*ALGEBRAIC(:,4).*(STATES(:,6) - STATES(:,1));
ALGEBRAIC(:,8) = ( CONSTANTS(:,9).*STATES(:,1))./(CONSTANTS(:,8)+STATES(:,1));
ALGEBRAIC(:,9) =  CONSTANTS(:,10).*(STATES(:,1) - STATES(:,9));
RATES(:,1) = ((ALGEBRAIC(:,7) - ( CONSTANTS(:,16).*(ALGEBRAIC(:,5)+ALGEBRAIC(:,6))+ALGEBRAIC(:,9)+ALGEBRAIC(:,8)))+ALGEBRAIC(:,3))./(( CONSTANTS(:,17).*CONSTANTS(:,19))./power(STATES(:,1)+CONSTANTS(:,19), 2.00000)+( CONSTANTS(:,18).*CONSTANTS(:,20))./power(STATES(:,1)+CONSTANTS(:,20), 2.00000)+CONSTANTS(:,21));
ALGEBRAIC(:,10) = ( CONSTANTS(:,12).*(power(STATES(:,9), 2.00000) - power(STATES(:,6), 2.00000)./power(7000.00, 2.00000)))./(power(CONSTANTS(:,11), 2.00000)+power(STATES(:,9), 2.00000)+power(STATES(:,6), 2.00000)./power(7000.00, 2.00000));
RATES(:,9) = (ALGEBRAIC(:,9) - ALGEBRAIC(:,10))./(( CONSTANTS(:,22).*CONSTANTS(:,24))./power(STATES(:,9)+CONSTANTS(:,24), 2.00000)+( CONSTANTS(:,23).*CONSTANTS(:,25))./power(STATES(:,9)+CONSTANTS(:,25), 2.00000)+CONSTANTS(:,26));
ALGEBRAIC(:,11) =  CONSTANTS(:,13).*STATES(:,6).*(CONSTANTS(:,15) - STATES(:,10)) -  CONSTANTS(:,14).*STATES(:,10);
RATES(:,6) = (ALGEBRAIC(:,10) - ALGEBRAIC(:,7))./CONSTANTS(:,27) - ALGEBRAIC(:,11);
RATES(:,10) = ALGEBRAIC(:,11);
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(:,1) =  CONSTANTS(:,3).*STATES(:,1).*STATES(:,4) -  (power(CONSTANTS(:,4), 2.00000)./( CONSTANTS(:,3).*STATES(:,1))).*STATES(:,2);
ALGEBRAIC(:,2) =  CONSTANTS(:,5).*STATES(:,1).*STATES(:,5) -  CONSTANTS(:,6).*STATES(:,3);
ALGEBRAIC(:,5) =  CONSTANTS(:,3).*STATES(:,1).*(1.00000 - STATES(:,7)) -  (power(CONSTANTS(:,4), 2.00000)./( CONSTANTS(:,3).*STATES(:,1))).*STATES(:,7);
ALGEBRAIC(:,6) =  CONSTANTS(:,5).*STATES(:,1).*(1.00000 - STATES(:,8)) -  CONSTANTS(:,6).*STATES(:,8);
ALGEBRAIC(:,3) =  CONSTANTS(:,2).*(CONSTANTS(:,1) - STATES(:,1));
ALGEBRAIC(:,4) =  STATES(:,7).*(1.00000 - STATES(:,8));
ALGEBRAIC(:,7) =  CONSTANTS(:,7).*ALGEBRAIC(:,4).*(STATES(:,6) - STATES(:,1));
ALGEBRAIC(:,8) = ( CONSTANTS(:,9).*STATES(:,1))./(CONSTANTS(:,8)+STATES(:,1));
ALGEBRAIC(:,9) =  CONSTANTS(:,10).*(STATES(:,1) - STATES(:,9));
ALGEBRAIC(:,10) = ( CONSTANTS(:,12).*(power(STATES(:,9), 2.00000) - power(STATES(:,6), 2.00000)./power(7000.00, 2.00000)))./(power(CONSTANTS(:,11), 2.00000)+power(STATES(:,9), 2.00000)+power(STATES(:,6), 2.00000)./power(7000.00, 2.00000));
ALGEBRAIC(:,11) =  CONSTANTS(:,13).*STATES(:,6).*(CONSTANTS(:,15) - STATES(:,10)) -  CONSTANTS(:,14).*STATES(:,10);
end

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

```
Source
Derived from workspace Snyder, Palmer, Moore, 2000 at changeset 375fae3a770d.
Collaboration
To begin collaborating on this work, please use your git client and issue this command:
Tools