Generated Code
The following is python code generated by the CellML API from this CellML file. (Back to language selection)
The raw code is available.
# Size of variable arrays:
sizeAlgebraic = 65
sizeStates = 15
sizeConstants = 39
from math import *
from numpy import *
def createLegends():
legend_states = [""] * sizeStates
legend_rates = [""] * sizeStates
legend_algebraic = [""] * sizeAlgebraic
legend_voi = ""
legend_constants = [""] * sizeConstants
legend_voi = "t in component environment (second)"
legend_states[0] = "q_Ca_i in component environment (fmol)"
legend_states[1] = "q_Ca_SR in component environment (fmol)"
legend_states[2] = "q_H_i in component environment (fmol)"
legend_states[3] = "q_Pi in component environment (fmol)"
legend_states[4] = "q_MgADP in component environment (fmol)"
legend_states[5] = "q_MgATP in component environment (fmol)"
legend_states[6] = "q_P1_SERCA in component environment (fmol)"
legend_states[7] = "q_P2_SERCA in component environment (fmol)"
legend_states[8] = "q_P2a_SERCA in component environment (fmol)"
legend_states[9] = "q_P4_SERCA in component environment (fmol)"
legend_states[10] = "q_P5_SERCA in component environment (fmol)"
legend_states[11] = "q_P10_SERCA in component environment (fmol)"
legend_states[12] = "q_P6_SERCA in component environment (fmol)"
legend_states[13] = "q_P8_SERCA in component environment (fmol)"
legend_states[14] = "q_P9_SERCA in component environment (fmol)"
legend_constants[0] = "q_PLBp in component environment (fmol)"
legend_constants[1] = "q_PLBp_baseline in component environment (fmol)"
legend_algebraic[51] = "v_Ca_i_SERCA in component SERCA (fmol_per_sec)"
legend_algebraic[57] = "v_Ca_SR_SERCA in component SERCA (fmol_per_sec)"
legend_algebraic[62] = "v_H_SERCA in component SERCA (fmol_per_sec)"
legend_algebraic[48] = "v_MgADP_SERCA in component SERCA (fmol_per_sec)"
legend_algebraic[45] = "v_MgATP_SERCA in component SERCA (fmol_per_sec)"
legend_algebraic[43] = "v_Pi_SERCA in component SERCA (fmol_per_sec)"
legend_constants[2] = "kappa_SERCA_R1_2 in component SERCA_parameters (fmol_per_sec)"
legend_constants[3] = "kappa_SERCA_R2_4 in component SERCA_parameters (fmol_per_sec)"
legend_constants[4] = "kappa_SERCA_R2_2a in component SERCA_parameters (fmol_per_sec)"
legend_constants[5] = "kappa_SERCA_R4_5 in component SERCA_parameters (fmol_per_sec)"
legend_constants[6] = "kappa_SERCA_R5_6 in component SERCA_parameters (fmol_per_sec)"
legend_constants[7] = "kappa_SERCA_R6_8 in component SERCA_parameters (fmol_per_sec)"
legend_constants[8] = "kappa_SERCA_R8_9 in component SERCA_parameters (fmol_per_sec)"
legend_constants[9] = "kappa_SERCA_R9_10 in component SERCA_parameters (fmol_per_sec)"
legend_constants[10] = "kappa_SERCA_R10_1 in component SERCA_parameters (fmol_per_sec)"
legend_constants[11] = "K_P1_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[12] = "K_P2_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[13] = "K_P2a_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[14] = "K_P4_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[15] = "K_P5_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[16] = "K_P6_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[17] = "K_P8_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[18] = "K_P9_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[19] = "K_P10_SERCA in component SERCA_parameters (per_fmol)"
legend_constants[20] = "K_H in component SERCA_parameters (per_fmol)"
legend_constants[21] = "K_Ca_i in component SERCA_parameters (per_fmol)"
legend_constants[22] = "K_Ca_SR in component SERCA_parameters (per_fmol)"
legend_constants[23] = "K_MgATP in component SERCA_parameters (per_fmol)"
legend_constants[24] = "K_MgADP in component SERCA_parameters (per_fmol)"
legend_constants[25] = "K_Pi in component SERCA_parameters (per_fmol)"
legend_constants[26] = "K_PLBp in component SERCA_parameters (per_fmol)"
legend_constants[27] = "R in component constants (J_per_K_per_mol)"
legend_constants[28] = "T in component constants (kelvin)"
legend_constants[29] = "F in component constants (C_per_mol)"
legend_constants[30] = "n_Ca_i in component SERCA (dimensionless)"
legend_constants[31] = "n_Ca_SR in component SERCA (dimensionless)"
legend_constants[32] = "n_H in component SERCA (dimensionless)"
legend_algebraic[0] = "q_SERCA_Ca_complexes in component SERCA (fmol)"
legend_algebraic[1] = "c_Ca_i in component SERCA (mM)"
legend_algebraic[2] = "c_Ca_SR in component SERCA (mM)"
legend_algebraic[3] = "c_H in component SERCA (mM)"
legend_algebraic[4] = "c_MgADP in component SERCA (mM)"
legend_algebraic[5] = "c_MgATP in component SERCA (mM)"
legend_algebraic[6] = "c_Pi in component SERCA (mM)"
legend_constants[33] = "vol_i in component SERCA (pL)"
legend_constants[34] = "vol_sr in component SERCA (pL)"
legend_constants[36] = "vol_isr in component SERCA (pL)"
legend_algebraic[7] = "mu_Ca_i in component SERCA (J_per_mol)"
legend_algebraic[8] = "mu_Ca_SR in component SERCA (J_per_mol)"
legend_algebraic[9] = "mu_H in component SERCA (J_per_mol)"
legend_algebraic[10] = "mu_MgADP in component SERCA (J_per_mol)"
legend_algebraic[11] = "mu_MgATP in component SERCA (J_per_mol)"
legend_algebraic[13] = "mu_P1 in component SERCA (J_per_mol)"
legend_algebraic[46] = "v_P1 in component SERCA (fmol_per_sec)"
legend_algebraic[12] = "mu_Pi in component SERCA (J_per_mol)"
legend_algebraic[14] = "mu_P2 in component SERCA (J_per_mol)"
legend_algebraic[53] = "v_P2 in component SERCA (fmol_per_sec)"
legend_algebraic[15] = "mu_P2a in component SERCA (J_per_mol)"
legend_algebraic[50] = "v_P2a in component SERCA (fmol_per_sec)"
legend_algebraic[16] = "mu_P4 in component SERCA (J_per_mol)"
legend_algebraic[55] = "v_P4 in component SERCA (fmol_per_sec)"
legend_algebraic[17] = "mu_P5 in component SERCA (J_per_mol)"
legend_algebraic[56] = "v_P5 in component SERCA (fmol_per_sec)"
legend_algebraic[19] = "mu_P6 in component SERCA (J_per_mol)"
legend_algebraic[59] = "v_P6 in component SERCA (fmol_per_sec)"
legend_algebraic[21] = "mu_P8 in component SERCA (J_per_mol)"
legend_algebraic[61] = "v_P8 in component SERCA (fmol_per_sec)"
legend_algebraic[22] = "mu_P9 in component SERCA (J_per_mol)"
legend_algebraic[63] = "v_P9 in component SERCA (fmol_per_sec)"
legend_algebraic[18] = "mu_P10 in component SERCA (J_per_mol)"
legend_algebraic[64] = "v_P10 in component SERCA (fmol_per_sec)"
legend_constants[35] = "mu_PLBp_baseline in component SERCA (J_per_mol)"
legend_constants[37] = "mu_PLBp in component SERCA (J_per_mol)"
legend_constants[38] = "mu_PLBp_eff in component SERCA (J_per_mol)"
legend_algebraic[25] = "Af_R1_2 in component SERCA (J_per_mol)"
legend_algebraic[26] = "Ar_R1_2 in component SERCA (J_per_mol)"
legend_algebraic[42] = "v_SERCA_R1_2 in component SERCA (fmol_per_sec)"
legend_algebraic[27] = "Af_R5_6 in component SERCA (J_per_mol)"
legend_algebraic[28] = "Ar_R5_6 in component SERCA (J_per_mol)"
legend_algebraic[44] = "v_SERCA_R5_6 in component SERCA (fmol_per_sec)"
legend_algebraic[29] = "Af_R2_2a in component SERCA (J_per_mol)"
legend_algebraic[30] = "Ar_R2_2a in component SERCA (J_per_mol)"
legend_algebraic[47] = "v_SERCA_R2_2a in component SERCA (fmol_per_sec)"
legend_algebraic[31] = "Af_R2_4 in component SERCA (J_per_mol)"
legend_algebraic[32] = "Ar_R2_4 in component SERCA (J_per_mol)"
legend_algebraic[49] = "v_SERCA_R2_4 in component SERCA (fmol_per_sec)"
legend_algebraic[33] = "Af_R4_5 in component SERCA (J_per_mol)"
legend_algebraic[34] = "Ar_R4_5 in component SERCA (J_per_mol)"
legend_algebraic[52] = "v_SERCA_R4_5 in component SERCA (fmol_per_sec)"
legend_algebraic[35] = "Af_R6_8 in component SERCA (J_per_mol)"
legend_algebraic[36] = "Ar_R6_8 in component SERCA (J_per_mol)"
legend_algebraic[54] = "v_SERCA_R6_8 in component SERCA (fmol_per_sec)"
legend_algebraic[37] = "Af_R8_9 in component SERCA (J_per_mol)"
legend_algebraic[38] = "Ar_R8_9 in component SERCA (J_per_mol)"
legend_algebraic[58] = "v_SERCA_R8_9 in component SERCA (fmol_per_sec)"
legend_algebraic[39] = "Af_R9_10 in component SERCA (J_per_mol)"
legend_algebraic[40] = "Ar_R9_10 in component SERCA (J_per_mol)"
legend_algebraic[60] = "v_SERCA_R9_10 in component SERCA (fmol_per_sec)"
legend_algebraic[23] = "Af_R10_1 in component SERCA (J_per_mol)"
legend_algebraic[24] = "Ar_R10_1 in component SERCA (J_per_mol)"
legend_algebraic[41] = "v_SERCA_R10_1 in component SERCA (fmol_per_sec)"
legend_algebraic[20] = "v_SERCA_R10_1_noPLBp in component SERCA (fmol_per_sec)"
legend_rates[0] = "d/dt q_Ca_i in component environment (fmol)"
legend_rates[1] = "d/dt q_Ca_SR in component environment (fmol)"
legend_rates[2] = "d/dt q_H_i in component environment (fmol)"
legend_rates[4] = "d/dt q_MgADP in component environment (fmol)"
legend_rates[5] = "d/dt q_MgATP in component environment (fmol)"
legend_rates[3] = "d/dt q_Pi in component environment (fmol)"
legend_rates[6] = "d/dt q_P1_SERCA in component environment (fmol)"
legend_rates[7] = "d/dt q_P2_SERCA in component environment (fmol)"
legend_rates[8] = "d/dt q_P2a_SERCA in component environment (fmol)"
legend_rates[9] = "d/dt q_P4_SERCA in component environment (fmol)"
legend_rates[10] = "d/dt q_P5_SERCA in component environment (fmol)"
legend_rates[11] = "d/dt q_P10_SERCA in component environment (fmol)"
legend_rates[12] = "d/dt q_P6_SERCA in component environment (fmol)"
legend_rates[13] = "d/dt q_P8_SERCA in component environment (fmol)"
legend_rates[14] = "d/dt q_P9_SERCA in component environment (fmol)"
return (legend_states, legend_algebraic, legend_voi, legend_constants)
def initConsts():
constants = [0.0] * sizeConstants; states = [0.0] * sizeStates;
states[0] = 0.0057
states[1] = 2.28
states[2] = 0.004028
states[3] = 570
states[4] = 1.3794
states[5] = 3.8
states[6] = 0.11111
states[7] = 0.11111
states[8] = 0.11111
states[9] = 0.11111
states[10] = 0.11111
states[11] = 0.11111
states[12] = 0.11111
states[13] = 0.11111
states[14] = 0.11111
constants[0] = 4.028E+00
constants[1] = 4.028E+00
constants[2] = 6.91835e-08
constants[3] = 7.55655
constants[4] = 8506.72
constants[5] = 7.55655
constants[6] = 0.241033
constants[7] = 45.2524
constants[8] = 6662.34
constants[9] = 6662.34
constants[10] = 3.65954e-06
constants[11] = 45.8697
constants[12] = 2.31881
constants[13] = 0.242269
constants[14] = 272.733
constants[15] = 0.000838529
constants[16] = 228.515
constants[17] = 0.320649
constants[18] = 0.309339
constants[19] = 0.445746
constants[20] = 237.968
constants[21] = 0.313625
constants[22] = 5.22709
constants[23] = 17.0902
constants[24] = 2.55479e-06
constants[25] = 0.00185871
constants[26] = 93.2902
constants[27] = 8.31
constants[28] = 310
constants[29] = 96485
constants[30] = 2
constants[31] = 2
constants[32] = 2
constants[33] = 34.0
constants[34] = constants[33]*0.0350000
constants[35] = constants[27]*constants[28]*log(constants[26]*constants[0])
constants[36] = constants[33]+constants[34]
constants[37] = constants[27]*constants[28]*log(constants[26]*constants[1])
constants[38] = constants[35]-constants[37]
return (states, constants)
def computeRates(voi, states, constants):
rates = [0.0] * sizeStates; algebraic = [0.0] * sizeAlgebraic
algebraic[18] = constants[27]*constants[28]*log(constants[19]*states[11])
algebraic[23] = algebraic[18]+constants[38]
algebraic[13] = constants[27]*constants[28]*log(constants[11]*states[6])
algebraic[12] = constants[27]*constants[28]*log(constants[25]*states[3])
algebraic[24] = algebraic[13]+algebraic[12]+constants[38]
algebraic[41] = constants[10]*(exp(algebraic[23]/(constants[27]*constants[28]))-exp(algebraic[24]/(constants[27]*constants[28])))
algebraic[43] = algebraic[41]
rates[3] = algebraic[43]
algebraic[11] = constants[27]*constants[28]*log(constants[23]*states[5])
algebraic[25] = algebraic[13]+algebraic[11]+constants[38]
algebraic[14] = constants[27]*constants[28]*log(constants[12]*states[7])
algebraic[26] = algebraic[14]+constants[38]
algebraic[42] = constants[2]*(exp(algebraic[25]/(constants[27]*constants[28]))-exp(algebraic[26]/(constants[27]*constants[28])))
algebraic[45] = -algebraic[42]
rates[5] = algebraic[45]
algebraic[46] = algebraic[41]-algebraic[42]
rates[6] = algebraic[46]
algebraic[17] = constants[27]*constants[28]*log(constants[15]*states[10])
algebraic[27] = algebraic[17]+constants[38]
algebraic[10] = constants[27]*constants[28]*log(constants[24]*states[4])
algebraic[19] = constants[27]*constants[28]*log(constants[16]*states[12])
algebraic[28] = algebraic[10]+algebraic[19]+constants[38]
algebraic[44] = constants[6]*(exp(algebraic[27]/(constants[27]*constants[28]))-exp(algebraic[28]/(constants[27]*constants[28])))
algebraic[48] = algebraic[44]
rates[4] = algebraic[48]
algebraic[9] = constants[27]*constants[28]*log(constants[20]*states[2])
algebraic[29] = algebraic[14]+algebraic[9]+constants[38]
algebraic[15] = constants[27]*constants[28]*log(constants[13]*states[8])
algebraic[30] = algebraic[15]+constants[38]
algebraic[47] = constants[4]*(exp(algebraic[29]/(constants[27]*constants[28]))-exp(algebraic[30]/(constants[27]*constants[28])))
algebraic[50] = algebraic[47]
rates[8] = algebraic[50]
algebraic[7] = constants[27]*constants[28]*log(constants[21]*states[0])
algebraic[31] = algebraic[14]+constants[30]*algebraic[7]+constants[38]
algebraic[16] = constants[27]*constants[28]*log(constants[14]*states[9])
algebraic[32] = algebraic[16]+constants[38]
algebraic[49] = constants[3]*(exp(algebraic[31]/(constants[27]*constants[28]))-exp(algebraic[32]/(constants[27]*constants[28])))
algebraic[51] = -constants[30]*algebraic[49]
rates[0] = algebraic[51]
algebraic[53] = algebraic[42]-algebraic[49]
rates[7] = algebraic[53]
algebraic[33] = algebraic[16]+constants[38]
algebraic[34] = algebraic[17]+constants[32]*algebraic[9]+constants[38]
algebraic[52] = constants[5]*(exp(algebraic[33]/(constants[27]*constants[28]))-exp(algebraic[34]/(constants[27]*constants[28])))
algebraic[55] = algebraic[49]-algebraic[52]
rates[9] = algebraic[55]
algebraic[56] = algebraic[52]-algebraic[44]
rates[10] = algebraic[56]
algebraic[35] = algebraic[19]+constants[38]
algebraic[8] = constants[27]*constants[28]*log(constants[22]*states[1])
algebraic[21] = constants[27]*constants[28]*log(constants[17]*states[13])
algebraic[36] = algebraic[21]+constants[31]*algebraic[8]+constants[38]
algebraic[54] = constants[7]*(exp(algebraic[35]/(constants[27]*constants[28]))-exp(algebraic[36]/(constants[27]*constants[28])))
algebraic[57] = constants[31]*algebraic[54]
rates[1] = algebraic[57]
algebraic[59] = algebraic[44]-algebraic[54]
rates[12] = algebraic[59]
algebraic[37] = algebraic[21]+constants[32]*algebraic[9]+constants[38]
algebraic[22] = constants[27]*constants[28]*log(constants[18]*states[14])
algebraic[38] = algebraic[22]+constants[38]
algebraic[58] = constants[8]*(exp(algebraic[37]/(constants[27]*constants[28]))-exp(algebraic[38]/(constants[27]*constants[28])))
algebraic[61] = algebraic[54]-algebraic[58]
rates[13] = algebraic[61]
algebraic[39] = algebraic[22]+constants[38]
algebraic[40] = algebraic[9]+algebraic[18]+constants[38]
algebraic[60] = constants[9]*(exp(algebraic[39]/(constants[27]*constants[28]))-exp(algebraic[40]/(constants[27]*constants[28])))
algebraic[62] = ((constants[32]*algebraic[52]-algebraic[47])-constants[32]*algebraic[58])+algebraic[60]
rates[2] = algebraic[62]
algebraic[64] = algebraic[60]-algebraic[41]
rates[11] = algebraic[64]
algebraic[63] = algebraic[58]-algebraic[60]
rates[14] = algebraic[63]
return(rates)
def computeAlgebraic(constants, states, voi):
algebraic = array([[0.0] * len(voi)] * sizeAlgebraic)
states = array(states)
voi = array(voi)
algebraic[18] = constants[27]*constants[28]*log(constants[19]*states[11])
algebraic[23] = algebraic[18]+constants[38]
algebraic[13] = constants[27]*constants[28]*log(constants[11]*states[6])
algebraic[12] = constants[27]*constants[28]*log(constants[25]*states[3])
algebraic[24] = algebraic[13]+algebraic[12]+constants[38]
algebraic[41] = constants[10]*(exp(algebraic[23]/(constants[27]*constants[28]))-exp(algebraic[24]/(constants[27]*constants[28])))
algebraic[43] = algebraic[41]
algebraic[11] = constants[27]*constants[28]*log(constants[23]*states[5])
algebraic[25] = algebraic[13]+algebraic[11]+constants[38]
algebraic[14] = constants[27]*constants[28]*log(constants[12]*states[7])
algebraic[26] = algebraic[14]+constants[38]
algebraic[42] = constants[2]*(exp(algebraic[25]/(constants[27]*constants[28]))-exp(algebraic[26]/(constants[27]*constants[28])))
algebraic[45] = -algebraic[42]
algebraic[46] = algebraic[41]-algebraic[42]
algebraic[17] = constants[27]*constants[28]*log(constants[15]*states[10])
algebraic[27] = algebraic[17]+constants[38]
algebraic[10] = constants[27]*constants[28]*log(constants[24]*states[4])
algebraic[19] = constants[27]*constants[28]*log(constants[16]*states[12])
algebraic[28] = algebraic[10]+algebraic[19]+constants[38]
algebraic[44] = constants[6]*(exp(algebraic[27]/(constants[27]*constants[28]))-exp(algebraic[28]/(constants[27]*constants[28])))
algebraic[48] = algebraic[44]
algebraic[9] = constants[27]*constants[28]*log(constants[20]*states[2])
algebraic[29] = algebraic[14]+algebraic[9]+constants[38]
algebraic[15] = constants[27]*constants[28]*log(constants[13]*states[8])
algebraic[30] = algebraic[15]+constants[38]
algebraic[47] = constants[4]*(exp(algebraic[29]/(constants[27]*constants[28]))-exp(algebraic[30]/(constants[27]*constants[28])))
algebraic[50] = algebraic[47]
algebraic[7] = constants[27]*constants[28]*log(constants[21]*states[0])
algebraic[31] = algebraic[14]+constants[30]*algebraic[7]+constants[38]
algebraic[16] = constants[27]*constants[28]*log(constants[14]*states[9])
algebraic[32] = algebraic[16]+constants[38]
algebraic[49] = constants[3]*(exp(algebraic[31]/(constants[27]*constants[28]))-exp(algebraic[32]/(constants[27]*constants[28])))
algebraic[51] = -constants[30]*algebraic[49]
algebraic[53] = algebraic[42]-algebraic[49]
algebraic[33] = algebraic[16]+constants[38]
algebraic[34] = algebraic[17]+constants[32]*algebraic[9]+constants[38]
algebraic[52] = constants[5]*(exp(algebraic[33]/(constants[27]*constants[28]))-exp(algebraic[34]/(constants[27]*constants[28])))
algebraic[55] = algebraic[49]-algebraic[52]
algebraic[56] = algebraic[52]-algebraic[44]
algebraic[35] = algebraic[19]+constants[38]
algebraic[8] = constants[27]*constants[28]*log(constants[22]*states[1])
algebraic[21] = constants[27]*constants[28]*log(constants[17]*states[13])
algebraic[36] = algebraic[21]+constants[31]*algebraic[8]+constants[38]
algebraic[54] = constants[7]*(exp(algebraic[35]/(constants[27]*constants[28]))-exp(algebraic[36]/(constants[27]*constants[28])))
algebraic[57] = constants[31]*algebraic[54]
algebraic[59] = algebraic[44]-algebraic[54]
algebraic[37] = algebraic[21]+constants[32]*algebraic[9]+constants[38]
algebraic[22] = constants[27]*constants[28]*log(constants[18]*states[14])
algebraic[38] = algebraic[22]+constants[38]
algebraic[58] = constants[8]*(exp(algebraic[37]/(constants[27]*constants[28]))-exp(algebraic[38]/(constants[27]*constants[28])))
algebraic[61] = algebraic[54]-algebraic[58]
algebraic[39] = algebraic[22]+constants[38]
algebraic[40] = algebraic[9]+algebraic[18]+constants[38]
algebraic[60] = constants[9]*(exp(algebraic[39]/(constants[27]*constants[28]))-exp(algebraic[40]/(constants[27]*constants[28])))
algebraic[62] = ((constants[32]*algebraic[52]-algebraic[47])-constants[32]*algebraic[58])+algebraic[60]
algebraic[64] = algebraic[60]-algebraic[41]
algebraic[63] = algebraic[58]-algebraic[60]
algebraic[0] = constants[30]*states[9]+constants[30]*states[10]+constants[31]*states[12]
algebraic[1] = states[0]/constants[33]
algebraic[2] = states[1]/constants[34]
algebraic[3] = states[2]/constants[36]
algebraic[4] = states[4]/constants[33]
algebraic[5] = states[5]/constants[33]
algebraic[6] = states[3]/constants[33]
algebraic[20] = constants[10]*(exp(algebraic[18]/(constants[27]*constants[28]))-exp((algebraic[13]+algebraic[12])/(constants[27]*constants[28])))
return algebraic
def solve_model():
"""Solve model with ODE solver"""
from scipy.integrate import ode
# Initialise constants and state variables
(init_states, constants) = initConsts()
# Set timespan to solve over
voi = linspace(0, 10, 500)
# Construct ODE object to solve
r = ode(computeRates)
r.set_integrator('vode', method='bdf', atol=1e-06, rtol=1e-06, max_step=1)
r.set_initial_value(init_states, voi[0])
r.set_f_params(constants)
# Solve model
states = array([[0.0] * len(voi)] * sizeStates)
states[:,0] = init_states
for (i,t) in enumerate(voi[1:]):
if r.successful():
r.integrate(t)
states[:,i+1] = r.y
else:
break
# Compute algebraic variables
algebraic = computeAlgebraic(constants, states, voi)
return (voi, states, algebraic)
def plot_model(voi, states, algebraic):
"""Plot variables against variable of integration"""
import pylab
(legend_states, legend_algebraic, legend_voi, legend_constants) = createLegends()
pylab.figure(1)
pylab.plot(voi,vstack((states,algebraic)).T)
pylab.xlabel(legend_voi)
pylab.legend(legend_states + legend_algebraic, loc='best')
pylab.show()
if __name__ == "__main__":
(voi, states, algebraic) = solve_model()
plot_model(voi, states, algebraic)
