
#
# This file is automatically generated with 
# the System Biology Format Converter (http://sbfc.sourceforge.net/)
# from an SBML file.
#
# The conversion system has the following limitations:
#  - You may have to re order some reactions and Assignment Rules definition
#  - Delays are not taken into account
#  - You should change the lsode parameters (start, end, steps) to get better results
#

#
# The following line is there to be sure that Octave think that this file 
# is a script and not function file
#
1;

#
# Model name = Hinch2004_VentricularMyocytes
#
# is urn:miriam:biomodels.db:MODEL0848342500
# isDescribedBy urn:miriam:pubmed:15465866
#
function z=pow(x,y),z=x^y;endfunction
function z=root(x,y),z=y^(1/x);endfunction
function z = piecewise(varargin)
	numArgs = nargin;
	result = 0;
	foundResult = 0;
	for k=1:2: numArgs-1
		if varargin{k+1} == 1
			result = varargin{k};
			foundResult = 1;
			break;
		endif
	end
	if foundResult == 0
		result = varargin{numArgs};
	endif
z = result;
endfunction

function xdot=f(x,t)
# Compartment: id = Compartment, name = Compartment, constant
	compartment_Compartment=1.0;
# Parameter:   id =  V_myo_cell_geometry, name = V_myo
	global_par_V_myo_cell_geometry=25840.0;
# Parameter:   id =  V_SR, name = V_SR
	global_par_V_SR=2098.0;
# Parameter:   id =  A_cap, name = A_cap
	global_par_A_cap=15340.0;
# Parameter:   id =  V_membrane, name = V
# Parameter:   id =  R, name = R
	global_par_R=8314.5;
# Parameter:   id =  T, name = T
	global_par_T=295.0;
# Parameter:   id =  F, name = F
	global_par_F=96487.0;
# Parameter:   id =  FVRT, name = FVRT
# Parameter:   id =  FVRT_Ca_membrane, name = FVRT_Ca
# Parameter:   id =  g_D, name = g_D
	global_par_g_D=0.065;
# Parameter:   id =  J_R, name = J_R
	global_par_J_R=0.02;
# Parameter:   id =  J_L, name = J_L
	global_par_J_L=9.13E-4;
# Parameter:   id =  N, name = N
	global_par_N=50000.0;
# Parameter:   id =  V_CaRU_Transitions, name = V
	global_par_V_CaRU_Transitions=NaN;
# Parameter:   id =  Ca_i_CaRU_Transitions, name = Ca_i
	global_par_Ca_i_CaRU_Transitions=NaN;
# Parameter:   id =  V_L, name = V_L
	global_par_V_L=-2.0;
# Parameter:   id =  del_VL, name = del_VL
	global_par_del_VL=7.0;
# Parameter:   id =  phi_L, name = phi_L
	global_par_phi_L=2.35;
# Parameter:   id =  t_L, name = t_L
	global_par_t_L=1.0;
# Parameter:   id =  tau_L, name = tau_L
	global_par_tau_L=650.0;
# Parameter:   id =  t_R, name = t_R
# Parameter:   id =  tau_R, name = tau_R
	global_par_tau_R=2.43;
# Parameter:   id =  phi_R, name = phi_R
	global_par_phi_R=0.05;
# Parameter:   id =  theta_R, name = theta_R
	global_par_theta_R=0.012;
# Parameter:   id =  K_RyR, name = K_RyR
	global_par_K_RyR=0.041;
# Parameter:   id =  K_L, name = K_L
	global_par_K_L=2.2E-4;
# Parameter:   id =  a, name = a
	global_par_a=0.0625;
# Parameter:   id =  b, name = b
	global_par_b=14.0;
# Parameter:   id =  c, name = c
	global_par_c=0.01;
# Parameter:   id =  d, name = d
	global_par_d=100.0;
# Parameter:   id =  expVL, name = expVL
# Parameter:   id =  alpha_p, name = alpha_p
# Parameter:   id =  alpha_m, name = alpha_m
# Parameter:   id =  beta_poc, name = beta_poc
# Parameter:   id =  beta_pcc, name = beta_pcc
# Parameter:   id =  beta_m, name = beta_m
# Parameter:   id =  epsilon_pco, name = epsilon_pco
# Parameter:   id =  epsilon_pcc, name = epsilon_pcc
# Parameter:   id =  epsilon_m, name = epsilon_m
# Parameter:   id =  mu_poc, name = mu_poc
# Parameter:   id =  mu_pcc, name = mu_pcc
# Parameter:   id =  mu_moc, name = mu_moc
# Parameter:   id =  mu_mcc, name = mu_mcc
# Parameter:   id =  Ca_i_DS_Calcium_Concentrations, name = Ca_i
	global_par_Ca_i_DS_Calcium_Concentrations=NaN;
# Parameter:   id =  Ca_SR_DS_Calcium_Concentrations, name = Ca_SR
	global_par_Ca_SR_DS_Calcium_Concentrations=NaN;
# Parameter:   id =  Ca_o_DS_Calcium_Concentrations, name = Ca_o
	global_par_Ca_o_DS_Calcium_Concentrations=NaN;
# Parameter:   id =  FVRT_Ca_DS_Calcium_Concentrations, name = FVRT_Ca
	global_par_FVRT_Ca_DS_Calcium_Concentrations=NaN;
# Parameter:   id =  C_cc, name = C_cc
# Parameter:   id =  C_oc, name = C_oc
# Parameter:   id =  C_co, name = C_co
# Parameter:   id =  C_oo, name = C_oo
# Parameter:   id =  Ca_i_LCC_and_RyR_fluxes, name = Ca_i
	global_par_Ca_i_LCC_and_RyR_fluxes=NaN;
# Parameter:   id =  Ca_SR_LCC_and_RyR_fluxes, name = Ca_SR
	global_par_Ca_SR_LCC_and_RyR_fluxes=NaN;
# Parameter:   id =  Ca_o_LCC_and_RyR_fluxes, name = Ca_o
	global_par_Ca_o_LCC_and_RyR_fluxes=NaN;
# Parameter:   id =  FVRT_Ca_LCC_and_RyR_fluxes, name = FVRT_Ca
	global_par_FVRT_Ca_LCC_and_RyR_fluxes=NaN;
# Parameter:   id =  J_Loo, name = J_Loo
# Parameter:   id =  J_Loc, name = J_Loc
# Parameter:   id =  J_Rco, name = J_Rco
# Parameter:   id =  J_Roo, name = J_Roo
# Parameter:   id =  denom, name = denom
# Parameter:   id =  y_oc, name = y_oc
# Parameter:   id =  y_co, name = y_co
# Parameter:   id =  y_oo, name = y_oo
# Parameter:   id =  y_cc, name = y_cc
# Parameter:   id =  y_ci, name = y_ci
# Parameter:   id =  y_oi, name = y_oi
# Parameter:   id =  y_ic, name = y_ic
# Parameter:   id =  y_io, name = y_io
# Parameter:   id =  y_ii, name = y_ii
# Parameter:   id =  r_1, name = r_1
# Parameter:   id =  r_2, name = r_2
# Parameter:   id =  r_3, name = r_3
# Parameter:   id =  r_4, name = r_4
# Parameter:   id =  r_5, name = r_5
# Parameter:   id =  r_6, name = r_6
# Parameter:   id =  r_7, name = r_7
# Parameter:   id =  r_8, name = r_8
# Parameter:   id =  z_1, name = z_1
# Parameter:   id =  z_2, name = z_2
# Parameter:   id =  z_3, name = z_3
# Parameter:   id =  z_4, name = z_4
# Parameter:   id =  time_CaRU_reduced_states, name = time
	global_par_time_CaRU_reduced_states=NaN;
# Parameter:   id =  V_myo_RyR_current, name = V_myo
	global_par_V_myo_RyR_current=NaN;
# Parameter:   id =  J_R1, name = J_R1
# Parameter:   id =  J_R3, name = J_R3
# Parameter:   id =  I_RyR, name = I_RyR
# Parameter:   id =  V_myo_LCC_current, name = V_myo
	global_par_V_myo_LCC_current=NaN;
# Parameter:   id =  J_L1, name = J_L1
# Parameter:   id =  J_L2, name = J_L2
# Parameter:   id =  I_LCC, name = I_LCC
# Parameter:   id =  K_mNa, name = K_mNa
	global_par_K_mNa=87.5;
# Parameter:   id =  K_mCa, name = K_mCa
	global_par_K_mCa=1.38;
# Parameter:   id =  eta, name = eta
	global_par_eta=0.35;
# Parameter:   id =  k_sat, name = k_sat
	global_par_k_sat=0.1;
# Parameter:   id =  g_NCX, name = g_NCX
	global_par_g_NCX=0.0385;
# Parameter:   id =  I_NaCa, name = I_NaCa
# Parameter:   id =  g_SERCA, name = g_SERCA
	global_par_g_SERCA=4.5E-4;
# Parameter:   id =  K_SERCA, name = K_SERCA
	global_par_K_SERCA=5.0E-4;
# Parameter:   id =  I_SERCA, name = I_SERCA
# Parameter:   id =  g_pCa, name = g_pCa
	global_par_g_pCa=3.5E-6;
# Parameter:   id =  K_mpCa, name = K_mpCa
	global_par_K_mpCa=5.0E-4;
# Parameter:   id =  I_pCa, name = I_pCa
# Parameter:   id =  E_Ca, name = E_Ca
# Parameter:   id =  g_CaB, name = g_CaB
	global_par_g_CaB=2.6875E-8;
# Parameter:   id =  I_CaB, name = I_CaB
# Parameter:   id =  g_SRl, name = g_SRl
	global_par_g_SRl=1.8951E-5;
# Parameter:   id =  I_SR, name = I_SR
# Parameter:   id =  k_m_TRPN, name = k_m_TRPN
	global_par_k_m_TRPN=0.04;
# Parameter:   id =  k_p_TRPN, name = k_p_TRPN
	global_par_k_p_TRPN=40.0;
# Parameter:   id =  B_TRPN, name = B_TRPN
	global_par_B_TRPN=0.07;
# Parameter:   id =  I_TRPN, name = I_TRPN
# Parameter:   id =  k_CMDN, name = k_CMDN
	global_par_k_CMDN=0.002382;
# Parameter:   id =  B_CMDN, name = B_CMDN
	global_par_B_CMDN=0.05;
# Parameter:   id =  beta_CMDN, name = beta_CMDN
# Parameter:   id =  Na_i, name = Na_i
	global_par_Na_i=10.0;
# Parameter:   id =  Ca_i_intracellular_ion_concentrations, name = Ca_i
# Parameter:   id =  Ca_SR_intracellular_ion_concentrations, name = Ca_SR
# Parameter:   id =  TRPN, name = TRPN
# Parameter:   id =  CaSR_plot, name = CaSR_plot
# Parameter:   id =  Na_o, name = Na_o
	global_par_Na_o=140.0;
# Parameter:   id =  Ca_o_extracellular_ion_concentrations, name = Ca_o
	global_par_Ca_o_extracellular_ion_concentrations=1.0;
# rateRule: variable = z_1
global_par_z_1 = x(1);
# rateRule: variable = z_2
global_par_z_2 = x(2);
# rateRule: variable = z_3
global_par_z_3 = x(3);
# rateRule: variable = TRPN
global_par_TRPN = x(4);
# rateRule: variable = Ca_i_intracellular_ion_concentrations
global_par_Ca_i_intracellular_ion_concentrations = x(5);
# rateRule: variable = Ca_SR_intracellular_ion_concentrations
global_par_Ca_SR_intracellular_ion_concentrations = x(6);
# assignmentRule: variable = FVRT
	global_par_FVRT=global_par_F*global_par_V_membrane/(global_par_R*global_par_T);
# assignmentRule: variable = FVRT_Ca_membrane
	global_par_FVRT_Ca_membrane=2*global_par_FVRT;
# assignmentRule: variable = V_membrane
	global_par_V_membrane=piecewise(0, (time >= 0) and (time <= 200), -80);
# assignmentRule: variable = expVL
	global_par_expVL=exp((global_par_V_CaRU_Transitions-global_par_V_L)/global_par_del_VL);
# assignmentRule: variable = t_R
	global_par_t_R=1.17*global_par_t_L;
# assignmentRule: variable = alpha_p
	global_par_alpha_p=global_par_expVL/(global_par_t_L*(global_par_expVL+1));
# assignmentRule: variable = alpha_m
	global_par_alpha_m=global_par_phi_L/global_par_t_L;
# assignmentRule: variable = beta_poc
	global_par_beta_poc=global_par_C_oc^2/(global_par_t_R*(global_par_C_oc^2+global_par_K_RyR^2));
# assignmentRule: variable = beta_pcc
	global_par_beta_pcc=global_par_Ca_i_CaRU_Transitions^2/(global_par_t_R*(global_par_Ca_i_CaRU_Transitions^2+global_par_K_RyR^2));
# assignmentRule: variable = beta_m
	global_par_beta_m=global_par_phi_R/global_par_t_R;
# assignmentRule: variable = epsilon_pco
	global_par_epsilon_pco=global_par_C_co*(global_par_expVL+global_par_a)/(global_par_tau_L*global_par_K_L*(global_par_expVL+1));
# assignmentRule: variable = epsilon_pcc
	global_par_epsilon_pcc=global_par_Ca_i_CaRU_Transitions*(global_par_expVL+global_par_a)/(global_par_tau_L*global_par_K_L*(global_par_expVL+1));
# assignmentRule: variable = epsilon_m
	global_par_epsilon_m=global_par_b*(global_par_expVL+global_par_a)/(global_par_tau_L*(global_par_b*global_par_expVL+global_par_a));
# assignmentRule: variable = mu_poc
	global_par_mu_poc=(global_par_C_oc^2+global_par_c*global_par_K_RyR^2)/(global_par_tau_R*(global_par_C_oc^2+global_par_K_RyR^2));
# assignmentRule: variable = mu_pcc
	global_par_mu_pcc=(global_par_Ca_i_CaRU_Transitions^2+global_par_c*global_par_K_RyR^2)/(global_par_tau_R*(global_par_Ca_i_CaRU_Transitions^2+global_par_K_RyR^2));
# assignmentRule: variable = mu_moc
	global_par_mu_moc=global_par_theta_R*global_par_d*(global_par_C_oc^2+global_par_c*global_par_K_RyR^2)/(global_par_tau_R*(global_par_d*global_par_C_oc^2+global_par_c*global_par_K_RyR^2));
# assignmentRule: variable = mu_mcc
	global_par_mu_mcc=global_par_theta_R*global_par_d*(global_par_Ca_i_CaRU_Transitions^2+global_par_c*global_par_K_RyR^2)/(global_par_tau_R*(global_par_d*global_par_Ca_i_CaRU_Transitions^2+global_par_c*global_par_K_RyR^2));
# assignmentRule: variable = C_cc
	global_par_C_cc=global_par_Ca_i_DS_Calcium_Concentrations;
# assignmentRule: variable = C_co
	global_par_C_co=(global_par_Ca_i_DS_Calcium_Concentrations+global_par_J_R/global_par_g_D*global_par_Ca_SR_DS_Calcium_Concentrations)/(1+global_par_J_R/global_par_g_D);
# assignmentRule: variable = J_Rco
	global_par_J_Rco=global_par_J_R*(global_par_Ca_SR_LCC_and_RyR_fluxes-global_par_Ca_i_LCC_and_RyR_fluxes)/(1+global_par_J_R/global_par_g_D);
# assignmentRule: variable = denom
	global_par_denom=(global_par_alpha_p+global_par_alpha_m)*((global_par_alpha_m+global_par_beta_m+global_par_beta_poc)*(global_par_beta_m+global_par_beta_pcc)+global_par_alpha_p*(global_par_beta_m+global_par_beta_poc));
# assignmentRule: variable = y_oc
	global_par_y_oc=global_par_alpha_p*global_par_beta_m*(global_par_alpha_p+global_par_alpha_m+global_par_beta_m+global_par_beta_pcc)/global_par_denom;
# assignmentRule: variable = y_co
	global_par_y_co=global_par_alpha_m*(global_par_beta_pcc*(global_par_alpha_m+global_par_beta_m+global_par_beta_poc)+global_par_beta_poc*global_par_alpha_p)/global_par_denom;
# assignmentRule: variable = y_oo
	global_par_y_oo=global_par_alpha_p*(global_par_beta_poc*(global_par_alpha_p+global_par_beta_m+global_par_beta_pcc)+global_par_beta_pcc*global_par_alpha_m)/global_par_denom;
# assignmentRule: variable = y_cc
	global_par_y_cc=global_par_alpha_m*global_par_beta_m*(global_par_alpha_m+global_par_alpha_p+global_par_beta_m+global_par_beta_poc)/global_par_denom;
# assignmentRule: variable = y_ci
	global_par_y_ci=global_par_alpha_m/(global_par_alpha_p+global_par_alpha_m);
# assignmentRule: variable = y_oi
	global_par_y_oi=global_par_alpha_p/(global_par_alpha_p+global_par_alpha_m);
# assignmentRule: variable = y_ic
	global_par_y_ic=global_par_beta_m/(global_par_beta_pcc+global_par_beta_m);
# assignmentRule: variable = y_io
	global_par_y_io=global_par_beta_pcc/(global_par_beta_pcc+global_par_beta_m);
# assignmentRule: variable = y_ii
	global_par_y_ii=1-global_par_y_oc-global_par_y_co-global_par_y_oo-global_par_y_cc-global_par_y_ci-global_par_y_ic-global_par_y_oi-global_par_y_io;
# assignmentRule: variable = r_1
	global_par_r_1=global_par_y_oc*global_par_mu_poc+global_par_y_cc*global_par_mu_pcc;
# assignmentRule: variable = r_2
	global_par_r_2=(global_par_alpha_p*global_par_mu_moc+global_par_alpha_m*global_par_mu_mcc)/(global_par_alpha_p+global_par_alpha_m);
# assignmentRule: variable = r_3
	global_par_r_3=global_par_beta_m*global_par_mu_pcc/(global_par_beta_m+global_par_beta_pcc);
# assignmentRule: variable = r_4
	global_par_r_4=global_par_mu_mcc;
# assignmentRule: variable = r_5
	global_par_r_5=global_par_y_co*global_par_epsilon_pco+global_par_y_cc*global_par_epsilon_pcc;
# assignmentRule: variable = r_6
	global_par_r_6=global_par_epsilon_m;
# assignmentRule: variable = r_7
	global_par_r_7=global_par_alpha_m*global_par_epsilon_pcc/(global_par_alpha_p+global_par_alpha_m);
# assignmentRule: variable = r_8
	global_par_r_8=global_par_epsilon_m;
# assignmentRule: variable = z_4
	global_par_z_4=1-global_par_z_1-global_par_z_2-global_par_z_3;
# assignmentRule: variable = J_R1
	global_par_J_R1=global_par_y_oo*global_par_J_Roo+global_par_J_Rco*global_par_y_co;
# assignmentRule: variable = J_R3
	global_par_J_R3=global_par_J_Rco*global_par_beta_pcc/(global_par_beta_m+global_par_beta_pcc);
# assignmentRule: variable = I_RyR
	global_par_I_RyR=(global_par_z_1*global_par_J_R1+global_par_z_3*global_par_J_R3)*global_par_N/global_par_V_myo_RyR_current;
# assignmentRule: variable = J_L1
	global_par_J_L1=global_par_J_Loo*global_par_y_oo+global_par_J_Loc*global_par_y_oc;
# assignmentRule: variable = J_L2
	global_par_J_L2=global_par_J_Loc*global_par_alpha_p/(global_par_alpha_p+global_par_alpha_m);
# assignmentRule: variable = I_LCC
	global_par_I_LCC=(global_par_z_1*global_par_J_L1+global_par_z_2*global_par_J_L2)*global_par_N/global_par_V_myo_LCC_current;
# assignmentRule: variable = I_NaCa
	global_par_I_NaCa=global_par_g_NCX*(exp(global_par_eta*global_par_FVRT)*global_par_Na_i^3*global_par_Ca_o_extracellular_ion_concentrations-exp((global_par_eta-1)*global_par_FVRT)*global_par_Na_o^3*global_par_Ca_i_intracellular_ion_concentrations)/((global_par_Na_o^3+global_par_K_mNa^3)*(global_par_Ca_o_extracellular_ion_concentrations+global_par_K_mCa)*(1+global_par_k_sat*exp((global_par_eta-1)*global_par_FVRT)));
# assignmentRule: variable = I_SERCA
	global_par_I_SERCA=global_par_g_SERCA*global_par_Ca_i_intracellular_ion_concentrations^2/(global_par_K_SERCA^2+global_par_Ca_i_intracellular_ion_concentrations^2);
# assignmentRule: variable = I_pCa
	global_par_I_pCa=global_par_g_pCa*global_par_Ca_i_intracellular_ion_concentrations/(global_par_K_mpCa+global_par_Ca_i_intracellular_ion_concentrations);
# assignmentRule: variable = E_Ca
	global_par_E_Ca=global_par_R*global_par_T/(2*global_par_F)*log(global_par_Ca_o_extracellular_ion_concentrations/global_par_Ca_i_intracellular_ion_concentrations);
# assignmentRule: variable = I_CaB
	global_par_I_CaB=global_par_g_CaB*(global_par_E_Ca-global_par_V_membrane);
# assignmentRule: variable = I_SR
	global_par_I_SR=global_par_g_SRl*(global_par_Ca_SR_intracellular_ion_concentrations-global_par_Ca_i_intracellular_ion_concentrations);
# assignmentRule: variable = I_TRPN
	global_par_I_TRPN=global_par_k_m_TRPN*(global_par_B_TRPN-global_par_TRPN)-global_par_k_p_TRPN*global_par_TRPN*global_par_Ca_i_intracellular_ion_concentrations;
# assignmentRule: variable = beta_CMDN
	global_par_beta_CMDN=(1+global_par_k_CMDN*global_par_B_CMDN/(global_par_k_CMDN+global_par_Ca_i_intracellular_ion_concentrations)^2)^(-1);
# assignmentRule: variable = CaSR_plot
	global_par_CaSR_plot=global_par_Ca_SR_intracellular_ion_concentrations*global_par_V_SR/global_par_V_myo_cell_geometry;
	xdot=zeros(6,1);
	# rateRule: variable = z_1
	xdot(1) = (-(global_par_r_1+global_par_r_5))*global_par_z_1+global_par_r_2*global_par_z_2+global_par_r_6*global_par_z_3;

	# rateRule: variable = z_2
	xdot(2) = global_par_r_1*global_par_z_1-(global_par_r_2+global_par_r_7)*global_par_z_2+global_par_r_8*global_par_z_4;

	# rateRule: variable = z_3
	xdot(3) = global_par_r_5*global_par_z_1-(global_par_r_6+global_par_r_3)*global_par_z_3+global_par_r_4*global_par_z_4;

	# rateRule: variable = TRPN
	xdot(4) = global_par_I_TRPN;

	# rateRule: variable = Ca_i_intracellular_ion_concentrations
	xdot(5) = global_par_beta_CMDN*(global_par_I_LCC+global_par_I_RyR-global_par_I_SERCA+global_par_I_SR+global_par_I_NaCa-global_par_I_pCa+global_par_I_CaB+global_par_I_TRPN);

	# rateRule: variable = Ca_SR_intracellular_ion_concentrations
	xdot(6) = global_par_V_myo_cell_geometry/global_par_V_SR*(-global_par_I_RyR+global_par_I_SERCA-global_par_I_SR);

endfunction

#Initial conditions vector
x0=zeros(6,1);
x0(1) = 0.98859;
x0(2) = 0.0087302;
x0(3) = 0.0026566;
x0(4) = 0.0636364;
x0(5) = 1.0E-4;
x0(6) = 0.7;


#Creating linespace
t=linspace(0,90,100);

#Solving equations
x=lsode("f",x0,t);

#ploting the results
plot(t,x);
