# Finding coefficients of a function, given a list of points on the function

Given $f(x) = ax^n + bx^{n-1} + ... + cx + d$, a list of points, and a specification of a tangent line (point $p_t$ and equation) find $a, b, ..., c, d$ s.t.

1. $f(x)$ passes through each point
2. the tangent line to $f(x)$ at $p_t$ satisfies the given equation

Now I know how to find a tangent line at a point on a function. What I'm less sure of is how to find the coefficients (and this is definitely not a linear regression problem).

This is a calculus I test question for which I don't have a specific example, and don't seem to know the magic google words to find one... In the actual case, I doubt this will be more than cubic in $x$, since this is a no-calculator test situation, but I'd still like to know the approach for arbitrary $n$

For the sake of argument, lets say the example polynomial is $ax^3 + bx^2 + cx + d$

• That's not enough to solve the problem, and in fact that will be the output - you don't really get to specify the polynomial degree. The input should be a list of points and a derivative somewhere, right? Commented Jun 17, 2015 at 15:57
• That's true--but since I don't have a solvable example myself, I'm leery of making one up. I definitely don't have the chops to evaluate whether the givens I make up are going to resolve to a list of coefficients. By all means, feel free to edit the question with an example.
– Ben
Commented Jun 17, 2015 at 16:12
• FYI, they are all solvable -- the art of example choosing is in making the answer come out numerically nice as well. I didn't do that, so the answer below has some not so nice fractions in it. Commented Jun 17, 2015 at 16:28

The big trick in polynomial interpolation problems uses the function:

$$g(x)=(x-x_1)(x-x_2)\dots(x-x_n)$$

Note that this function is zero at each $x_n$ (and nowhere else). Also, $g'(x)=\sum_{i=1}^n \frac{g(x)}{x-x_i}$ (where the division is intended to cancel out the extra factor, so that it is defined even at each $x_i$).

If I divide $g(x)$ by $g(x^*)$ for some $x^*$ which is not equal to any $x_n$, I get a function that is $1$ at $x^*$ and $0$ at $x_i$. Adding functions of this form multiplied by scalars allows us to solve the problem of finding a polynomial which goes through $x_i,y_i$ (just take $\sum_{i=1}^ny_ig_i(x)$ where $g_i$ is zero for $x_j,j\ne i$ and one at $x_i$).

To get the derivative right at some specified $x^*$, just add to this expression $a\frac{g^*(x)}{{g^*}'(x^*)}$ where $g^*(x)$ is zero at each $x_i$ and at $x^*$; since $g^*(x)$ has a single root at $x^*$ its derivative there is nonzero, so the derivative of this part of the function is $a$, and we can set $a$ to be the desired derivative minus the derivative of the point-interpolation part of the function.

To give an example, let's find a polynomial such that $f(-2)=1$, $f(-1)=0$, $f'(0)=4$, $f(2)=2$. (I just made these numbers up.) First let's ignore the derivative part and construct functions that are zero at two of the points and one at the remaining point:

$$g_1(x)=\frac{(x+1)(x-2)}{(-2+1)(-2-2)}=\frac{x^2-x-2}{4}$$ $$g_2(x)=\frac{(x+2)(x-2)}{(-1+2)(-1-2)}=\frac{-x^2+4}{3}$$ $$g_3(x)=\frac{(x+2)(x+1)}{(2+2)(2+1)}=\frac{x^2+3x+1}{12}$$

Then $h(x)=g_1(x)+0g_2(x)+2g_3(x)=\frac{5x^2+3x-2}{12}$ satisfies $h(-2)=1$, $h(-1)=0$, $h(2)=2$. But it probably has the wrong derivative: $h'(x)=\frac{10x+3}{12}$, so $h'(0)=\frac14$ is not what we want. So let's construct a function which won't affect our other values, but has a nonzero derivative at $0$:

$$g^*(x)=(x+2)(x+1)(x-2)=x^3+x^2-4x-4\implies {g^*}'(x)=3x^2+2x-4$$

So ${g^*}'(0)=-4$. (It is possible for this to come out zero, in which case you can multiply the formula by $x-x^*$ to guarantee nonzero derivative at the expense of a higher degree.) Now the $h$ function is off from what we want by $4-\frac14=\frac{15}4$, while the adjustment function has derivative $-4$, so $-\frac{15}{16}{g^*}(x)$ has derivative $4-\frac14$ at $0$ and $f(x)=h(x)-\frac{15}{16}{g^*}(x)=-\frac{15}{16}x^3-\frac{25}{48}x^2+4x+\frac{43}{12}$ should do the trick.

• Can you point me of an example of this so I can test my understanding?
– Ben
Commented Jun 17, 2015 at 15:43
• @Ben I could come up with one, but it might help for consistency if you put an example polynomial in the OP. Commented Jun 17, 2015 at 15:51
• Done--hope I'm getting this right, since all I have to go on is the description above...
– Ben
Commented Jun 17, 2015 at 15:55
• @Ben Okay, I can give an example if you need. Commented Jun 17, 2015 at 16:00