# 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 =31;
end
% There are a total of 10 entries in each of the rate and state variable arrays.
% There are a total of 13 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 (millisecond)');
LEGEND_STATES(:,1) = strpad('V in component membrane (millivolt)');
LEGEND_CONSTANTS(:,1) = strpad('C in component membrane (microF_per_cm2)');
LEGEND_ALGEBRAIC(:,1) = strpad('i_Na in component fast_sodium_current (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,21) = strpad('i_si in component secondary_inward_current (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,23) = strpad('i_K2 in component pacemaker_potassium_current (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,25) = strpad('i_x1 in component plateau_potassium_current1 (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,27) = strpad('i_x2 in component plateau_potassium_current2 (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,28) = strpad('i_qr in component transient_chloride_current (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,29) = strpad('i_K1 in component time_independent_outward_current (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,30) = strpad('i_Na_b in component sodium_background_current (microA_per_cm2)');
LEGEND_ALGEBRAIC(:,31) = strpad('i_Cl_b in component chloride_background_current (microA_per_cm2)');
LEGEND_CONSTANTS(:,2) = strpad('E_Na in component fast_sodium_current (millivolt)');
LEGEND_CONSTANTS(:,3) = strpad('g_Na in component fast_sodium_current (milliS_per_cm2)');
LEGEND_STATES(:,2) = strpad('m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_STATES(:,3) = strpad('h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,2) = strpad('alpha_m in component fast_sodium_current_m_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,12) = strpad('beta_m in component fast_sodium_current_m_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,3) = strpad('alpha_h in component fast_sodium_current_h_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,13) = strpad('beta_h in component fast_sodium_current_h_gate (per_millisecond)');
LEGEND_CONSTANTS(:,4) = strpad('g_si in component secondary_inward_current (milliS_per_cm2)');
LEGEND_CONSTANTS(:,5) = strpad('g_si_ in component secondary_inward_current (milliS_per_cm2)');
LEGEND_CONSTANTS(:,6) = strpad('E_si in component secondary_inward_current (millivolt)');
LEGEND_STATES(:,4) = strpad('d in component secondary_inward_current_d_gate (dimensionless)');
LEGEND_STATES(:,5) = strpad('f in component secondary_inward_current_f_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,11) = strpad('d1 in component secondary_inward_current_d1_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,4) = strpad('alpha_d in component secondary_inward_current_d_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,14) = strpad('beta_d in component secondary_inward_current_d_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,5) = strpad('alpha_f in component secondary_inward_current_f_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,15) = strpad('beta_f in component secondary_inward_current_f_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,22) = strpad('I_K2 in component pacemaker_potassium_current (microA_per_cm2)');
LEGEND_CONSTANTS(:,7) = strpad('E_K in component pacemaker_potassium_current (millivolt)');
LEGEND_STATES(:,6) = strpad('s in component pacemaker_potassium_current_s_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,6) = strpad('alpha_s in component pacemaker_potassium_current_s_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,16) = strpad('beta_s in component pacemaker_potassium_current_s_gate (per_millisecond)');
LEGEND_CONSTANTS(:,8) = strpad('E_s in component pacemaker_potassium_current_s_gate (millivolt)');
LEGEND_ALGEBRAIC(:,24) = strpad('I_x1 in component plateau_potassium_current1 (microA_per_cm2)');
LEGEND_STATES(:,7) = strpad('x1 in component plateau_potassium_current1_x1_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,7) = strpad('alpha_x1 in component plateau_potassium_current1_x1_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,17) = strpad('beta_x1 in component plateau_potassium_current1_x1_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,26) = strpad('I_x2 in component plateau_potassium_current2 (microA_per_cm2)');
LEGEND_STATES(:,8) = strpad('x2 in component plateau_potassium_current2_x2_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,8) = strpad('alpha_x2 in component plateau_potassium_current2_x2_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,18) = strpad('beta_x2 in component plateau_potassium_current2_x2_gate (per_millisecond)');
LEGEND_CONSTANTS(:,9) = strpad('E_Cl in component transient_chloride_current (millivolt)');
LEGEND_CONSTANTS(:,10) = strpad('g_qr in component transient_chloride_current (milliS_per_cm2)');
LEGEND_STATES(:,9) = strpad('q in component transient_chloride_current_q_gate (dimensionless)');
LEGEND_STATES(:,10) = strpad('r in component transient_chloride_current_r_gate (dimensionless)');
LEGEND_ALGEBRAIC(:,9) = strpad('alpha_q in component transient_chloride_current_q_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,19) = strpad('beta_q in component transient_chloride_current_q_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,10) = strpad('alpha_r in component transient_chloride_current_r_gate (per_millisecond)');
LEGEND_ALGEBRAIC(:,20) = strpad('beta_r in component transient_chloride_current_r_gate (per_millisecond)');
LEGEND_CONSTANTS(:,11) = strpad('E_K1 in component time_independent_outward_current (millivolt)');
LEGEND_CONSTANTS(:,12) = strpad('g_Nab in component sodium_background_current (milliS_per_cm2)');
LEGEND_CONSTANTS(:,13) = strpad('g_Clb in component chloride_background_current (milliS_per_cm2)');
LEGEND_RATES(:,1) = strpad('d/dt V in component membrane (millivolt)');
LEGEND_RATES(:,2) = strpad('d/dt m in component fast_sodium_current_m_gate (dimensionless)');
LEGEND_RATES(:,3) = strpad('d/dt h in component fast_sodium_current_h_gate (dimensionless)');
LEGEND_RATES(:,4) = strpad('d/dt d in component secondary_inward_current_d_gate (dimensionless)');
LEGEND_RATES(:,5) = strpad('d/dt f in component secondary_inward_current_f_gate (dimensionless)');
LEGEND_RATES(:,6) = strpad('d/dt s in component pacemaker_potassium_current_s_gate (dimensionless)');
LEGEND_RATES(:,7) = strpad('d/dt x1 in component plateau_potassium_current1_x1_gate (dimensionless)');
LEGEND_RATES(:,8) = strpad('d/dt x2 in component plateau_potassium_current2_x2_gate (dimensionless)');
LEGEND_RATES(:,9) = strpad('d/dt q in component transient_chloride_current_q_gate (dimensionless)');
LEGEND_RATES(:,10) = strpad('d/dt r in component transient_chloride_current_r_gate (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) = -78.041367;
CONSTANTS(:,1) = 10;
CONSTANTS(:,2) = 40;
CONSTANTS(:,3) = 150;
STATES(:,2) = 0.02566853;
STATES(:,3) = 0.78656359;
CONSTANTS(:,4) = 0.8;
CONSTANTS(:,5) = 0.04;
CONSTANTS(:,6) = 70;
STATES(:,4) = 0.00293135;
STATES(:,5) = 0.80873917;
CONSTANTS(:,7) = -110;
STATES(:,6) = 0.75473994;
CONSTANTS(:,8) = -52;
STATES(:,7) = 0.02030289;
STATES(:,8) = 0.0176854;
CONSTANTS(:,9) = -70;
CONSTANTS(:,10) = 2.5;
STATES(:,9) = 3.11285794;
STATES(:,10) = 0.13500116;
CONSTANTS(:,11) = -30;
CONSTANTS(:,12) = 0.105;
CONSTANTS(:,13) = 0.01;
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) = ( 1.00000.*(STATES(:,1)+47.0000))./(1.00000 - exp( - (STATES(:,1)+47.0000)./10.0000));
ALGEBRAIC(:,12) =  40.0000.*exp(  - 0.0560000.*(STATES(:,1)+72.0000));
RATES(:,2) =  ALGEBRAIC(:,2).*(1.00000 - STATES(:,2)) -  ALGEBRAIC(:,12).*STATES(:,2);
ALGEBRAIC(:,3) =  0.00850000.*exp(  - 0.184000.*(STATES(:,1)+71.0000));
ALGEBRAIC(:,13) = 2.50000./(exp(  - 0.0820000.*(STATES(:,1)+10.0000))+1.00000);
RATES(:,3) =  ALGEBRAIC(:,3).*(1.00000 - STATES(:,3)) -  ALGEBRAIC(:,13).*STATES(:,3);
ALGEBRAIC(:,4) = ( 0.00200000.*(STATES(:,1)+40.0000))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+40.0000)));
ALGEBRAIC(:,14) =  0.0200000.*exp(  - 0.0888000.*(STATES(:,1)+40.0000));
RATES(:,4) =  ALGEBRAIC(:,4).*(1.00000 - STATES(:,4)) -  ALGEBRAIC(:,14).*STATES(:,4);
ALGEBRAIC(:,5) =  0.000987000.*exp(  - 0.0400000.*(STATES(:,1)+60.0000));
ALGEBRAIC(:,15) = 0.0200000./(exp(  - 0.0870000.*(STATES(:,1)+26.0000))+1.00000);
RATES(:,5) =  ALGEBRAIC(:,5).*(1.00000 - STATES(:,5)) -  ALGEBRAIC(:,15).*STATES(:,5);
ALGEBRAIC(:,6) = ( 0.00100000.*(STATES(:,1) - CONSTANTS(:,8)))./(1.00000 - exp(  - 0.200000.*(STATES(:,1) - CONSTANTS(:,8))));
ALGEBRAIC(:,16) =  5.00000e-05.*exp(  - 0.0670000.*(STATES(:,1) - CONSTANTS(:,8)));
RATES(:,6) =  ALGEBRAIC(:,6).*(1.00000 - STATES(:,6)) -  ALGEBRAIC(:,16).*STATES(:,6);
ALGEBRAIC(:,7) = ( 0.000500000.*exp((STATES(:,1)+50.0000)./12.1000))./(1.00000+exp((STATES(:,1)+50.0000)./17.5000));
ALGEBRAIC(:,17) = ( 0.00130000.*exp( - (STATES(:,1)+20.0000)./16.6700))./(1.00000+exp( - (STATES(:,1)+20.0000)./25.0000));
RATES(:,7) =  ALGEBRAIC(:,7).*(1.00000 - STATES(:,7)) -  ALGEBRAIC(:,17).*STATES(:,7);
ALGEBRAIC(:,8) = ( 0.000127000.*1.00000)./(1.00000+exp( - (STATES(:,1)+19.0000)./5.00000));
ALGEBRAIC(:,18) = ( 0.000300000.*exp( - (STATES(:,1)+20.0000)./16.6700))./(1.00000+exp( - (STATES(:,1)+20.0000)./25.0000));
RATES(:,8) =  ALGEBRAIC(:,8).*(1.00000 - STATES(:,8)) -  ALGEBRAIC(:,18).*STATES(:,8);
ALGEBRAIC(:,9) = ( 0.00800000.*STATES(:,1))./(1.00000 - exp(  - 0.100000.*STATES(:,1)));
ALGEBRAIC(:,19) =  0.0800000.*exp(  - 0.0888000.*STATES(:,1));
RATES(:,9) =  ALGEBRAIC(:,9).*(1.00000 - STATES(:,9)) -  ALGEBRAIC(:,19).*STATES(:,9);
ALGEBRAIC(:,10) =  0.000180000.*exp(  - 0.0400000.*(STATES(:,1)+80.0000));
ALGEBRAIC(:,20) = 0.0200000./(exp(  - 0.0870000.*(STATES(:,1)+26.0000))+1.00000);
RATES(:,10) =  ALGEBRAIC(:,10).*(1.00000 - STATES(:,10)) -  ALGEBRAIC(:,20).*STATES(:,10);
ALGEBRAIC(:,1) =  CONSTANTS(:,3).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - CONSTANTS(:,2));
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp(  - 0.150000.*(STATES(:,1)+40.0000)));
ALGEBRAIC(:,21) =  CONSTANTS(:,4).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - CONSTANTS(:,6))+ CONSTANTS(:,5).*ALGEBRAIC(:,11).*(STATES(:,1) - CONSTANTS(:,6));
ALGEBRAIC(:,22) = ( 2.80000.*(exp((STATES(:,1) - CONSTANTS(:,7))./25.0000) - 1.00000))./(exp((STATES(:,1)+60.0000)./12.5000)+exp((STATES(:,1)+60.0000)./25.0000));
ALGEBRAIC(:,23) =  ALGEBRAIC(:,22).*STATES(:,6);
ALGEBRAIC(:,24) = ( 1.20000.*(exp((STATES(:,1)+95.0000)./25.0000) - 1.00000))./exp((STATES(:,1)+45.0000)./25.0000);
ALGEBRAIC(:,25) =  STATES(:,7).*ALGEBRAIC(:,24);
ALGEBRAIC(:,26) = 25.0000+ 1.00000.*0.385000.*STATES(:,1);
ALGEBRAIC(:,27) =  STATES(:,8).*ALGEBRAIC(:,26);
ALGEBRAIC(:,28) =  CONSTANTS(:,10).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,9));
ALGEBRAIC(:,29) = ALGEBRAIC(:,22)./2.80000+( 0.200000.*(STATES(:,1) - CONSTANTS(:,11)))./(1.00000 - exp( - (STATES(:,1) - CONSTANTS(:,11))./25.0000));
ALGEBRAIC(:,30) =  CONSTANTS(:,12).*(STATES(:,1) - CONSTANTS(:,2));
ALGEBRAIC(:,31) =  CONSTANTS(:,13).*(STATES(:,1) - CONSTANTS(:,9));
RATES(:,1) =  - (ALGEBRAIC(:,1)+ALGEBRAIC(:,21)+ALGEBRAIC(:,23)+ALGEBRAIC(:,25)+ALGEBRAIC(:,27)+ALGEBRAIC(:,28)+ALGEBRAIC(:,29)+ALGEBRAIC(:,30)+ALGEBRAIC(:,31))./CONSTANTS(:,1);
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) = ( 1.00000.*(STATES(:,1)+47.0000))./(1.00000 - exp( - (STATES(:,1)+47.0000)./10.0000));
ALGEBRAIC(:,12) =  40.0000.*exp(  - 0.0560000.*(STATES(:,1)+72.0000));
ALGEBRAIC(:,3) =  0.00850000.*exp(  - 0.184000.*(STATES(:,1)+71.0000));
ALGEBRAIC(:,13) = 2.50000./(exp(  - 0.0820000.*(STATES(:,1)+10.0000))+1.00000);
ALGEBRAIC(:,4) = ( 0.00200000.*(STATES(:,1)+40.0000))./(1.00000 - exp(  - 0.100000.*(STATES(:,1)+40.0000)));
ALGEBRAIC(:,14) =  0.0200000.*exp(  - 0.0888000.*(STATES(:,1)+40.0000));
ALGEBRAIC(:,5) =  0.000987000.*exp(  - 0.0400000.*(STATES(:,1)+60.0000));
ALGEBRAIC(:,15) = 0.0200000./(exp(  - 0.0870000.*(STATES(:,1)+26.0000))+1.00000);
ALGEBRAIC(:,6) = ( 0.00100000.*(STATES(:,1) - CONSTANTS(:,8)))./(1.00000 - exp(  - 0.200000.*(STATES(:,1) - CONSTANTS(:,8))));
ALGEBRAIC(:,16) =  5.00000e-05.*exp(  - 0.0670000.*(STATES(:,1) - CONSTANTS(:,8)));
ALGEBRAIC(:,7) = ( 0.000500000.*exp((STATES(:,1)+50.0000)./12.1000))./(1.00000+exp((STATES(:,1)+50.0000)./17.5000));
ALGEBRAIC(:,17) = ( 0.00130000.*exp( - (STATES(:,1)+20.0000)./16.6700))./(1.00000+exp( - (STATES(:,1)+20.0000)./25.0000));
ALGEBRAIC(:,8) = ( 0.000127000.*1.00000)./(1.00000+exp( - (STATES(:,1)+19.0000)./5.00000));
ALGEBRAIC(:,18) = ( 0.000300000.*exp( - (STATES(:,1)+20.0000)./16.6700))./(1.00000+exp( - (STATES(:,1)+20.0000)./25.0000));
ALGEBRAIC(:,9) = ( 0.00800000.*STATES(:,1))./(1.00000 - exp(  - 0.100000.*STATES(:,1)));
ALGEBRAIC(:,19) =  0.0800000.*exp(  - 0.0888000.*STATES(:,1));
ALGEBRAIC(:,10) =  0.000180000.*exp(  - 0.0400000.*(STATES(:,1)+80.0000));
ALGEBRAIC(:,20) = 0.0200000./(exp(  - 0.0870000.*(STATES(:,1)+26.0000))+1.00000);
ALGEBRAIC(:,1) =  CONSTANTS(:,3).*power(STATES(:,2), 3.00000).*STATES(:,3).*(STATES(:,1) - CONSTANTS(:,2));
ALGEBRAIC(:,11) = 1.00000./(1.00000+exp(  - 0.150000.*(STATES(:,1)+40.0000)));
ALGEBRAIC(:,21) =  CONSTANTS(:,4).*STATES(:,4).*STATES(:,5).*(STATES(:,1) - CONSTANTS(:,6))+ CONSTANTS(:,5).*ALGEBRAIC(:,11).*(STATES(:,1) - CONSTANTS(:,6));
ALGEBRAIC(:,22) = ( 2.80000.*(exp((STATES(:,1) - CONSTANTS(:,7))./25.0000) - 1.00000))./(exp((STATES(:,1)+60.0000)./12.5000)+exp((STATES(:,1)+60.0000)./25.0000));
ALGEBRAIC(:,23) =  ALGEBRAIC(:,22).*STATES(:,6);
ALGEBRAIC(:,24) = ( 1.20000.*(exp((STATES(:,1)+95.0000)./25.0000) - 1.00000))./exp((STATES(:,1)+45.0000)./25.0000);
ALGEBRAIC(:,25) =  STATES(:,7).*ALGEBRAIC(:,24);
ALGEBRAIC(:,26) = 25.0000+ 1.00000.*0.385000.*STATES(:,1);
ALGEBRAIC(:,27) =  STATES(:,8).*ALGEBRAIC(:,26);
ALGEBRAIC(:,28) =  CONSTANTS(:,10).*STATES(:,9).*STATES(:,10).*(STATES(:,1) - CONSTANTS(:,9));
ALGEBRAIC(:,29) = ALGEBRAIC(:,22)./2.80000+( 0.200000.*(STATES(:,1) - CONSTANTS(:,11)))./(1.00000 - exp( - (STATES(:,1) - CONSTANTS(:,11))./25.0000));
ALGEBRAIC(:,30) =  CONSTANTS(:,12).*(STATES(:,1) - CONSTANTS(:,2));
ALGEBRAIC(:,31) =  CONSTANTS(:,13).*(STATES(:,1) - CONSTANTS(:,9));
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 Mcallister, Noble, Tsien, 1975 at changeset b84d9a62c623.
Collaboration
To begin collaborating on this work, please use your git client and issue this command: