title: How to program a differential equation of form dy/dt = f(t,y) (i.e. time is in differential equation) in R?
body: <p>I am trying to simulate a model with this differential equation for concentration A: </p>
  
  <pre><code>dA/dt = (a-b)*exp^(d*(s-t))
  </code></pre>
  
  <p>(The equations has parameters: a, b, d, and s.) I can not figure out how to use R to solve differential equations that have a t (time step) variable? I tried it with the function radau of the package deSolve (See beneath). I did not get the code to work. I also do not understand how to define the index variable? Or if this is solvable with this function at all? (All my other simpler differential equations I have ran in the past with the ode function of deSolve, worked fine). </p>
  
  <p>I hope you can help me!</p>
  
  <p><strong>My try:</strong> </p>
  
  <pre><code>#Defining parameters
  parameter &lt;- c(a=0.03, b=0.02, d=0.01, s=179)
  
  #Defining Function
  Function1 &lt;- function(t, y, parameter) { with (as.list(Y),
  list(c(dA = (a-b)*exp^(d*(s-t)))))}
  
  #Initial conditions
  yini &lt;- c(A=1)
  
  #Mass matrix
  M &lt;- diag(nrow=1)
  M[5,5] &lt;- 0
  M
  
  #index/times/output
  index &lt;- c(1)
  times &lt;- seq(from = 0, to = 10, by = 0.01)
  out &lt;- radau(y = yini, func = Function1, parms = parameters, times = times, mass = M, nind = index)
  plot(out, type = "l", lwd = 2)
  </code></pre>