title: Adams Variable Step-Size Predictor-Corrector python
body: <p>I don't know to use initial values with Rk4 and use variable step size with h. My initial values is in q. My initial conditions are: a= 0, b= 12, y0=1, tol= 1e-5, hmax= 1,  and hmin= 0.1</p>
  <pre><code>def P_C_A1( m, a, b, y0, tol, hmax, hmin ): #m is a function
  
  i=3
  
  h = hmax   
  t = a +3*h
  T = np.array( [t] )
  
  
  q= rk4_4(m,y0,4,h)[1][:4].tolist()  #Initial values RK4
  k1= m(q[3],0+3*h)
  k2= m(q[2],0+2*h)
  k3= m(q[1],+h)
  k4= m(q[0],0)  
  while t and i&lt; b:
      
      if t + h &gt; b:
        h = b - t
                                                            
      y= q[i] 
      #Corrector  
      y= q[i] + h/24*( 55*m(q[i],t) -59*m(q[i-1],t-h)+ 37*m(q[i-2],t-2*h) -9*m(q[i-3],t-3*h))
        
      k0 = m(y, t+h)
      #Predictor    
      w = q[i] + h*(9*m(y, t+h)+19*m(q[i],t)-5*m(q[i-1],t-h)+m(q[i-2],t-2*h))/24
      
      r = (19/270*h)*abs( w-y )  # error
      
      if len( np.shape( r ) ) &gt; 0:
        r = max(r)
      if r &lt;= tol:
          
          t = t + h
          i= i +1
             
  
          
          
       
          q.append(w)
          
          T = np.append( T, t )
          
      z = (tol/(2*r))**0.25 #  
      
      if (z &lt;= 0.1):
        h = 0.1*h   # ( big error ) 0.1 is min value for z
      elif (z &gt;= 1):
        h = 1.*h    #1 is max value for z
      else:
        h = z*h     #scalar h a z*h, paso ideal ( 0.1 &lt; z &lt; 1)
      
      if   (h &gt; hmax): h = hmax  # Not allowed values greater hmax
      elif (h &lt; hmin): 
          print('(h not allowed.')
          break
      
  return ( T, q )
  
  k= 0.0009906
  def m(x,t):
    return k*x*(1000-x)
  P_C_A1( m, 0, 12, 0, 1e-5, 1,0.1 )
  </code></pre>
  <p>Ouput:
  h not allowed</p>
  <p>So How can I change h and use my range of values for h?. I probably have errors in my code but I don't see them.</p>