Trying to interpolate linearly in python
<p>I have 3 arrays: a, b, c all with length 15. </p>

<pre><code>a=[950, 850, 750, 675, 600, 525, 460, 400, 350, 300, 250, 225, 200, 175, 150] 

b = [16, 12, 9, -35, -40, -40, -40, -45, -50, -55, -60, -65, -70, -75, -80]

c=[32.0, 22.2, 12.399999999999999, 2.599999999999998, -7.200000000000003, -17.0, -26.800000000000004, -36.60000000000001, -46.400000000000006, -56.2, -66.0, -75.80000000000001, -85.60000000000001, -95.4, -105.20000000000002] 
</code></pre>

<p>I am trying to find the value of a  at the index where b=c. T</p>

<p>The problem is that there is no place where b=c exactly so I need to linearly interpolate between values in the array to find the value of a where b=c. Does that make sense? </p>

<p>I was thinking about using <strong>scipy.interpolate</strong> to do the interpolation. </p>

<p>I am having a hard time wrappying my mind around how to solve this problem. Any ideas on this would be great!</p>

<p>Here's simpler variation of a function from <a href="http://stackoverflow.com/questions/15112964/digitizing-an-analog-signal/15114952#15114952">another answer of mine</a>:</p>

<pre><code>from __future__ import division

import numpy as np


def find_roots(t, y):
    """
    Given the input signal `y` with samples at times `t`,
    find the times where `y` is 0.

    `t` and `y` must be 1-D numpy arrays.

    Linear interpolation is used to estimate the time `t` between
    samples at which sign changes in `y` occur.
    """
    # Find where y crosses 0.
    transition_indices = np.where(np.sign(y[1:]) != np.sign(y[:-1]))[0]

    # Linearly interpolate the time values where the transition occurs.
    t0 = t[transition_indices]
    t1 = t[transition_indices + 1]
    y0 = y[transition_indices]
    y1 = y[transition_indices + 1]
    slope = (y1 - y0) / (t1 - t0)
    transition_times = t0 - y0/slope

    return transition_times
</code></pre>

<p>That function can be used with <code>t = a</code> and <code>y = b - c</code>. For example, here is your data, entered as numpy arrays:</p>

<pre><code>In [354]: a = np.array([950, 850, 750, 675, 600, 525, 460, 400, 350, 300, 250, 225, 200, 175, 150])

In [355]: b = np.array([16, 12, 9, -35, -40, -40, -40, -45, -50, -55, -60, -65, -70, -75, -80])

In [356]: c = np.array([32.0, 22.2, 12.399999999999999, 2.599999999999998, -7.200000000000003, -17.0, -26.800000000000004, -3
     ...: 6.60000000000001, -46.400000000000006, -56.2, -66.0, -75.80000000000001, -85.60000000000001, -95.4, -105.2000000000
     ...: 0002])
</code></pre>

<p>The place where "b = c" is the place where "b - c = 0", so we pass <code>b - c</code> for <code>y</code>:</p>

<pre><code>In [357]: find_roots(a, b - c)
Out[357]: array([ 312.5])
</code></pre>

<p>So the linearly interpolated value of <code>a</code> is 312.5.</p>

<p>With the following matplotlib commands:</p>

<pre><code>In [391]: plot(a, b, label="b")
Out[391]: [&lt;matplotlib.lines.Line2D at 0x11eac8780&gt;]

In [392]: plot(a, c, label="c")
Out[392]: [&lt;matplotlib.lines.Line2D at 0x11f23aef0&gt;]

In [393]: roots = find_roots(a, b - c)

In [394]: [axvline(root, color='k', alpha=0.2) for root in roots]
Out[394]: [&lt;matplotlib.lines.Line2D at 0x11f258208&gt;]

In [395]: grid()

In [396]: legend(loc="best")
Out[396]: &lt;matplotlib.legend.Legend at 0x11f260ba8&gt;

In [397]: xlabel("a")
Out[397]: &lt;matplotlib.text.Text at 0x11e71c470&gt;
</code></pre>

<p>I get the plot</p>

<p><a href="http://i.stack.imgur.com/JQzo3.png" rel="nofollow"><img src="http://i.stack.imgur.com/JQzo3.png" alt="plot"></a></p>

python scipy interpolation