[R] attempt to apply non-function

Berend Hasselman bhh at xs4all.nl
Mon Feb 18 16:02:40 CET 2013


On 18-02-2013, at 15:19, Jannetta Steyn <jannetta at henning.org> wrote:

> Hi All
> 
> I am getting the above mentioned error when I run the code below. I don't
> know why because I have implemented the function and I'm calling the
> function with a parameter. I'm obviously missing the plot ... Can someone
> perhaps point out the error of my ways?
> 
> Error:
>> out<-ode(y=init, times=times, func=G1999, parms=parms, method="lsoda")
> Error in m_Na(v) : attempt to apply non-function
> 
> Code:
> library(deSolve)
> G1999 <-  function(time, init, parms) {
>  with(as.list(c(init, parms)),{
> 
>    m_Na <- function(v) 1 / (1 + 15 * exp(-0.769 * (v+34)) * ((1 -
> exp(-0.05(v+6)/0.11 * v + 0.66))))
> 
>    dv <- I_ext - (
>      + g_Na * (m_Na(v))^3 * h_Na * (E_Na - v)
>      + ((g_CaT * m_CaT * h_CaT) + (g_CaS * m_CaS)) * (E_Ca - v)
>      + (g_K * m_K^4) * (E_K - v)
>      + (g_KCa * m_KCa * h_KCa * (E_K - v))
>      + (g_Af * h_Af + g_As * h_As) * m_A^3 * (E_K - v)
>      + (g_L * (E_L - v)))
> 
>    dh_Na <- k_h * (0.08 * (1 - h_Na) * exp(-0.125 * (v + 39)) - h_Na / (1
> + exp(-(0.2 * (2 + 8)))))
> 
>    dm_Ca <- -C_Ca * (g_CaT * m_CaT * h_CaT + g_CaS * m_CaS) * (v - E_Ca) +
> k_Ca * (0.05 - m_Ca)
>    dm_CaT <- 50 * 1 / (1 + exp(-0.143 * (v + 11))) - 50 * m_CaT
>    dm_CaS <- 10 * 1 / (1 + exp(-0.143) * (v - 22)) - 50 * m_CaS
>    dh_CaT <- 16 * 1 / (1 + exp(0.125) * (v + 50)) - 16 * h_CaT
> 
>    dm_K <- (180 * 1/(1 + exp(-0.0588 * (v + 25))) * (180 * m_K)) / (1 +
> exp(-0.0455 * (v - 10)))
> 
>    dm_KCa <- k_KCa * (m_Ca/(1+exp(-(0.0435 * v + 0.026 * m_Ca)) * (1 +
> exp(-(0.2 * v + 3.2 + 0.12 * m_Ca))) * (2.5 + m_Ca)) - m_KCa)
>    dh_KCa <- (21 / (0.6 + m_Ca)) - (35 * h_KCa)
> 
>    dm_A <- 40 / (1+exp(-(0.0667 * (v - vA)))-140 * m_A)
>    dh_Af <- k_Af * (1 / ((1 + exp(0.167 * (v + 31))))) - h_Af
>    dh_As <- k_As * (1 / ((1 + exp(0.167 * (v + 31))))) - h_As
> 
> 
>    list(c())
>  })
> }
> 
> times<-seq(from=1, to=100, by=0.1)
> parms<-c(I_ext=6.5,
>         g_Af=0.7, g_As=1.2, g_K=0.42, g_KCa=5.9, g_CaT=0.21, g_CaS=0.047,
> g_L=0.1, g_Na=2300,
>         E_K=-86, E_L=-50, E_Ca=40, E_Na=50,
>         vA=-43,
>         k_KCa=600, C_Ca = 300, k_Ca=360, k_Af=45, k_As=10, k_h=500,
> C_m=0.0017)
> init<-c(v=-50, h_Na=0.52, m_Ca=0.52, m_CaT=0.52, m_CaS=0.52, h_CaT=0.52,
> m_K=0.52, m_KCa=0.52, h_KCa=0.52,
>        m_A=0.52, h_Af=0.52, h_As=0.52)
> out<-ode(y=init, times=times, func=G1999, parms=parms, method="lsoda")
> 

There is a missing multiply * in the second line

   m_Na <- function(v) 1 / (1 + 15 * exp(-0.769 * (v+34)) * ((1 -
exp(-0.05(v+6)/0.11 * v + 0.66))))

Because you don't have a * between 0.05 and (v+6) in the second exp()
you are applying a non function.
Write

   m_Na <- function(v) 1 / (1 + 15 * exp(-0.769 * (v+34)) * ((1 -
exp(-0.05*(v+6)/0.11 * v + 0.66))))

Berend



More information about the R-help mailing list