title: How to solve real life difference equations using python
body: <p>I want to solve a difference equation using python. </p>
  
  <p><code>y = x(n - 1) - (0.5(x(n-2) + x(n))</code></p>
  
  <p><code>x</code> here is a long array of values. I want to plot <code>y</code> with respect to another time sequence array <code>t</code> using <a href="https://plot.ly/" rel="nofollow noreferrer">Plotly</a>. I can plot <code>x</code> with <code>t</code>, but I am not able to generate the filtered signal <code>y</code>. I have tried the code below, but it seems I'm missing something. I am not getting the desired output. </p>
  
  <pre><code>from scipy import signal
  from plotly.offline import plot, iplot
  x = array(...)
  t = array(...) # x and t are big arrays 
  b = [-0.5, 1, -0.5]
  a = 0
  y = signal.lfilter(b, a, x, axis=-1, zi=None) 
  iplot([{"x": t, "y": y}])
  </code></pre>
  
  <p>However, the output is something like this.</p>
  
  <pre><code>&gt;&gt;&gt;y
  &gt;&gt;&gt; array([-inf, ...,  nan])
  </code></pre>
  
  <p>Therefore, I am getting a blank graph.</p>
  
  <p>UPDATE with examples of x and t (9 values each):</p>
  
  <pre><code>x = [3.1137561664814495,
   -1.4589810840917137,
   -0.12631870857936914,
   -1.2695030212226599,
   2.7600637824592158,
   -1.7810937909691049,
   0.050527483431747656,
   0.27158522344564368,
   0.48001109260160274]
  
  t = [0.0035589523041146265,
   0.011991765409288035,
   0.020505576424579175,
   0.028935389041247817,
   0.037447199517441021,
   0.045880011487565042,
   0.054462819797731044,
   0.062835632533346342,
   0.071347441874490158]
  </code></pre>